Booting sensors without Gateway connection?


  • 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
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.