how add watchdog to my sensors?
-
hi
how add watchdog to my sensors?
for example this code:// Enable debug prints // #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #include <SPI.h> #include <MySensors.h> unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds) #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define CHILD_ID 1 // Id of the sensor child // Initialize motion message MyMessage msg(CHILD_ID, V_TRIPPED); void setup() { pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Motion Sensor", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID, S_MOTION); } void loop() { // Read digital motion value boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; Serial.println(tripped); send(msg.set(tripped?"1":"0")); // Send tripped value to gw // Sleep until interrupt comes in on motion sensor. Send update every two minute. sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME); } -
hi
how add watchdog to my sensors?
for example this code:// Enable debug prints // #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #include <SPI.h> #include <MySensors.h> unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds) #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define CHILD_ID 1 // Id of the sensor child // Initialize motion message MyMessage msg(CHILD_ID, V_TRIPPED); void setup() { pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Motion Sensor", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID, S_MOTION); } void loop() { // Read digital motion value boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; Serial.println(tripped); send(msg.set(tripped?"1":"0")); // Send tripped value to gw // Sleep until interrupt comes in on motion sensor. Send update every two minute. sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME); }@Reza What would be the purpose of the watchdog? To keep the node alive or to make sure the node can make a connection to the gateway?
(btw Please enclose code in code marks to keep it readable.
(I did it for you in your posting above)
-
@Reza What would be the purpose of the watchdog? To keep the node alive or to make sure the node can make a connection to the gateway?
(btw Please enclose code in code marks to keep it readable.
(I did it for you in your posting above)
-
if (!isTransportReady()) wait(MY_RECONNECT);your node just needs to be awake to reconnect to the gateway.
I've set MY_RECONNECT to 5000 (5sec).
So far this works for my sleeping battery node.isTransportReady could also be isTransportOK. depends on the version you are using.
-
if (!isTransportReady()) wait(MY_RECONNECT);your node just needs to be awake to reconnect to the gateway.
I've set MY_RECONNECT to 5000 (5sec).
So far this works for my sleeping battery node.isTransportReady could also be isTransportOK. depends on the version you are using.
@Hermann-Kaiser
hi thank you .
for this sketch , where put your code?#define MY_DEBUG #define MY_RADIO_NRF24 #define MY_REPEATER_FEATURE #include <SPI.h> #include <MySensors.h> #define CHILD_ID_LIGHT 0 #define LIGHT_SENSOR_ANALOG_PIN 0 unsigned long SLEEP_TIME = 30000; MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; void presentation() { sendSketchInfo("Light Sensor", "1.0"); present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } void loop() { int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; Serial.println(lightLevel); if (lightLevel != lastLightLevel) { send(msg.set(lightLevel)); lastLightLevel = lightLevel; } wait(SLEEP_TIME); }also this is for radio , but for arduino and sensor , how add watchdog ?
-
-
if (!isTransportReady()) wait(MY_RECONNECT);your node just needs to be awake to reconnect to the gateway.
I've set MY_RECONNECT to 5000 (5sec).
So far this works for my sleeping battery node.isTransportReady could also be isTransportOK. depends on the version you are using.
-
thank you
-
@Hermann-Kaiser said:
isTransportOK
isTransportOK is true , but wait(MY_RECONNECT); have error !
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login