Debug messages over Wi-Fi

  • Code Contributor

    I wrote a library to be able to watch the debug messages from a ethernet gateway over Wi-Fi (or ethernet).
    It opens port 2300, so you can connect with putty (change the "Connection type" to Telnet or Raw).

    If anyone is interested, here is the code:

    To use it, add the following lines in your sketch before MySensors.h

    #include <MyNetDebug.h>
    #define MY_SERIALDEVICE NetDebug

    And into your loop function:

    void loop()

    For more details, please check the examples.

  • @marceloaqno interesting. Did you try it on atmega328p only? Other MCU?

  • Hi,
    Your initiative seems a bright idea, thanks for that !
    I tried your library to debug a gateway on a wemos D1 mini with Mysensors 2.3.0, but I got error messages when compiling. Maybe it's because I didn't follow proper installation of your library as I'm not friendly with Arduino IDE library system.
    I did symply download your folders from github and installed Mynetdebug-master folder in same folder than Mysensors library folder. IN the Mynetdebug folder, I have a keywords.txt file and a library.json and library.master, and a src folder where I have the .cpp and .h files.
    Is it correct ?
    I used your example for ESP8266 to modify my working gateway .ino.
    Then, when I compiled, I got following error messages:

    Arduino: 1.8.5 (Windows 7), Board: "WeMos D1 R2 & mini, 80 MHz, 115200, 4M (3M SPIFFS)"
    WARNING: Category 'MySensors' in library MyNetDebug is not valid. Setting to 'Uncategorized'
    In file included from d:\userdata\myname\My Documents\Arduino\libraries\MySensors/MySensors.h:212:0,
                     from D:\userdata\myname\My Documents\Arduino\LoraGTWperso04Mynetdebug\LoraGTWperso04Mynetdebug.ino:67:
    d:\userdata\myname\My Documents\Arduino\libraries\MySensors/core/MyGatewayTransportEthernet.cpp: In function 'bool gatewayTransportInit()':
    d:\userdata\myname\My Documents\Arduino\libraries\MySensors/core/MyGatewayTransportEthernet.cpp:28:22: error: 'MY_ESP8266_SSID' was not declared in this scope
     #define MY_WIFI_SSID MY_ESP8266_SSID
    d:\userdata\myname\My Documents\Arduino\libraries\MySensors/core/MyGatewayTransportEthernet.cpp:163:19: note: in expansion of macro 'MY_WIFI_SSID'
    d:\userdata\myname\My Documents\Arduino\libraries\MySensors/core/MyGatewayTransportEthernet.cpp:34:26: error: 'MY_ESP8266_PASSWORD' was not declared in this scope
    d:\userdata\myname\My Documents\Arduino\libraries\MySensors/core/MyGatewayTransportEthernet.cpp:163:33: note: in expansion of macro 'MY_WIFI_PASSWORD'
    exit status 1
    Error compiling for board WeMos D1 R2 & mini.
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

    Can you help me ?

  • Mod

    @ricorico94 did you define these in your sketch, before including MySensors.h?

    #define MY_ESP8266_SSID "MySSID"
    #define MY_ESP8266_PASSWORD "MyVerySecretPassword"

  • Hi,
    Thanks for your help.
    Yes, I defined them before the Mysesnors.h.
    here's my ino (I anonymised ssid and password):

    // Application details
    #define APPLICATION_NAME    "Gateway RFM95 Eric"
    #define APPLICATION_VERSION "0.0.0.Beta Eric"
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
    #define MY_BAUD_RATE 115200 
    // Enable and select radio type attached
    #define   MY_RADIO_RFM95
    #define   MY_DEBUG_VERBOSE_RFM95
    //#define MY_RFM95_ATC_TARGET_RSSI (-70)  // target RSSI -70dBm
    //#define   MY_RFM95_MAX_POWER_LEVEL_DBM (20)   // max. TX power 10dBm = 10mW
    #define   MY_RFM95_FREQUENCY (RFM95_434MHZ)
    //#define   MY_RFM95_MODEM_CONFIGRUATION (RFM95_BW500CR45SF128)
    //below was used in first successful testings then modified to try improving coverage
    #define MY_TRANSPORT_STATE_TIMEOUT_MS  (3*1000ul)
    #define RFM95_RETRY_TIMEOUT_MS  (3000ul) 
    #define   MY_RFM95_IRQ_PIN 5
    #define   MY_RFM95_IRQ_NUM MY_RFM95_IRQ_PIN
    #define   MY_RFM95_CS_PIN 15
    #define MY_GATEWAY_ESP8266
    // Set WIFI SSID and password
    #define MY_ESP8266_SSID "nameofmywifi"
    #define MY_ESP8266_PASSWORD "mypassword"
    #define MY_HOSTNAME "lora-gateway"
    #define MY_PORT 5003
    //added for MyNetdebug
    // How many clients should be able to connect to this gateway (default 1)
    #if defined(MY_USE_UDP)
    #include <WiFiUdp.h>
    // end added for Mynetdebug
    #include <ESP8266WiFi.h>
    //added for Mynetdebug
    #include <MyNetDebug.h>
    #define MY_SERIALDEVICE NetDebug
    // end added
    #include <MySensors.h>
    void setup()
      //all block below added for Mynetdebug
         // Echo all data sent by the debug client
      // Send a carriage return before each line feed
      // If you want the debug message to also be sent to Serial port
      // Initialize the serial port if you plan to use it in your sketch or if you are using the mirror function
      // MySensors usually does this for us, however, since we've set up our serial device to be NetDebug,
      // we have to do it ourselves
      // end added Mynetdebug
        // Setup locally attached sensors
    void presentation()
        // Present locally attached sensors here
    void loop()
      //added for Mynetdebug
    // end added for Mynetdebug
        // Send locally attached sensors data here

    For your info, before I make these changes, it was compiling OK. My changes are embedded within the comments "added for Mynetdebug".
    In IDE, I use the setting wemos D1R2 & mini, 80MHz and "4M(3M SPIFFS)".
    Maybe I installed the library i a wrong manner ? Shoudl I move the .h and .cpp one level up in folders ?


  • Hi,
    I found the cause of the error..
    Since 2.3.0, we shouldn't write anymore:

    #define MY_ESP8266_SSID "MySSID"
    #define MY_ESP8266_PASSWORD "MyVerySecretPassword"


    #define MY_WIFI_SSID "MySSID"
    #define MY_WIFI_PASSWORD "MyVerySecretPassword"

    I found because I discovered than compiling was OK with 2.2.0 and not anymore with 2.3.0 (even without the MyNetDebug library) and I looked at the example in the 2.3.0 library..
    I had been misleaded by the fact than in release description, it was stated that 2.3 is backward compatible and that network had not to be modified.. So I had thought that no change was required in the sketch..

    I could test the library MyNetDebug and it seems working: the only thing is that it seems slow. Letters show up one after the other fairly slowly (much more slowly than if Serial Monitor used alone). I hope it's not disturbing radio communication..
    But it's great to be able to catch debug messages without plugging the ESP8266 in a computer ! I'll have to investigate if the debug status can be switched on/off by a remote command to the ESP8266 gateway to avoid overloading the device if not necessary.

    Thanks again for your efforts!

  • Hello
    I've tried to use this with an ESP32 (I modified some defines for the architecture, to make it compatible). In MyHwESP32.h I've changed

    #define MY_SERIALDEVICE Serial


      #define MY_SERIALDEVICE Serial

    I think this why it doesn't work for you @ricorico94 with version 2.3 of MySensors.

    It worked sometimes, but usually Putty responds "Network error: Connection refused"

    Any ideas?

Log in to reply

Suggested Topics