Remote debug messages with V_TEXT


  • Hero Member

    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
    

  • Hardware Contributor

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


Log in to reply
 

Suggested Topics

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts