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);
    }
    
    

  • Hero Member

    @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. 0_1474354717994_upload-0e56e228-365f-4d94-90b3-5cf1305c6fae (I did it for you in your posting above)



  • @AWI
    hi ok thank you.
    yes watchdog to keep the node alive and to make sure the node can make a connection to the gateway



  • 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 ?


  • Hardware Contributor



  • @Hermann-Kaiser said:

    isTransportOK

    isTransportOK is true , but wait(MY_RECONNECT); have error !



  • @sundberg84

    thank you



  • @Reza this is a #define MY_RECONNECT 5000
    just put a time in ms into the wait function.



  • @Hermann-Kaiser
    ok .this is true .
    so where i add this ? after sleep(SLEEP_TIME); ???
    also this is for radio ? is this right ? so for sensor and arduino !! there are not any function in mysensors?


Log in to reply
 

Suggested Topics

  • 1
  • 1
  • 2
  • 2
  • 3
  • 1

58
Online

11.4k
Users

11.1k
Topics

112.7k
Posts