MY_SERIALDEVICE overrides MY_DEBUG_HWSERIAL
-
Everything makes much more sense to me now. I found that macro in a discussion on this forum:
Now that I have re-read that discussion I understand that I was seeing what I wanted to see.
Thank you.
@nelsonov you're welcome. Always great when new people join the forum.
The suggestion to modify hwDebugPrint, as discussed in the thread you linked, seems like the best way forward to me.
You could manually replace all occurrences of MY_SERIALDEVICE in the implementation for your board (https://github.com/mysensors/MySensors/blob/development/hal/architecture/ESP8266/MyHwESP8266.cpp#L149 if you're using esp8266) with the serial device you want to use.
It is a bit of a hack, but if it works and you find it useful we should be able to modify a future release of the MySensors library to support redirecting debug output without having to hack the library.
-
it would be better to change it directly in MyHwESP8266.h , for a quick hack (just one line)
-
it would be better to change it directly in MyHwESP8266.h , for a quick hack (just one line)
-
@mfalkvidd
not sure to understand "change device" :blush:
I thought he wants to use another serial. Then you adviced to change all lines in the esp8266 hw layer cpp. That's why I said, it's quicker to change this directly in the .h as it's here it's defined.. -
@mfalkvidd
not sure to understand "change device" :blush:
I thought he wants to use another serial. Then you adviced to change all lines in the esp8266 hw layer cpp. That's why I said, it's quicker to change this directly in the .h as it's here it's defined.. -
@mfalkvidd
Oki, I just got it lol. was not obvious to me first time (I've never needed this)
I agree with you, forget what I said above ;) (because that would be applied globally) -
@nelsonov you're welcome. Always great when new people join the forum.
The suggestion to modify hwDebugPrint, as discussed in the thread you linked, seems like the best way forward to me.
You could manually replace all occurrences of MY_SERIALDEVICE in the implementation for your board (https://github.com/mysensors/MySensors/blob/development/hal/architecture/ESP8266/MyHwESP8266.cpp#L149 if you're using esp8266) with the serial device you want to use.
It is a bit of a hack, but if it works and you find it useful we should be able to modify a future release of the MySensors library to support redirecting debug output without having to hack the library.
@mfalkvidd I'm using an AVR board for my serial gateway. I modified hwDebugPrint in MyHwAVR.cpp with an extra #ifndef to look for MY_DEBUGDEVICE or copy MY_SERIALDEVICE to it. Then all occurrences of MY_SERIALDEVICE were changed to MY_DEBUGDEVICE.
I added this to my sketch:
#define MY_DEBUGDEVICE Serial // Redirect debug to SerialThe result was what I wanted. Controller <-> Gateway configuration went over Serial1 (/dev/ttyS0 on my RPi) and debugging output went to Serial (/dev/ttyACM0 on my RPi). This allows me to easily debug without having to take any special steps with my controller.
void hwDebugPrint(const char *fmt, ... ) { #ifndef MY_DEBUGDEVICE #define MY_DEBUGDEVICE MY_SERIALDEVICE #endif #ifndef MY_DISABLED_SERIAL char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_SERIAL // prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE) snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "), C_INTERNAL, I_LOG_MESSAGE, hwMillis()); MY_DEBUGDEVICE.print(fmtBuffer); #else // prepend timestamp MY_DEBUGDEVICE.print(hwMillis()); MY_DEBUGDEVICE.print(F(" ")); #endif va_list args; va_start (args, fmt ); vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args); #ifdef MY_GATEWAY_SERIAL // Truncate message if this is gateway node fmtBuffer[sizeof(fmtBuffer) - 2] = '\n'; fmtBuffer[sizeof(fmtBuffer) - 1] = '\0'; #endif va_end (args); MY_DEBUGDEVICE.print(fmtBuffer); MY_DEBUGDEVICE.flush(); #else (void)fmt; #endif } -
@mfalkvidd I'm using an AVR board for my serial gateway. I modified hwDebugPrint in MyHwAVR.cpp with an extra #ifndef to look for MY_DEBUGDEVICE or copy MY_SERIALDEVICE to it. Then all occurrences of MY_SERIALDEVICE were changed to MY_DEBUGDEVICE.
I added this to my sketch:
#define MY_DEBUGDEVICE Serial // Redirect debug to SerialThe result was what I wanted. Controller <-> Gateway configuration went over Serial1 (/dev/ttyS0 on my RPi) and debugging output went to Serial (/dev/ttyACM0 on my RPi). This allows me to easily debug without having to take any special steps with my controller.
void hwDebugPrint(const char *fmt, ... ) { #ifndef MY_DEBUGDEVICE #define MY_DEBUGDEVICE MY_SERIALDEVICE #endif #ifndef MY_DISABLED_SERIAL char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_SERIAL // prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE) snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "), C_INTERNAL, I_LOG_MESSAGE, hwMillis()); MY_DEBUGDEVICE.print(fmtBuffer); #else // prepend timestamp MY_DEBUGDEVICE.print(hwMillis()); MY_DEBUGDEVICE.print(F(" ")); #endif va_list args; va_start (args, fmt ); vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args); #ifdef MY_GATEWAY_SERIAL // Truncate message if this is gateway node fmtBuffer[sizeof(fmtBuffer) - 2] = '\n'; fmtBuffer[sizeof(fmtBuffer) - 1] = '\0'; #endif va_end (args); MY_DEBUGDEVICE.print(fmtBuffer); MY_DEBUGDEVICE.flush(); #else (void)fmt; #endif } -
@nelsonov very nice!
Would you be comfortable creating a pull request with these changes? Preferably for all platforms, but we can work together on that.@mfalkvidd I'm quite willing to open a pull request. This will be my first time. Do you want me to create an issue as well? Also what would this be called? Perhaps something like "Alternate Port Debugging"? It's hard to think of something that's 'googlable'.
-
@mfalkvidd I'm quite willing to open a pull request. This will be my first time. Do you want me to create an issue as well? Also what would this be called? Perhaps something like "Alternate Port Debugging"? It's hard to think of something that's 'googlable'.