Node stops working and does not recover if communication fails



  • I've noticed a problem recently, which I haven't seen before (not sure if it was a recent update or is a problem with 2.0).
    If a node sends data to the gateway while the gateway is powered off, the node seems to stop communicating with the gw (after the gw is turned on, of course) until the node is restarted. I have 2 nodes, both with 2.0 and MYSBootloader 1.3, and they both exhibit this behavior.
    Since one of them is inside the wall switch, and the other in a small box, I have not yet had the chance to debug it further.

    Any tips?



  • @abmantis
    I confirm.
    I have no background as my setup is brand new (RPi gateway and openhab2)
    But nodes have to be reset after a restart of gateway


  • Hero Member

    Hard to say without seeing any debug info or sketch details but if you are using sleep in your sketch this thread may be of help.



  • @Boots33 Yeah, my node sleeps! It may be that. I see that the development branch has a fix for that already. Is it ok to use that branch?


  • Hero Member

    @abmantis Yes that is correct the node will try and re connect to the gateway when it wakes. In a perfect world this would work every time without issue.
    But of course perfect is a very rare thing to find. So there can be problems with the re-connection. This could be caused by many things such as your node being on the fringe of reception range or interference on the 2.4ghz frequency caused by other devices(microwave ovens for example) or perhaps even other nodes that happen to be transmitting at the same time.

    If your node cannot connect on the first try it will make several more attempts and then if it still cant connect it will then try to find another way to the gateway through a repeater etc. In that other thread they found that If you are using sleep your node may shutdown before the connection is made and it would not get a chance to connect and send your data.

    The workaround stops the node from sleeping if a connection is not present and makes it wait instead. wait will pause the execution of the code but the node will still try and connect in the background.

    the downside is that if the node cannot connect it will never sleep which will be hard on battery powered devices. Depending on your sketch if it is a battery powered node you could perhaps add a counter to the loop which could send the node to sleep after several tries.

    
    if(isTransportOK()){
        sleep(30000);  // transport is OK, node can sleep
      } 
      else {
        wait(5000); // transport is not operational, allow the transport layer to fix this
      }
    
    


  • Thanks for the help and explanation.

    I suggest the following:

    if(!isTransportOK()){
        wait(5000); // transport is not operational, allow the transport layer to fix this
     }
     sleep(30000);  // transport is OK, node can sleep
    

    That way, if it still can't connect during those 5 seconds it will sleep, and try again the next time.


  • Hero Member

    @abmantis with that the node will go into a sleep as soon as it comes out of the wait so the original way is probably best.



  • @Boots33 But for my node it should be connected in 5 seconds. Range is not a problem. The problem happened because I had to reboot my raspberry, and someone pressed the switch 😛

    Lets say it looses connection for some reason. The next time I press the switch (and the gateway is on), it will have 5 seconds to reconnect, which should be enough. If the gateway is still of, I can just press the switch again when it is turned on.


  • Hero Member

    @abmantis Always more than one way to fix a problem 😃


Log in to reply
 

Suggested Topics

  • 3
  • 5
  • 1
  • 1
  • 2

52
Online

11.4k
Users

11.1k
Topics

112.6k
Posts