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!
4 out of 4
Suggested Topics
-
Arduino Celebrates 10 years (Malmö/Sweden)
Announcements • 29 Mar 2014, 17:08 • hek 29 Mar 2014, 17:08 -
Saving last known good state, but not in EEPROM
Development • 30 Jan 2024, 18:46 • OldSurferDude 15 Jan 2025, 08:51 -
Sending offset to node
Development • 31 Jan 2025, 00:59 • bsl88k 4 Feb 2025, 12:14 -
LAN8720A - will mysensors work with this module
Development • 13 Nov 2024, 17:06 • Marcin 15 Nov 2024, 10:59 -
Home Assistant/MySensors quirks
Development • 25 days ago • OldSurferDude 25 days ago -
Gateway without a radio
Development • 12 Jan 2025, 23:19 • OldSurferDude 14 Jan 2025, 22:07