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. Checking for current gateway connection state on Node?

Checking for current gateway connection state on Node?

Scheduled Pinned Locked Moved Development
8 Posts 4 Posters 2.1k Views 4 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.
  • phil2020P Offline
    phil2020P Offline
    phil2020
    wrote on last edited by phil2020
    #1

    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

    mfalkviddM 1 Reply Last reply
    0
    • phil2020P phil2020

      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

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by mfalkvidd
      #2

      @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

      1 Reply Last reply
      0
      • phil2020P Offline
        phil2020P Offline
        phil2020
        wrote on last edited by
        #3

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

        mfalkviddM 1 Reply Last reply
        0
        • phil2020P phil2020

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

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by mfalkvidd
          #4

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

          1 Reply Last reply
          0
          • phil2020P Offline
            phil2020P Offline
            phil2020
            wrote on last edited by
            #5

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

            mfalkviddM 1 Reply Last reply
            0
            • phil2020P phil2020

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

              mfalkviddM Offline
              mfalkviddM Offline
              mfalkvidd
              Mod
              wrote on last edited by mfalkvidd
              #6

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

              1 Reply Last reply
              0
              • ThucarT Offline
                ThucarT Offline
                Thucar
                wrote on last edited by
                #7

                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

                Controller: Node-Red
                Gateway: SerialGateway & GSMMQTTGateway
                MySensors: 2.2.0

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  pjr
                  wrote on last edited by pjr
                  #8

                  @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(?).

                  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