|
@@ -8,6 +8,22 @@
|
|
|
|
|
|
#define MY_RF24_CHANNEL 14
|
|
|
|
|
|
+
|
|
|
+// INFO coincell optimization
|
|
|
+// https://www.openhardware.io/view/398/NModule-Temperature-Humidity-Light-Door-sensor-shield#tabs-source
|
|
|
+#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
|
|
|
+
|
|
|
+// Timeout for transport to be ready during initialization, after this duration, even if it didn't manage to enable transport the node will enter the loop() method
|
|
|
+// For battery powered nodes, I set this to 5000 so after 5 seconds it will stop eating the battery
|
|
|
+// 5s is long enough to connect to gateway so you should connect your node back to your computer and check the log if your node cannot connect
|
|
|
+#define MY_TRANSPORT_WAIT_READY_MS 5000 // no more than 5 seconds of waiting for transport to be ready
|
|
|
+
|
|
|
+// Reduce maximum delay before going to sleep, as we do not want to kill the battery if gateway is not available
|
|
|
+// Before going to sleep MySensors will make sure we don't have a connection problem to MySensors network
|
|
|
+// If this value is too high and you have connection problem, MySensors will never go to sleep and bye bye battery ...
|
|
|
+// If using AA/AAA batteries you can set a longer duration like 5000ms
|
|
|
+#define MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS 2000
|
|
|
+
|
|
|
// #define MY_SIGNING_SIMPLE_PASSWD "C@KptBi1L@5op?8!"
|
|
|
// #define MY_SECURITY_SIMPLE_PASSWD "C@KptBi1L@5op?8!"
|
|
|
|
|
@@ -26,7 +42,9 @@ static const uint64_t UPDATE_INTERVAL = 900000; // (15min * 60sec = 900 seconds
|
|
|
|
|
|
bool metric = true;
|
|
|
float ahtTemp; //to store T/RH result
|
|
|
+float last_ahtTemp; //to store T/RH result
|
|
|
float ahtHumi;
|
|
|
+float last_ahtHumi;
|
|
|
|
|
|
int oldBatteryPcnt = 0;
|
|
|
#define FULL_BATTERY 3 // 3V for 2xAA alkaline. Adjust if you use a different battery setup.
|
|
@@ -45,21 +63,33 @@ MyMessage msgBatVPrefix(CHILD_ID_BATV, V_UNIT_PREFIX); // Custom unit message.
|
|
|
AHTxx aht10(0x38, AHT1x_SENSOR); //sensor address, sensor type
|
|
|
// AHTxx aht10(0x00, 0x38);
|
|
|
|
|
|
+// Sleep between sendings to preserve coin cell
|
|
|
+void sleepForCoinCell() {
|
|
|
+ sleep(400);
|
|
|
+}
|
|
|
|
|
|
void presentation()
|
|
|
{
|
|
|
- Serial.println("- - - - - presentation - - - - -");
|
|
|
-
|
|
|
+ #ifdef MY_DEBUG
|
|
|
+ Serial.println("- - - - - presentation - - - - -");
|
|
|
+ #endif
|
|
|
+
|
|
|
// Send the sketch version information to the gateway
|
|
|
- sendSketchInfo("aht10", "0.4.2");
|
|
|
+ sendSketchInfo("aht10", "0.5");
|
|
|
+ sleepForCoinCell();
|
|
|
|
|
|
// Register all sensors to gw (they will be created as child devices)
|
|
|
present(CHILD_ID_TEMP, S_TEMP, "Temperature");
|
|
|
+ sleepForCoinCell();
|
|
|
present(CHILD_ID_HUM, S_HUM, "Humidity");
|
|
|
+ sleepForCoinCell();
|
|
|
present(CHILD_ID_BAT, S_CUSTOM, "Battery Percent");
|
|
|
+ sleepForCoinCell();
|
|
|
present(CHILD_ID_BATV, S_CUSTOM, "Battery Voltage");
|
|
|
+ sleepForCoinCell();
|
|
|
|
|
|
metric = getControllerConfig().isMetric;
|
|
|
+ sleepForCoinCell();
|
|
|
|
|
|
}
|
|
|
|
|
@@ -98,9 +128,14 @@ void loop()
|
|
|
Serial.println(F(" +-0.3C"));
|
|
|
#endif
|
|
|
// static MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
|
|
|
- send(msgTemp.set(ahtTemp, 1));
|
|
|
+ if (ahtTemp != last_ahtTemp)
|
|
|
+ {
|
|
|
+ send(msgTemp.set(ahtTemp, 1));
|
|
|
+ last_ahtTemp = ahtTemp;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- delay(2000); //measurement with high frequency leads to heating of the sensor, see NOTE
|
|
|
+ sleep(2000); //measurement with high frequency leads to heating of the sensor, see NOTE
|
|
|
|
|
|
ahtHumi = aht10.readHumidity(); //read another 6-bytes via I2C, takes 80 milliseconds
|
|
|
#ifdef MY_DEBUG
|
|
@@ -109,9 +144,14 @@ void loop()
|
|
|
Serial.println(F(" +-2%"));
|
|
|
#endif
|
|
|
// static MyMessage msgHum(CHILD_ID_HUM, V_HUM);
|
|
|
- send(msgHum.set(ahtHumi, 1));
|
|
|
+ if (ahtHumi != last_ahtHumi)
|
|
|
+ {
|
|
|
+ send(msgHum.set(ahtHumi, 1));
|
|
|
+ last_ahtHumi = ahtHumi;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- delay(2000);
|
|
|
+ sleep(2000);
|
|
|
|
|
|
// get the battery Voltage
|
|
|
long batteryMillivolts = hwCPUVoltage();
|
|
@@ -128,10 +168,14 @@ void loop()
|
|
|
|
|
|
if (oldBatteryPcnt != batteryPcnt) {
|
|
|
sendBatteryLevel(batteryPcnt);
|
|
|
+ sleepForCoinCell();
|
|
|
oldBatteryPcnt = batteryPcnt;
|
|
|
send(msgBatPrefix.set("%")); // Set custom unit.
|
|
|
+ sleepForCoinCell();
|
|
|
send(msgBat.set(batteryPcnt, 1));
|
|
|
+ sleepForCoinCell();
|
|
|
send(msgBatVPrefix.set("V")); // Set custom unit.
|
|
|
+ sleepForCoinCell();
|
|
|
send(msgBatV.set(batteryVolts, 1));
|
|
|
}
|
|
|
|