Remote debug messages with V_TEXT
-
Sometimes I want to have debug information from my nodes while these are not connected through serial. I.e. to discover "random" freezes of an outside weather node. So I rewrote a familiar macro
#define LOCAL_DEBUG #ifdef LOCAL_DEBUG #define Sprint(a) (Serial.print(a)) // macro as substitute for print, enable if no print wanted #define Sprintln(a) (Serial.println(a)) // macro as substitute for println #else // no print #define Sprint(a) #define Sprintln(a) #endif
to include "remote debugging" by using "sprintf()" (formatted print). It is a (working) first attempt with limitations. Suggestions for improvement are more than welcome. The debug information is sent with V_TEXT and needs to be handled by the controller or a "logging node" (I will publish one soon)
// Helper for Debug: 1 = Serial debug output ; 2 = V_TEXT remote output ; else no debug // Use Formats described in fprint() : http://www.cplusplus.com/reference/cstdio/printf/ // Example: Printf("Temp %2d Hum %2d\n", temperature, humidity); // warning: max print size < 24 ; float = NOT supported in Arduino, you need to convert it yourself, ie. dtostrf(Temperature, 5, 2, tempBuf) #define _DEBUG 2 // 0 = no output ; 1 = Serial debug output ; 2 = V_TEXT remote output #if _DEBUG == 1 // Serial output char printBuf[24] ; // need temporary buffer #define Printf(...) { sprintf(printBuf, __VA_ARGS__) ; Serial.print(printBuf);} // macro to substitute Printf() #elif _DEBUG == 2 // if remote debug you need to define a child and present it to the controller #define DEBUG_CHILD_ID 10 // Child id of V_TEXT MyMessage debugMsg(DEBUG_CHILD_ID, V_TEXT); // get the debug message ready char printBuf[24] ; // need temporary buffer #define Printf(...) { sprintf(printBuf, __VA_ARGS__) ; send(debugMsg.set(printBuf)); } // macro to substitute Printf() #else // No debug wanted #define Printf(...) #endif
-
@AWI - Woaw! Great idea Awi!
Looks awesome - keep it up!
-
Very nice... love to have this
-
@AWI This sounds extremely cool. I will try it asap! Thanks for sharing!
1 out of 4
Suggested Topics
-
Arduino Celebrates 10 years (Malmö/Sweden)
Announcements • 29 Mar 2014, 17:08 • hek 29 Mar 2014, 17:08 -
MQTT-Help me understand about the MQTT Gateway.
Development • 27 days ago • dpcons 16 days ago -
PJON and Minicore not working
Development • 7 days ago • Trand 7 days ago -
Home Assistant/MySensors quirks
Development • 12 days ago • OldSurferDude 12 days ago -
Saving last known good state, but not in EEPROM
Development • 30 Jan 2024, 18:46 • OldSurferDude 15 Jan 2025, 08:51 -
Radio waking up for no reason.
Development • 4 Jul 2020, 21:09 • Sasquatch 15 Jan 2025, 08:33