Node not working very well when MY_DEBUG not defined



  • Hello everybody,

    When MY_DEBUG is not defined in my node, the gateway doesn't received every time the ACK send by the node.

    I use MySensors V2.3.1 is both gateway and node.
    I use a nrf24l01+pa+lna with Socket Adapter Board with arduino pro mini 5V



  • @snyfir Without seeing your code we can't comment too much, but just judging from what you are saying, if it works fine with debug turned on, but not well with it off, you may need some short delay in your main loop. The delay in time that it takes to do the serial sends may be enough to make it work. Putting the delay in there may mimic those delays. Something like this might work:

    #ifdef DEBUG
        Serial.println("your debug message");
    #else
        delay(1);
    #endif
    

    You probably only need to do this for one debug print and then adjust the delay time to your needs.

    Outside of that, post your code and we can help better.



  • thank you @dbemowsk for your answer

    my code is:

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    
    // Enable IRQ pin
    #define MY_RX_MESSAGE_BUFFER_FEATURE
    #define MY_RF24_IRQ_PIN (2)
    
    // RF24 PA level
    #define MY_RF24_PA_LEVEL (RF24_PA_HIGH)
    
    // Enable repeater functionality
    #define MY_REPEATER_FEATURE
    
    // Define pins
    #define SIREN 5
    
    // Includes
    #include <MySensors.h>
    
    // Others
    MyMessage msg(0, V_CUSTOM);
    unsigned long _sirenTime = 0;
    int _sirenState = 0;
    int _bipNumber = 0;
    int _sirenLevel = 100;
    
    void before()
    {
      pinMode(SIREN, OUTPUT);
      digitalWrite(SIREN, LOW);
      stopSiren();
    }
    
    void setup() {
    
    }
    
    void presentation() {
      sendSketchInfo("Siren", "1.0");
      present(0, S_CUSTOM);
    }
    
    void receive(const MyMessage &myMsg)
    {
      if (myMsg.type == V_CUSTOM) {
        String message = myMsg.getString();
    
        if (message == "stop") {
          stopSiren();
          send(msg.set(F("stopped by user")));
        } else if (message == "start") {
          startSiren(5, 100);
          send(msg.set(F("started")));
        }
      }
    }
    
    void loop() {
      manageSiren();
      wait(100);
    }
    
    void startSiren(char bipBumber, char level) {
      _bipNumber = bipBumber;
      _sirenLevel = level;
      _sirenTime = 0;
      _sirenState = 1;
    }
    
    void stopSiren() {
      _sirenState = 0;
      stopSirenSound();
    }
    
    bool isSirenOn() {
      return _sirenState != 0;
    }
    
    void manageSiren() {
      if (_sirenState == 0) {
        // nothing to do
      } else if ((_sirenState % 2 == 1 && _sirenState < _bipNumber * 2 + 2) && millis() - _sirenTime >= 1000) {
        startSirenSound(_sirenLevel);
        _sirenTime = millis();
        _sirenState++;
      } else if ((_sirenState % 2 == 0 && _sirenState < _bipNumber * 2 + 2) && millis() - _sirenTime >= 100) {
        stopSirenSound();
        _sirenTime = millis();
        _sirenState++;
      } else if ((_sirenState == _bipNumber * 2 + 2) && millis() - _sirenTime >= 60000) {
        stopSiren();
        send(msg.set(F("stopped")));
      }
    }
    
    void startSirenSound(char level) {
        analogWrite(SIREN, map(level, 0, 100, 0, 255));
    }
    
    void stopSirenSound() {
        analogWrite(SIREN, 0);
    }
    

    I try with delay(1) but it doesn't change anything, maybe i should increase the delay.
    I have an other node which have the same issue.



  • @snyfir Looking at your code, I don't see any debug prints that you have defined yourself. You will however get debug info from the MySensors library. Also, I need to correct myself. You are better off using wait(ms) over delay(ms). Delay will halt all MySensors processing for the specified period of time where using wait(ms) will allow the process() method to continue to run.

    I see that you have a call to wait(100) in your main loop. Did you just add that, or is that part of the code that fails with debug off?



  • @dbemowsk
    I didn't change anything of my code. This is the one who don't work well when I comments #define MY_DEBUG
    but if I don't comments this line it work well.



  • Nobody has a clue ?



  • Do you have capacitors on the nrf24l01+ board?

    I am just guesing here but maybe with debug it slows things down enough to allow power to the nrf to recover but without the debug code running it is a little faster and not allowing the rnf to get full power?

    We don't know what 'siren' actually is or how it is connected, so I suspect a power issue might be at play here.

    Maybe also try with #define MY_RF24_PA_LEVEL (RF24_PA_LOW) just to see if it makes a difference.

    Other than that, I too am stumped.



  • I confirm. Looks like a huge bug :). A node with an led was assembled. Uploaded sketch from examples - actuator relays. In the mysensors controller I send a command with a confirmation flag, the led lights up, there is no response message with confirmation. In the sketch I activate debag and then send the command with the acknowledgement, the reply message arrives. Hw for nodes is nrf52, atmega328 were used. In addition to the mysensors controller, the Majordomo controller has been tested. Same thing. Gateway was connected to a serial monitor. The error was also reproduced by other users in the community.



  • @Snyfir: Maybe a timing issue in MySensors code? Are both node and gateway on the same kind of hardware?

    It seems also (at least for me) that 2.3.1 may be more concerned by timing issues than 2.3.0, even if I don't saw in the code what could be the real cause. You may perhaps revert to 2.3.0 and see if you still have this kind of issue?



  • My problem is temporarily solved(nrf5). Delivery confirmation to the controller come steadily if the file MyTransport.ccp (line 723) add:

    #if !defined(MY_DEBUG)
    wait(5);
    #endif
    

    based on:
    https://github.com/mysensors-rus/MySensors/commit/06f8083b785237b8d1b430a142fe3d9a3cd6f7ff



  • @berkseo said in Node not working very well when MY_DEBUG not defined:

    My problem is temporarily solved(nrf5). Delivery confirmation to the controller come steadily if the file MyTransport.ccp (line 723) add:

    #if !defined(MY_DEBUG)
    wait(5);
    #endif
    

    based on:
    https://github.com/mysensors-rus/MySensors/commit/06f8083b785237b8d1b430a142fe3d9a3cd6f7ff

    The bug will be fix in the 2.3.2 release i suppose so


 

355
Online

8.9k
Users

9.6k
Topics

100.9k
Posts