Is serial.print blocked by mySensors?



  • Hi All,

    I am trying to implement a RDIF sensor (https://www.mysensors.org/build/rfid).
    I have copied and using this sketch example without it being modified.

    My issue is that the Serial.print outputs are not being output to the serial monitor because the #define MY_DEBUG data about the radio takes up the serial monitor, and no Serial.print from the main code ever gets through.

    I have even tested this by placing Serial.print("TestMessage to Serial that is not displaying."); throughout the sketch and only the radio debug info is displayed on the serial monitor.

    These messages should be getting through as in the instructions, "Hold tag in front of reader and your identifier should pop up." indicates that the serial prints should show up along with the radio debug info.

    I have also tried commenting out the //#define MY_DEBUG line, the radio debug info is not displayed, but neither is the program print lines.

    I also tried including the Serial.begin(115200); but with no luck.

    I have tried this with the latest mySensors 2.1.1, 2.1.0 and 2.0.0, all having the same effect.

    I have tried using Arduino IDE 1.6 and 1.8.

    My system is MAC OS 10.11, and my board is an Uno.

    I need this to work so I can debug the actual main sketch as I am making a few modifications. However this sketch does NOT work even without any modifications.

    Makes me wonder if the main sketch is even running??

    Some other user was also having the same problem on this sketch;

    @miro said in 💬 RFID Lock Sensor:

    @mfalkvidd

    I have followed the guide here (https://www.mysensors.org/build/rfid) to the letter. Yes, it could be me that have problems but this isn´t so hard project. Feels like something is missing?

    In the description it says:

    "To find out the unique ID of your tag just run the example while looking at serial monitor. Hold tag in front of reader and your identifier should pop up."

    This I did, but the monitor don`t show anything

    Regards,
    Sam.

    PS: I have tried it in the example MySensors sketch, and Serial Prints don't return anything, so it is not project specific;

    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>
    
    
    #define NODE_ID 3
    
    #define OPEN 1
    #define CLOSE 0
    
    MyMessage msg(NODE_ID, V_TRIPPED);
    
    uint8_t value = OPEN;
    
    
    void presentation()
    {
        present(NODE_ID, S_DOOR);
    }
    
    void loop()
    {
        value = value == OPEN ? CLOSE : OPEN;
        send(msg.set(value));
        Serial.print("TestMessage to Serial that is not displaying."); //<< Not displaying 
        sleep(10000);
    }

  • Admin

    Does it ever reach the loop-section then? Please post your log.



  • Hi!,

    Where did the following piece of code go?

    void setup()
    {
    Serial.Begin(115200);
    }
    

    That might help, since it will tell the sketch you want to talk to the outside world using serial communication.
    Have you tried that?

    Another option is adding this in your sketch:
    (before you include the mysensors lib!)

    #define MY_DEBUG 
    

    See: https://www.mysensors.org/build/debug



  • @Tag said in Is serial.print blocked by mySensors?:

    void setup()
    {
    Serial.Begin(115200);
    }

    I did try putting in a Serial.begin(115200); as I mentioned in my post, and yes it was in the void setup loop.

      void setup()
      { 
      Serial.begin(115200);
      }
    

    I also do have the #define MY_DEBUG and it outputs the radio debug only.
    Still did not fix it.



  • @hek It is reaching the loop, yep.

    Source Sketch:

    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>
    
    
    #define NODE_ID 3
    
    #define OPEN 1
    #define CLOSE 0
    
    MyMessage msg(NODE_ID, V_TRIPPED);
    
    uint8_t value = OPEN;
    
    void setup()
    {
    Serial.begin(115200);
    }
    
    void presentation()
    {
        present(NODE_ID, S_DOOR);
    }
    
    void loop()
    {
        value = value == OPEN ? CLOSE : OPEN;
        send(msg.set(value));
        Serial.print("TestMessage to Serial that is not displaying.");
        sleep(10000);
    }
    

    Serial Output:

    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=2)
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=2)
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=2)
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    

    (the fails are not of concern at this time as my test bench is quite far from the gateway and I need to add a capacitor to the radio. This just proves that the program is hitting the loop but not outputting any Serial.print.)


  • Admin

    No, it's not....

    The node is searching for a gateway or repeater. If you want it to enter the loop without finding a parent, you have to add the following to your sketch:

    #define MY_TRANSPORT_WAIT_READY_MS 1
    

    Which means it will only wait one millisecond before entering loop even if transport is unavailable.



  • @samburner3

    Strange, will have a look later today see if i can recreate your issue.
    Did you post your complete sketch?



  • Oh so the send messages are it attempting to connect to the gateway? I thaught they were the loop as they were appearing exactly once a second (hence the sleep(10000);)

    Even after moving next to the gateway it still won't connect? Gateway is up and ok:

    0;255;3;0;9;Starting gateway (RNNGA-, 2.0.0)
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSM:RADIO:OK
    0;255;3;0;9;TSM:GW MODE
    0;255;3;0;9;TSM:READY
    0;255;3;0;14;Gateway startup complete.
    0;255;0;0;18;2.0.0
    0;255;3;0;9;No registration required
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0, registration=1
    0;255;3;0;9;TSP:SANCHK:OK
    0;255;3;0;9;TSP:SANCHK:OK
    0;255;3;0;9;TSP:SANCHK:OK
    

    Anyway first things first;

    @hek Ok so I added the line #define MY_TRANSPORT_WAIT_READY_MS 1 to my sketch, however it did not turn blue in the IDE like other define tags have. This is using libray version 2.0.0.

    0_1485185424115_Screen Shot 2017-01-24 at 2.29.45 AM.png

    So I re-added the mysensors lib from the menu in the IDE (Sketch > Include Library > MySensors) to ensure it was added correctly.

    Then I tried to compile I got an error

       #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
        ^
    exit status 1
    Error compiling for board Arduino/Genuino Uno.
    

    I think I got this before but overlooked it. However the sketch is the same as the example so not sure what I am missing?

    My current sketch (with compile error):

    #include <MyConfig.h>
    #include <MySensors.h>
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    #define MY_TRANSPORT_WAIT_READY_MS 1
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    //#include <MySensors.h>
    
    #define NODE_ID 3
    
    #define OPEN 1
    #define CLOSE 0
    
    MyMessage msg(NODE_ID, V_TRIPPED);
    
    uint8_t value = OPEN;
    
    void setup()
    {
    Serial.begin(115200);
    }
    
    void presentation()
    {
        present(NODE_ID, S_DOOR);
    }
    
    void loop()
    {
        value = value == OPEN ? CLOSE : OPEN;
        send(msg.set(value));
        Serial.print("TestMessage to Serial that is not displaying.");
        sleep(10000);
    }```

  • Admin

    Put MySensors include at the bottom of the file (or at least below the defines)



  • @hek Ok have done so:

    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    #define MY_TRANSPORT_WAIT_READY_MS 1
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    //#include <MySensors.h>
    
    #define NODE_ID 3
    
    #define OPEN 1
    #define CLOSE 0
    
    #include <MySensors.h>
    
    MyMessage msg(NODE_ID, V_TRIPPED);
    
    uint8_t value = OPEN;
    
    void setup()
    {
    Serial.begin(115200);
    }
    
    void presentation()
    {
        present(NODE_ID, S_DOOR);
    }
    
    void loop()
    {
        value = value == OPEN ? CLOSE : OPEN;
        send(msg.set(value));
        Serial.print("TestMessage to Serial that is not displaying.");
        sleep(10000);
    }
    

    It now compiles ok however the MY_TRANSPORT_WAIT_READY_MS 1 is still not blue. (Just a sanity check this define feature exists in library version 2.0.0. correct?)

    Also still no serial prints:

    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=2)
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 2-2-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=2)
    


  • @hek Ok I tried again using lib version 2.1.1. and it works!

    3 TSM:INIT
    4 TSF:WUR:MS=1
    11 TSM:INIT:TSP OK
    13 TSF:SID:OK,ID=2
    14 TSM:FPAR
    1613 TSF:MSG:SEND,2-2-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    1620 MCO:BGN:STP
    1622 MCO:BGN:INIT OK,TSP=0
    1625 !MCO:SND:NODE NOT REG
    TestMessage to Serial that is not displaying.1627 MCO:SLP:MS=10000,SMS=0,I1=255,M1=255,I2=255,M2=255
    1635 !MCO:SLP:TNR
    3621 !TSM:FPAR:NO REPLY
    3623 TSM:FPAR
    5223 TSF:MSG:SEND,2-2-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    7230 !TSM:FPAR:NO REPLY
    7232 TSM:FPAR
    8832 TSF:MSG:SEND,2-2-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    10839 !TSM:FPAR:NO REPLY
    10841 TSM:FPAR
    

    However the '1' is still not blue
    0_1485186778237_Screen Shot 2017-01-24 at 2.52.20 AM.png

    and got the compile warning

    warning: "MY_TRANSPORT_WAIT_READY_MS" redefined
     #define MY_TRANSPORT_WAIT_READY_MS 1
    note: this is the location of the previous definition
     #define MY_TRANSPORT_WAIT_READY_MS (0ul)
    

    Glad it is working, however would the output suggest it is not connected to the gate way or just not registered? (forgive me I should RTFM go read the serial debug output message documentation)

    Is the MY_TRANSPORT_WAIT_READY_MS needed when not just connected to the gateway or when its has not been 'included' or regestered?

    So the main code im MySensors won't run until what condition is met? (forgive me again I am still learning the exciting mySensors lib 🙂


Log in to reply
 

Suggested Topics

  • 3
  • 2
  • 6
  • 1
  • 5

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts