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 4.9k 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.
  • PhracturedBlueP Offline
    PhracturedBlueP Offline
    PhracturedBlue
    wrote on last edited by
    #1

    I am designing sensors that do data-logging in addition to sending that data back to a gateway via mqtt. Today, the sensor does not begin to execute until it has established communication with the gateway. This may make sense if the sensors only purpose is transmitting data, but in my case, I want to ensure that the data-logging activates as soon as the sensor powers on, even if a gateway isn't found.

    Is it possible to defer configuration to the main loop such that my sensors can collect data while trying to establish communication with the gateway?

    I am using RFM69W sensors if it is relevant. From what I can tell, the sensors seem to get stuck in an ACK loop waiting for gateway response, but I am not 100% sure whether this happens for all radios or not.

    Boots33B 1 Reply Last reply
    0
    • PhracturedBlueP PhracturedBlue

      I am designing sensors that do data-logging in addition to sending that data back to a gateway via mqtt. Today, the sensor does not begin to execute until it has established communication with the gateway. This may make sense if the sensors only purpose is transmitting data, but in my case, I want to ensure that the data-logging activates as soon as the sensor powers on, even if a gateway isn't found.

      Is it possible to defer configuration to the main loop such that my sensors can collect data while trying to establish communication with the gateway?

      I am using RFM69W sensors if it is relevant. From what I can tell, the sensors seem to get stuck in an ACK loop waiting for gateway response, but I am not 100% sure whether this happens for all radios or not.

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

      @PhracturedBlue

      If you are using MySensors V2.1 one solution may be add

      //set how long to wait for transport ready in milliseconds
      #define MY_TRANSPORT_WAIT_READY_MS 3000
      

      before #include <MySensors.h>

      This will set how long the node will try to connect before it will move on to execute the loop code, in the line above that will be 3 seconds.
      If the node connects before the time is up it will move on as well.

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

        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 1 Reply Last reply
        1
        • 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


                                  24

                                  Online

                                  11.7k

                                  Users

                                  11.2k

                                  Topics

                                  113.0k

                                  Posts


                                  Copyright 2019 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