Booting sensors without Gateway connection?



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


  • Hero Member

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



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


  • Hero Member

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



  • Excellent, thanks. Just what I need.



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



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


  • Hero Member

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



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



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


  • Hero Member

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



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


  • Hero Member

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



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


  • Hero Member

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



  • 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


Log in to reply
 

Suggested Topics

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts