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. Booting sensors without Gateway connection?

Booting sensors without Gateway connection?

Scheduled Pinned Locked Moved Development
16 Posts 4 Posters 5.0k Views 5 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.
  • S Stuart Middleton

    I was just about to ask this very question!

    So, assuming I don't get a connection on startup and drop into my main loop, what do I call periodically to try to connect?

    I have a similar system that can operate autonomously. I do, however, need the main loop to be pretty much real-time, which means I can't afford a 3-second stall every X seconds while it tries to establish a connection with the gateway. Is there an asynchronous way to attempt a connection?

    Thanks,

    Boots33B Offline
    Boots33B Offline
    Boots33
    Hero Member
    wrote on last edited by
    #4

    @Stuart-Middleton That code is only run when the node first boots up so the 3 second delay is only run once.
    If the node fails to establish an uplink then it will automatically continue to try and connect in the background as well once the node has continued on to the loop.

    1 Reply Last reply
    1
    • S Offline
      S Offline
      Stuart Middleton
      wrote on last edited by
      #5

      Excellent, thanks. Just what I need.

      1 Reply Last reply
      1
      • T Offline
        T Offline
        Tinimini
        wrote on last edited by
        #6

        I'm kind of in the same boat and trying to figure out what to do if the gateway does not respond. What's the impact on power consumption? If it tries to connect in the background, does it still go to sleep when I call sleep in loop? Now when I don't have the gateway running, it seems to use up quite a lot more power when trying to connect.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tinimini
          wrote on last edited by
          #7

          Is the 3 seconds the default? If so, I have waited that long and the power consumption stays high even after that. So it seems that it doesn't go to sleep properly when there's no connection to the gateway. Optimally I'd like to go to sleep and try reconnecting myself every few minutes or so.

          Boots33B 1 Reply Last reply
          0
          • T Tinimini

            Is the 3 seconds the default? If so, I have waited that long and the power consumption stays high even after that. So it seems that it doesn't go to sleep properly when there's no connection to the gateway. Optimally I'd like to go to sleep and try reconnecting myself every few minutes or so.

            Boots33B Offline
            Boots33B Offline
            Boots33
            Hero Member
            wrote on last edited by
            #8

            @Tinimini No 3 seconds is not the default. The default is 0 which means the node will not continue until the uplink is established. You could just set it to 1 if you want the node to move directly to the loop without delay. As far as sleep goes I am not sure but I would have thought that sleep should still work .

            1 Reply Last reply
            2
            • T Offline
              T Offline
              Tinimini
              wrote on last edited by
              #9

              Ah, cool. I will try to change the value and see how that affects the power consumption. Thanks!

              1 Reply Last reply
              0
              • T Offline
                T Offline
                Tinimini
                wrote on last edited by
                #10

                Hmm.. Looks like it's still using quite a lot of power. When the gateway is running and the sensor is sleeping I'm seeing about 6uA of current drawn. When gateway is down, it's about 3mA. So that's not very good.. I need to add some debug statements to see if it actually is sleeping or what.

                Boots33B 1 Reply Last reply
                0
                • T Tinimini

                  Hmm.. Looks like it's still using quite a lot of power. When the gateway is running and the sensor is sleeping I'm seeing about 6uA of current drawn. When gateway is down, it's about 3mA. So that's not very good.. I need to add some debug statements to see if it actually is sleeping or what.

                  Boots33B Offline
                  Boots33B Offline
                  Boots33
                  Hero Member
                  wrote on last edited by
                  #11

                  @Tinimini yes that would appear not to be sleeping, I have no battery powered nodes so have not done much with the sleep function but still think it should work once your node gets to the loop part of the sketch.

                  perhaps post your sketch if you cannot find a solution.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    Tinimini
                    wrote on last edited by
                    #12

                    The sketch is very very simple. Just a basic door sensor.

                    // Enable debug prints to serial monitor
                    //#define MY_DEBUG
                    
                    // Set how long to wait for transport ready in milliseconds
                    #define MY_TRANSPORT_WAIT_READY_MS 3000
                    
                    // Enable and select radio type attached
                    #define MY_RADIO_NRF24
                    
                    // Set this nodes id. Needs to be unique between nodes (value = 1-254)
                    #define MY_NODE_ID 102
                    
                    #include <SPI.h>
                    #include <MySensors.h>
                    
                    #define CHILD_ID   3
                    #define DOOR_PIN   3     // Arduino Digital I/O pin for button/reed switch
                    #define SLEEP_TIME 3000 // Sleep time between heartbeats (seconds * 1000 ms)
                    
                    int oldValue = -1;
                    
                    MyMessage msg(CHILD_ID, V_TRIPPED);
                    
                    void setup() {
                      pinMode(DOOR_PIN, INPUT);
                    }
                    
                    void presentation() {
                      present(CHILD_ID, S_DOOR);
                    }
                    
                    void loop() {
                      int value = digitalRead(DOOR_PIN);
                    
                      if (value != oldValue) {
                         send(msg.set(value == HIGH ? 1 : 0));
                         oldValue = value;
                      }
                    
                      wait(10);
                    
                      smartSleep(digitalPinToInterrupt(DOOR_PIN), CHANGE, SLEEP_TIME);
                    }
                    

                    I tried changing smartSleep to sleep to try if that makes a difference, but it doesn't seem to change anything.

                    Boots33B 1 Reply Last reply
                    0
                    • T Tinimini

                      The sketch is very very simple. Just a basic door sensor.

                      // Enable debug prints to serial monitor
                      //#define MY_DEBUG
                      
                      // Set how long to wait for transport ready in milliseconds
                      #define MY_TRANSPORT_WAIT_READY_MS 3000
                      
                      // Enable and select radio type attached
                      #define MY_RADIO_NRF24
                      
                      // Set this nodes id. Needs to be unique between nodes (value = 1-254)
                      #define MY_NODE_ID 102
                      
                      #include <SPI.h>
                      #include <MySensors.h>
                      
                      #define CHILD_ID   3
                      #define DOOR_PIN   3     // Arduino Digital I/O pin for button/reed switch
                      #define SLEEP_TIME 3000 // Sleep time between heartbeats (seconds * 1000 ms)
                      
                      int oldValue = -1;
                      
                      MyMessage msg(CHILD_ID, V_TRIPPED);
                      
                      void setup() {
                        pinMode(DOOR_PIN, INPUT);
                      }
                      
                      void presentation() {
                        present(CHILD_ID, S_DOOR);
                      }
                      
                      void loop() {
                        int value = digitalRead(DOOR_PIN);
                      
                        if (value != oldValue) {
                           send(msg.set(value == HIGH ? 1 : 0));
                           oldValue = value;
                        }
                      
                        wait(10);
                      
                        smartSleep(digitalPinToInterrupt(DOOR_PIN), CHANGE, SLEEP_TIME);
                      }
                      

                      I tried changing smartSleep to sleep to try if that makes a difference, but it doesn't seem to change anything.

                      Boots33B Offline
                      Boots33B Offline
                      Boots33
                      Hero Member
                      wrote on last edited by
                      #13

                      @Tinimini Is there a reason you are only sleeping the node for three seconds? As I said I have not used sleep but would think you would need to sleep longer to gain much benefit.

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        Tinimini
                        wrote on last edited by
                        #14

                        Oh, that's very simple. It's there because I'm testing this and trying to make it work. It will be more like 15 minutes to half an hour in reality.
                        Unfortunately still haven't been able to get this to work, and as I'm just starting with my home automation stuff, the gateway will probably be offline quite a lot while I'm developing things. And that means that the battery powered sensors are going to suck their batteries dry in no time... I probably have to add an on/off switch to the sensors or something. Just so I can turn them off when I know they can't be used.

                        Boots33B 1 Reply Last reply
                        0
                        • T Tinimini

                          Oh, that's very simple. It's there because I'm testing this and trying to make it work. It will be more like 15 minutes to half an hour in reality.
                          Unfortunately still haven't been able to get this to work, and as I'm just starting with my home automation stuff, the gateway will probably be offline quite a lot while I'm developing things. And that means that the battery powered sensors are going to suck their batteries dry in no time... I probably have to add an on/off switch to the sensors or something. Just so I can turn them off when I know they can't be used.

                          Boots33B Offline
                          Boots33B Offline
                          Boots33
                          Hero Member
                          wrote on last edited by
                          #15

                          @Tinimini I think you may be best to start a new thread about the sleep issue as the title if this one may not be that helpful in gaining an answer. I do remember seeing a thread somewhere that sleep may be working better in the development branch.

                          1 Reply Last reply
                          0
                          • T Offline
                            T Offline
                            Tinimini
                            wrote on last edited by
                            #16

                            Yes, you're right. Considering how I kind of hijacked this thread anyway :) I will run some more tests and start a new thread if I can't find a solution

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            23

                            Online

                            11.7k

                            Users

                            11.2k

                            Topics

                            113.1k

                            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