Checking for current gateway connection state on Node?



  • Hi,

    I have a basic setup of 2 nodes connected to a gateway (no controller at present). I have added the NODE-IDs, so they can connect to the gateway and send messages OK.

    What I would like to do to is have an LED on each of my nodes, which flashes when powered up, but then goes solid when the connection is made to the gateway. So if there is an issue with the gateway, then the LED will flash on the node, so I can know that I've dropped out of range, or if I need to go and reset the gateway.

    Is there any way I can check from the node side whether there is a current connection to a gateway device?

    Thanks


  • Mod

    @phil2020 there is no persistent connection. There are just messages. So exactly what you are asking for is impossible.

    If a message was sent successfully half a second ago - does that mean the node is still in range? Probably, but we can't be sure.

    We can never know if the gateway is within range until we try sending a message. After a successful try, we know that the gateway was in range. But a second later we don't know if it still is within range.

    However, isTransportReady() is probably close to what you want.

    You can also look at the radio traffic led feature: https://www.mysensors.org/build/advanced_gateway#radio-traffic-leds



  • @mfalkvidd thanks for the reply. On the api docs page you referred me to, I saw another function called transportCheckUplink() which seems to do the necessary check for the uplink to the gateway. I added the below simple while loop to the beginning of the main loop() execution.

    while (transportCheckUplink() == false){
      power_led_flash();
    }
    

    If the link to gateway is OK, then it quickly confirms and moves onto the rest of my code. If the link to gateway is lost, then it enters the while loop and flashes the LED until the link to gateway is established again. I tested by unplugging my gateway, seeing that it went into flashing mode after a few seconds, then plugged back in, and it returned to operational mode a few seconds later.

    The only small problem I have left is that I can't seem to find a way to flash the LED on my node device if the gateway is not initially present, as the MySensors software seems to want to wait until it gets the link to the gateway before running the presentation(), setup() and main loop().

    Is there any way to run some code before MySensors loads up, or before the initial link to the gateway is established?


  • Mod

    @phil2020 yes. Add your code to a function called before(). But a lot of MySensors functionalty won't be ready, so I am not sure if you can use transportCheckUplink() from before(). Maybe just light the led in before, and turn the led off in loop when connection is established?



  • @mfalkvidd The before() function only seems to allow you to do a one-off things like turn on LEDs before moving on, rather than allowing you to stay in a loop checking for the current status of the network as it starts up. When I tried that it doesn't then progress onto the main loop(). Helped getting the LED on to start with though, so thanks for that.


  • Mod

    @phil2020 yes. If you never exit the function, the Arduino will never be able to proceed to the next function. The same applies to presentation and setup.



  • Maybe look into the possibility f setting up a low frequency PWM to drive that led. You can get it running at boot and then just change the duty cycle to manipulate th b havior.

    http://forum.arduino.cc/index.php?topic=140905.0



  • @phil2020 try this in your sketch: #define MY_TRANSPORT_WAIT_READY_MS (200ul)
    Its the "timeout" for waiting connection to gateway. Default 0 -> wait infinitely(?).


Log in to reply
 

Suggested Topics

  • 1
  • 5
  • 1
  • 10
  • 3
  • 6

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts