Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. how add watchdog to my sensors?

how add watchdog to my sensors?

Scheduled Pinned Locked Moved Development
10 Posts 4 Posters 5.1k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reza
    wrote on last edited by Reza
    #1

    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);
    }
    
    
    A 1 Reply Last reply
    0
    • R Reza

      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);
      }
      
      
      A Offline
      A Offline
      AWI
      Hero Member
      wrote on last edited by AWI
      #2

      @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)

      R 1 Reply Last reply
      1
      • A AWI

        @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)

        R Offline
        R Offline
        Reza
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        0
        • HonkH Offline
          HonkH Offline
          Honk
          wrote on last edited by
          #4
          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.

          R 2 Replies Last reply
          1
          • HonkH Honk
            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.

            R Offline
            R Offline
            Reza
            wrote on last edited by Reza
            #5

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

            1 Reply Last reply
            1
            • S Offline
              S Offline
              sundberg84
              Hardware Contributor
              wrote on last edited by
              #6

              @Reza https://tushev.org/articles/arduino/5/arduino-and-watchdog-timer

              Controller: Proxmox VM - Home Assistant
              MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
              MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
              RFLink GW - Arduino Mega + RFLink Shield, 433mhz

              R 1 Reply Last reply
              1
              • HonkH Honk
                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.

                R Offline
                R Offline
                Reza
                wrote on last edited by
                #7

                @Hermann-Kaiser said:

                isTransportOK

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

                HonkH 1 Reply Last reply
                0
                • S sundberg84

                  @Reza https://tushev.org/articles/arduino/5/arduino-and-watchdog-timer

                  R Offline
                  R Offline
                  Reza
                  wrote on last edited by
                  #8

                  @sundberg84

                  thank you

                  1 Reply Last reply
                  0
                  • R Reza

                    @Hermann-Kaiser said:

                    isTransportOK

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

                    HonkH Offline
                    HonkH Offline
                    Honk
                    wrote on last edited by
                    #9

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

                    R 1 Reply Last reply
                    1
                    • HonkH Honk

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

                      R Offline
                      R Offline
                      Reza
                      wrote on last edited by
                      #10

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

                      1 Reply Last reply
                      0

                      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
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      23

                      Online

                      12.0k

                      Users

                      11.2k

                      Topics

                      113.4k

                      Posts


                      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • MySensors
                      • OpenHardware.io
                      • Categories
                      • Recent
                      • Tags
                      • Popular