Evenin' all. I'm using the following to confirm messages are successfully sent.
void Resend(MyMessage &msg) {
int repeatDelay = 1000;
boolean sendOK = false;
unsigned long lastWhile;
while (sendOK == false) {
if ((millis() - lastWhile) >= repeatDelay) {
if (send(msg) == true) sendOK = true;
else repeatDelay += 1000;
lastWhile = millis();
}
}
}
Here's the full code.
#define MY_DEBUG
#define MY_RADIO_RF24
#define MY_NODE_ID 22
#define SENSOR_NAME "Master Bedroom Sensors"
#define SENSOR_VERSION "2.1"
#define DHT_DATA_PIN 3
#define SENSOR_TEMP_OFFSET 0
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#include <SPI.h>
#include <DHT.h>
#include <MySensors.h>
#include <avr/wdt.h>
DHT dht;
int lastTemp, lastHum;
unsigned long lastLoop;
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
void presentation() {
sendSketchInfo(SENSOR_NAME, SENSOR_VERSION);
present(CHILD_ID_HUM, S_HUM, "Humidity");
present(CHILD_ID_TEMP, S_TEMP, "Temperature");
}
void setup() {
wdt_enable(WDTO_8S);
dht.setup(DHT_DATA_PIN);
}
void loop() {
if ((millis() - lastLoop) >= 10000) {
dht.readSensor(true);
int temperature = lrint(dht.toFahrenheit(dht.getTemperature()) + SENSOR_TEMP_OFFSET);
if (temperature > 1 && temperature != lastTemp) {
lastTemp = temperature;
Resend(msgTemp.setDestination(26).setSensor(101).set(lastTemp));
Resend(msgTemp.set(lastTemp));
}
int humidity = lrint(dht.getHumidity());
if (!isnan(humidity) && humidity != lastHum) {
lastHum = humidity;
Resend(msgTemp.setDestination(26).setSensor(100).set(lastHum));
Resend(msgHum.set(lastHum));
}
lastLoop = millis();
}
wdt_reset();
}
void Resend(MyMessage &msg) {
int repeatDelay = 1000;
boolean sendOK = false;
unsigned long lastWhile;
while (sendOK == false) {
if ((millis() - lastWhile) >= repeatDelay) {
if (send(msg) == true) sendOK = true;
else repeatDelay += 1000;
lastWhile = millis();
}
}
}
This works very well for messages sent to the gateway; however, it is not catching node-2-node failures.
10041 !TSF:MSG:SEND,22-22-26-26,s=101,c=1,t=0,pt=2,l=2,sg=0,ft=0,st=NACK:70
10048 !TSF:RTE:N2N FAIL
10052 TSF:MSG:SEND,22-22-0-26,s=101,c=1,t=0,pt=2,l=2,sg=0,ft=0,st=OK:70
10094 !TSF:MSG:SEND,22-22-26-26,s=100,c=1,t=1,pt=2,l=2,sg=0,ft=0,st=NACK:58
10101 !TSF:RTE:N2N FAIL
I shut down node 26 in order to reproduce the errors. Is there a way to catch these failures?
Thanks!