Skip to content
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. MY_SERIALDEVICE overrides MY_DEBUG_HWSERIAL
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

MY_SERIALDEVICE overrides MY_DEBUG_HWSERIAL

Scheduled Pinned Locked Moved Troubleshooting
13 Posts 3 Posters 1.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nelsonov
    wrote on last edited by
    #1

    I'm building a serial gateway for my RFM95 radios. I already have a funcitoning ESP8266 gateway for my NRF24 radios. I want to use my device's Serial1 for communication with my controller (RPi running Home Assistant). I would like the debug output to go out my devices USB port, called Serial. So, I would expect to have these two configuration elements:

    #define MY_DEBUG
    #define MY_DEBUG_HWSERIAL Serial
    
    #define MY_GATEWAY_SERIAL
    #define MY_SERIALDEVICE Serial1
    

    However, all output, debug and otherwise, goes out Serial1. If I reverse the configuration, then all output goes out Serial. MY_DEBUG_HWSERIAL does not seem to have any effect.

    The top part of my sketch is included below. Any insight would be appreciated.

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    //Want DEBUG output to Serial (USB Port)
    #define MY_DEBUG_HWSERIAL Serial  // Tried 'Serial' and 'Serial0'
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    // Set LOW transmit power level as default, if you have an amplified NRF-module and
    // power your radio separately with a good regulator you can turn up PA level.
    //#define MY_RF24_PA_LEVEL RF24_PA_LOW
    
    #define   RFM95_IRQ_PIN  6
    #define   RFM95_RST_PIN  9
    #define   RFM95_SPI_CS   10
    #define   MY_RADIO_RFM95
    #define   MY_DEBUG_VERBOSE_RFM95
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    //Want Gateway <-> Controller communication over Serial1
    #define MY_SERIALDEVICE Serial1
    
    // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
    //#if F_CPU == 8000000L
    #define MY_BAUD_RATE 38400
    //#endif
    
    // Enable inclusion mode
    //#define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    
    // Inverses behavior of inclusion button (if using external pullup)
    //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
    
    // Set inclusion mode duration (in seconds)
    //#define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    //#define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Inverses the behavior of leds
    //#define MY_WITH_LEDS_BLINKING_INVERSE
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  13  // the PCB, on board LED
    
    #include <MySensors.h>```

    https://keybase.io/nelsonov

    mfalkviddM 1 Reply Last reply
    0
    • N nelsonov

      I'm building a serial gateway for my RFM95 radios. I already have a funcitoning ESP8266 gateway for my NRF24 radios. I want to use my device's Serial1 for communication with my controller (RPi running Home Assistant). I would like the debug output to go out my devices USB port, called Serial. So, I would expect to have these two configuration elements:

      #define MY_DEBUG
      #define MY_DEBUG_HWSERIAL Serial
      
      #define MY_GATEWAY_SERIAL
      #define MY_SERIALDEVICE Serial1
      

      However, all output, debug and otherwise, goes out Serial1. If I reverse the configuration, then all output goes out Serial. MY_DEBUG_HWSERIAL does not seem to have any effect.

      The top part of my sketch is included below. Any insight would be appreciated.

      // Enable debug prints to serial monitor
      #define MY_DEBUG
      //Want DEBUG output to Serial (USB Port)
      #define MY_DEBUG_HWSERIAL Serial  // Tried 'Serial' and 'Serial0'
      
      // Enable and select radio type attached
      //#define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      // Set LOW transmit power level as default, if you have an amplified NRF-module and
      // power your radio separately with a good regulator you can turn up PA level.
      //#define MY_RF24_PA_LEVEL RF24_PA_LOW
      
      #define   RFM95_IRQ_PIN  6
      #define   RFM95_RST_PIN  9
      #define   RFM95_SPI_CS   10
      #define   MY_RADIO_RFM95
      #define   MY_DEBUG_VERBOSE_RFM95
      
      // Enable serial gateway
      #define MY_GATEWAY_SERIAL
      //Want Gateway <-> Controller communication over Serial1
      #define MY_SERIALDEVICE Serial1
      
      // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
      //#if F_CPU == 8000000L
      #define MY_BAUD_RATE 38400
      //#endif
      
      // Enable inclusion mode
      //#define MY_INCLUSION_MODE_FEATURE
      // Enable Inclusion mode button on gateway
      //#define MY_INCLUSION_BUTTON_FEATURE
      
      // Inverses behavior of inclusion button (if using external pullup)
      //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
      
      // Set inclusion mode duration (in seconds)
      //#define MY_INCLUSION_MODE_DURATION 60
      // Digital pin used for inclusion mode button
      //#define MY_INCLUSION_MODE_BUTTON_PIN  3
      
      // Set blinking period
      //#define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Inverses the behavior of leds
      //#define MY_WITH_LEDS_BLINKING_INVERSE
      
      // Flash leds on rx/tx/err
      // Uncomment to override default HW configurations
      //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  13  // the PCB, on board LED
      
      #include <MySensors.h>```
      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      @nelsonov MY_DEBUG_HWSERIAL does not have any effect because it does not exist in MySensors. I would guess you found some documentation that needs to be changed. Could you point me to where you found it?

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nelsonov
        wrote on last edited by
        #3

        Everything makes much more sense to me now. I found that macro in a discussion on this forum:

        https://forum.mysensors.org/topic/5624/serial-gateway-using-arduino-mega-how-to-set-what-serial-to-use/3

        Now that I have re-read that discussion I understand that I was seeing what I wanted to see.

        Thank you.

        https://keybase.io/nelsonov

        mfalkviddM 1 Reply Last reply
        0
        • N nelsonov

          Everything makes much more sense to me now. I found that macro in a discussion on this forum:

          https://forum.mysensors.org/topic/5624/serial-gateway-using-arduino-mega-how-to-set-what-serial-to-use/3

          Now that I have re-read that discussion I understand that I was seeing what I wanted to see.

          Thank you.

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by
          #4

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

          N 1 Reply Last reply
          0
          • scalzS Offline
            scalzS Offline
            scalz
            Hardware Contributor
            wrote on last edited by scalz
            #5

            it would be better to change it directly in MyHwESP8266.h , for a quick hack (just one line)

            mfalkviddM 1 Reply Last reply
            0
            • scalzS scalz

              it would be better to change it directly in MyHwESP8266.h , for a quick hack (just one line)

              mfalkviddM Offline
              mfalkviddM Offline
              mfalkvidd
              Mod
              wrote on last edited by mfalkvidd
              #6

              @scalz won't that cause the gateway serial output to the controller to also change device?

              The same define is used here: https://github.com/mysensors/MySensors/blob/development/core/MyGatewayTransportSerial.cpp#L32

              1 Reply Last reply
              0
              • scalzS Offline
                scalzS Offline
                scalz
                Hardware Contributor
                wrote on last edited by
                #7

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

                mfalkviddM 1 Reply Last reply
                0
                • scalzS scalz

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

                  mfalkviddM Offline
                  mfalkviddM Offline
                  mfalkvidd
                  Mod
                  wrote on last edited by
                  #8

                  @scalz OP wants debug prints to go to one serial device, and serial gateway prints to go to a different serial device.

                  1 Reply Last reply
                  1
                  • scalzS Offline
                    scalzS Offline
                    scalz
                    Hardware Contributor
                    wrote on last edited by scalz
                    #9

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

                    1 Reply Last reply
                    1
                    • mfalkviddM mfalkvidd

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

                      N Offline
                      N Offline
                      nelsonov
                      wrote on last edited by nelsonov
                      #10

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

                      The 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
                      }
                      

                      https://keybase.io/nelsonov

                      mfalkviddM 1 Reply Last reply
                      1
                      • N nelsonov

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

                        The 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
                        }
                        
                        mfalkviddM Offline
                        mfalkviddM Offline
                        mfalkvidd
                        Mod
                        wrote on last edited by
                        #11

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

                        N 1 Reply Last reply
                        0
                        • mfalkviddM mfalkvidd

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

                          N Offline
                          N Offline
                          nelsonov
                          wrote on last edited by
                          #12

                          @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'.

                          https://keybase.io/nelsonov

                          mfalkviddM 1 Reply Last reply
                          1
                          • N nelsonov

                            @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'.

                            mfalkviddM Offline
                            mfalkviddM Offline
                            mfalkvidd
                            Mod
                            wrote on last edited by mfalkvidd
                            #13

                            @nelsonov Great! There is no need to create an issue. If there is anything to discuss, we can discuss in the pull request thread.

                            Maybe call it something like "Add MY_DEBUGDEVICE to redirect debug output"

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            18

                            Online

                            11.7k

                            Users

                            11.2k

                            Topics

                            113.0k

                            Posts


                            Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • OpenHardware.io
                            • Categories
                            • Recent
                            • Tags
                            • Popular