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



  • So I have my gateway up and running and connected to my controller which is Domoticz.

    And I notice that every time Domoticz is sending a heart beat both TX and RX LED lights up on the gateway.
    So I wonder why the RX lights up. I only have battery powered sensors, and they dont reply on the heart beats.
    When I use MYSController to check. There is no answere to the heart beats.

    I use MySensors 2.2.0. The gateway is a ESP8266 (NodeMCU 0.9).


  • Mod

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



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


  • Mod

    @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



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


  • Mod

    @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);
      }
    }
    


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


  • Mod

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



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


  • Mod

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



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


  • Mod

    @strixx yes


 

343
Online

8.0k
Users

8.8k
Topics

94.4k
Posts