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. Radio Traffic LEDs - Lights up on heart beat...

Radio Traffic LEDs - Lights up on heart beat...

Scheduled Pinned Locked Moved Development
12 Posts 3 Posters 1.7k Views 2 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.
  • mfalkviddM mfalkvidd

    @strixx if I'm reading the code correctly, the gateway will blink the RX led when receiving data from the controller. In your case that would be the heartbeat message. So the leds are not only for radio traffic.

    The INDICATION_GW_RX is only set by ethernet and serial gateways though, so mqtt gateways might behave differently.

    S Offline
    S Offline
    Strixx
    wrote on last edited by
    #3

    @mfalkvidd

    Thank you!

    Would you like to tell where in the code you found this?
    I would like to change that, so that the led's only show the radio traffic for the node communication, and not between GW and controller.

    YveauxY 1 Reply Last reply
    0
    • S Strixx

      @mfalkvidd

      Thank you!

      Would you like to tell where in the code you found this?
      I would like to change that, so that the led's only show the radio traffic for the node communication, and not between GW and controller.

      YveauxY Offline
      YveauxY Offline
      Yveaux
      Mod
      wrote on last edited by
      #4

      @strixx the official way would be to define your own indication handler so you have total control over the leds. I don't have an example at hand now, maybe later...

      If you choose to hack the library, the actual code setting the leds can be found at : https://github.com/mysensors/MySensors/blob/development/core/MyIndication.cpp#L33

      http://yveaux.blogspot.nl

      S 1 Reply Last reply
      0
      • YveauxY Yveaux

        @strixx the official way would be to define your own indication handler so you have total control over the leds. I don't have an example at hand now, maybe later...

        If you choose to hack the library, the actual code setting the leds can be found at : https://github.com/mysensors/MySensors/blob/development/core/MyIndication.cpp#L33

        S Offline
        S Offline
        Strixx
        wrote on last edited by
        #5

        @yveaux I'm a newbie when it comes to C++, but I have been coding for a long time in Python. I can't really see how I can change that code you are referring to to get the changes I am looking for.

        But I found something in https://github.com/mysensors/MySensors/blob/development/core/MyGatewayTransportEthernet.cpp which I think is the code @mfalkvidd is reffering to.

        So I think I someway need to change INDICATION_GW_TX and INDICATION_GW_RX in my sketch for my gateway.

        Is that the way I should go if I don't change directly in the library code?

        YveauxY 1 Reply Last reply
        1
        • S Strixx

          @yveaux I'm a newbie when it comes to C++, but I have been coding for a long time in Python. I can't really see how I can change that code you are referring to to get the changes I am looking for.

          But I found something in https://github.com/mysensors/MySensors/blob/development/core/MyGatewayTransportEthernet.cpp which I think is the code @mfalkvidd is reffering to.

          So I think I someway need to change INDICATION_GW_TX and INDICATION_GW_RX in my sketch for my gateway.

          Is that the way I should go if I don't change directly in the library code?

          YveauxY Offline
          YveauxY Offline
          Yveaux
          Mod
          wrote on last edited by
          #6

          @strixx

          You need to #define MY_INDICATION_HANDLER in your sketch before the MySensors include, like:

          #define MY_INDICATION_HANDLER
          
          #include <MySensors.h>
          

          Add following code to actually switch the LEDs on:

          void indication( const indication_t ind )
          {
            if (INDICATION_TX == ind)
            {
              // Switch TX led on here
            }
            else if (INDICATION_RX == ind)
            {
              // Switch RX led on here
            }
          }
          

          The indication function will be called from the MySensors sketch each time when important events occur in the MySensors stack.
          Here you can find a list of all supported events.

          I guess you can actually blink a led in the indication function (so switch on, wait and switch off again) as long as you keep the blink-wait time very short (< 20ms or so).

          Preferably you blink the LED from the main loop; something like (untested):

          static bool TxBlink = false;
          unsigned long TxLedOnTime = 0;
          
          void indication( const indication_t ind )
          {
            if (INDICATION_TX == ind)
            {
              // Trigger LED blink. Register timestamp at which the blink started.
              TxBlink = true;
              TxLedOnTime = millis();
            }
          }
          
          // ...
          
          const unsigned long TxLedBlinkTimeMs = 1000;
          
          void loop()
          {
            if (TxBlink)
            {
              if ((millis() - TxLedOnTime) >= TxLedBlinkTimeMs)
              {
                // LED blink time elapsed. End the blink.
                TxBlink = false;
              }
              // Reflect TxBlink state on digital output to which LED is connected
              digitalWrite(LED_pin, TxBlink ? HIGH : LOW);
            }
          }
          

          http://yveaux.blogspot.nl

          S 1 Reply Last reply
          1
          • YveauxY Yveaux

            @strixx

            You need to #define MY_INDICATION_HANDLER in your sketch before the MySensors include, like:

            #define MY_INDICATION_HANDLER
            
            #include <MySensors.h>
            

            Add following code to actually switch the LEDs on:

            void indication( const indication_t ind )
            {
              if (INDICATION_TX == ind)
              {
                // Switch TX led on here
              }
              else if (INDICATION_RX == ind)
              {
                // Switch RX led on here
              }
            }
            

            The indication function will be called from the MySensors sketch each time when important events occur in the MySensors stack.
            Here you can find a list of all supported events.

            I guess you can actually blink a led in the indication function (so switch on, wait and switch off again) as long as you keep the blink-wait time very short (< 20ms or so).

            Preferably you blink the LED from the main loop; something like (untested):

            static bool TxBlink = false;
            unsigned long TxLedOnTime = 0;
            
            void indication( const indication_t ind )
            {
              if (INDICATION_TX == ind)
              {
                // Trigger LED blink. Register timestamp at which the blink started.
                TxBlink = true;
                TxLedOnTime = millis();
              }
            }
            
            // ...
            
            const unsigned long TxLedBlinkTimeMs = 1000;
            
            void loop()
            {
              if (TxBlink)
              {
                if ((millis() - TxLedOnTime) >= TxLedBlinkTimeMs)
                {
                  // LED blink time elapsed. End the blink.
                  TxBlink = false;
                }
                // Reflect TxBlink state on digital output to which LED is connected
                digitalWrite(LED_pin, TxBlink ? HIGH : LOW);
              }
            }
            
            S Offline
            S Offline
            Strixx
            wrote on last edited by
            #7

            @yveaux But what I would like is that the led's only show status of communication between nodes and gateway. Not between gateway and controller to. So not to change or add things to led, only remove the part where it lights up on communication between gateway and controller.

            Is this really the easiest way to do just that?

            YveauxY 1 Reply Last reply
            0
            • S Strixx

              @yveaux But what I would like is that the led's only show status of communication between nodes and gateway. Not between gateway and controller to. So not to change or add things to led, only remove the part where it lights up on communication between gateway and controller.

              Is this really the easiest way to do just that?

              YveauxY Offline
              YveauxY Offline
              Yveaux
              Mod
              wrote on last edited by
              #8

              @strixx That's exactly what the above piece of code should do, in a supported way that persists over MySensors updates.

              For TX there exist 2 events, INDICATION_TX and INDICATION_GW_TX, that blink the TX LED when enabled in MySensors.
              The same for RX, INDICATION_RX and INDICATION_GW_RX.
              The INDICATION_GW_xx events are used for gateway-controller communication, and that's what you want to suppress.
              So, If you want to hack it into the stack you should remove the handling of INDICATION_GW_xx events from the setIndication function in core/MyIndication.cpp:

              void setIndication( const indication_t ind )
              {
              #if defined(MY_DEFAULT_TX_LED_PIN)
              	if (INDICATION_TX == ind) {
              		ledsBlinkTx(1);
              	} else
              #endif
              #if defined(MY_DEFAULT_RX_LED_PIN)
              		if (INDICATION_RX == ind) {
              			ledsBlinkRx(1);
              		} else
              #endif
              #if defined(MY_DEFAULT_ERR_LED_PIN)
              			if (ind > INDICATION_ERR_START) {
              				// Number of blinks indicates which error occurred.
              				ledsBlinkErr(ind-INDICATION_ERR_START);
              			}
              #endif
              	indication(ind);
              }
              

              As I said before, I would not recommend going this way though...

              http://yveaux.blogspot.nl

              1 Reply Last reply
              1
              • S Offline
                S Offline
                Strixx
                wrote on last edited by
                #9

                I haven't had time to read up on your suggestions. But hopefully I will have some spare time this weekend. But thank you for your help so far.

                Do I understand it right:
                By defining MY_INDICATION_HANDLER before the I include the MySensors library, that part of the library will not be included in the sketch?
                And then I wright my own handler for blinking the leds in my own sketch?

                Can I put it at the end or must it be in the beginning?

                YveauxY 1 Reply Last reply
                0
                • S Strixx

                  I haven't had time to read up on your suggestions. But hopefully I will have some spare time this weekend. But thank you for your help so far.

                  Do I understand it right:
                  By defining MY_INDICATION_HANDLER before the I include the MySensors library, that part of the library will not be included in the sketch?
                  And then I wright my own handler for blinking the leds in my own sketch?

                  Can I put it at the end or must it be in the beginning?

                  YveauxY Offline
                  YveauxY Offline
                  Yveaux
                  Mod
                  wrote on last edited by
                  #10

                  @strixx yes, you have to supply your own implementation of the indication function once you define that.
                  It needs to be defined before the mySensors include statement.

                  http://yveaux.blogspot.nl

                  S 1 Reply Last reply
                  0
                  • YveauxY Yveaux

                    @strixx yes, you have to supply your own implementation of the indication function once you define that.
                    It needs to be defined before the mySensors include statement.

                    S Offline
                    S Offline
                    Strixx
                    wrote on last edited by
                    #11

                    @yveaux said in Radio Traffic LEDs - Lights up on heart beat...:

                    @strixx yes, you have to supply your own implementation of the indication function once you define that.
                    It needs to be defined before the mySensors include statement.

                    I have learned that much that I need to define before including the library. But can I put the function (the code) anywhere? For example at the end of my sketch?

                    YveauxY 1 Reply Last reply
                    0
                    • S Strixx

                      @yveaux said in Radio Traffic LEDs - Lights up on heart beat...:

                      @strixx yes, you have to supply your own implementation of the indication function once you define that.
                      It needs to be defined before the mySensors include statement.

                      I have learned that much that I need to define before including the library. But can I put the function (the code) anywhere? For example at the end of my sketch?

                      YveauxY Offline
                      YveauxY Offline
                      Yveaux
                      Mod
                      wrote on last edited by
                      #12

                      @strixx yes

                      http://yveaux.blogspot.nl

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      14

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.1k

                      Posts


                      Copyright 2025 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