homeassistant/smartsleep stops even trying after a few iterations



  • I have a small battery powered node I am using with smartsleep. For some reason though, it seems that after either a certain timeframe or certain number of iterations it just stops waking up and sending the pre/post smartsleep messages.

    677f3ff4-fa18-4907-b0fe-c909cbc66621-image.png

    I reset it and was watching the mqtt topic. You can see it's consistently reporting in roughly every 30 seconds or so. Just as expected. But then it just stops dead. I sent a state change command via home assistant and the state never changed, the node just seems to be stopping dead after X amount of time/iterations. Oddly enough I saw over the last few days, it will eventually wake up. I had it wake up yesterday morning at 1:46am and today at 4:36am. But when I have it configured to wake up every 30 seconds, doing once a day isn't going to work (im going to flood my yard that way) lol

    I am running mqtt esp gateway, all my other nodes and everything are still functional, so i do not believe it to be the gateway or mqtt. I am running 2.3.2 on the gateway and node in question. Using the easypcb/newbie board with a pro mini and all the necessary capacitors.

    Any thoughts or suggestions?



  • @CrankyCoder Can you provide your node sketch and also activate MY_DEBUG to get a log to provide here? This would be helpful for sure.



  • For the debug i would need to pull the node apart and bring inside and hook serial pins up to the computer. I can and will. Just need to wait for my meeting to end so I can leave my desk.

    For the sketch. Here it is.

    
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    #define MY_NODE_ID 18
    int BATTERY_SENSE_PIN = A0;
    // Enable repeater functionality for this node
    //#define MY_REPEATER_FEATURE
    #define CHILD_ID_HOSE 0
    #define CHILD_ID_VOLT 1
    uint32_t SLEEP_TIME = 30000;
    #include <MySensors.h>
    MyMessage msg(CHILD_ID_HOSE, V_STATUS);
    MyMessage msgVolt(CHILD_ID_VOLT, V_VOLTAGE);
    #define HOSE_ON 1  // GPIO value to write to turn on attached relay
    #define HOSE_OFF 0 // GPIO value to write to turn off attached relay
    int oldBatteryPcnt = 0;
    int in1 = 5;
    int in2 = 6;
    unsigned long start_time; 
    unsigned long timed_event = 1000;
    unsigned long current_time;
    
    void before()
    {
    	pinMode(in1, OUTPUT);
      pinMode(in2, OUTPUT);
    }
    
    void setup()
    {
    #if defined(__AVR_ATmega2560__)
      analogReference(INTERNAL1V1);
    #else
      analogReference(INTERNAL);
    #endif
     
     SendBatteryUpdate();
    }
    
    void presentation()
    {
    	// Send the sketch version information to the gateway and Controller
    	sendSketchInfo("Garden Soaker Hose Control", "1.0");
      present(CHILD_ID_HOSE,S_BINARY);
      present(CHILD_ID_VOLT, S_MULTIMETER);
    	digitalWrite(in1, LOW);
      digitalWrite(in2, LOW);
      current_time = millis();
      start_time = current_time;
     
    }
    
    
    void loop()
    {
      static bool first_message_sent = false;
      if ( first_message_sent == false ) {
        Serial.println( "Sending initial state..." );
        send_status_message();
        first_message_sent = true;
      }
      
      
      current_time = millis(); // update the timer every cycle
      if (current_time - start_time >= timed_event) {
        SendBatteryUpdate();
        start_time = current_time;  // reset the timer
      }
    
      #ifdef MY_DEBUG
        Serial.println("Going to sleep");
      #endif
      smartSleep(SLEEP_TIME);
      
      #ifdef MY_DEBUG
        Serial.println("Awake Now");
      #endif
      
    
    }
    
    void SendBatteryUpdate()
    {
      // get the battery Voltage
      int runningTotal=0;
      
      for (int x=0;x<10;x++)
      {
        runningTotal=runningTotal+analogRead(BATTERY_SENSE_PIN);
      }
      
      
      int sensorValue=runningTotal / 10;
      //int sensorValue = analogRead(BATTERY_SENSE_PIN);
    
      #ifdef MY_DEBUG
        Serial.println(sensorValue);
        //973 = 4.05v
      #endif
    
      
    
      
      
      
      #ifdef MY_DEBUG
        float batteryV  = (sensorValue * 3.34) / 1024;
        Serial.println(batteryV);
        batteryV = batteryV / 0.7802721088435374;
        //batteryV = batteryV / 0.4857457520453115;
        batteryV = batteryV / 0.5291330073696145;
        int batteryPcnt = (batteryV / 8.4) * 100;
        Serial.print("Battery Voltage: ");
        Serial.print(batteryV);
        Serial.println(" V");
      
        Serial.print("Battery percent: ");
        Serial.print(batteryPcnt);
        Serial.println(" %");
      #endif
      if (oldBatteryPcnt != batteryPcnt) {
        // Power up radio after sleep
        sendBatteryLevel(batteryPcnt);
        send(msgVolt.set(batteryV,1));
        oldBatteryPcnt = batteryPcnt;
        }
    
    
      Serial.print("sensorValue:");
      Serial.println(sensorValue);
      
    }
    
    void receive(const MyMessage &message)
    {
    	// We only expect one type of message from controller. But we better check anyway.
    	if (message.getType()==V_STATUS) {
    		// Change relay state
        directionControl(message.getBool()?HOSE_ON:HOSE_OFF);
    		//digitalWrite(message.getSensor()-1+RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
    		// Store state in eeprom
    		saveState(message.getSensor(), message.getBool());
    		// Write some debug info
    		Serial.print("Incoming change for sensor:");
    		Serial.print(message.getSensor());
    		Serial.print(", New status: ");
    		Serial.println(message.getBool());
    	}
    }
    
    void send_status_message()
    {
      
        send(msg.set(1));
    }
    
    void directionControl(int ONOFF) {
      // Set motors to maximum speed
      // For PWM maximum possible values are 0 to 255
      
      // Turn flip circuit on for 1/4 second
      if (ONOFF == HOSE_ON)
        {
          Serial.print("turning hose: ");
          Serial.println(ONOFF);
          digitalWrite(in1, HIGH);
          digitalWrite(in2, LOW);
          delay(250);
          send(msg.set(HOSE_ON));
        }
      else
        {
          // turn off circuit for 1/4 second
          digitalWrite(in1, LOW);
          digitalWrite(in2, HIGH);
          delay(250);
          send(msg.set(HOSE_OFF));
        }
      
      // disable
      digitalWrite(in1, LOW);
      digitalWrite(in2, LOW);
      
    }
    

    Thanks for taking a peek!!



  • @CrankyCoder My comments to your sketch:

    • be aware that the millis() counter also stops while your node sleeps,
    • when the node sleeps then it will not receive messages, may be someone can help out how to handle this (basically I think the node should request the child node state from MQTT after wake up),
    • be aware that presentation() can be called from controller at any time, not only at node startup, so I would move the non presentation code to setup().

    But for your main problem that the node doesn't wake up after some time I have no idea so far. Hopefully the log helps here.



  • Thanks πŸ™‚ Yeah super odd it just kind of stops. I can see the special "smart sleep" messages telling HA to go to sleep and then they just stop. I even took a repeater out of the equation to see if it was the repeater and the other nodes were going directly to the gateway, so now I only have the gateway and no change. Very strange.



  • I was able to get the module inside without powering it off and serial connected. So I was able to get some logging from while it's in it's broken state!!

    2541717 MCO:SLP:MS=30000,SMS=1,I1=255,M1=255,I2=255,M2=255
    2541725 !MCO:SLP:TNR
    2543659 TSM:FAIL:RE-INIT
    2543661 TSM:INIT
    2543669 TSM:INIT:TSP OK
    2543671 TSM:INIT:STATID=18
    2543673 TSF:SID:OK,ID=18
    2543677 TSM:FPAR
    2543679 ?TSF:MSG:SEND,18-18-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2545688 !TSM:FPAR:NO REPLY
    2545690 TSM:FPAR
    2545694 ?TSF:MSG:SEND,18-18-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2547703 !TSM:FPAR:NO REPLY
    2547705 TSM:FPAR
    2547709 ?TSF:MSG:SEND,18-18-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2549719 !TSM:FPAR:NO REPLY
    2549721 TSM:FPAR
    2549725 ?TSF:MSG:SEND,18-18-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2551730 MCO:SLP:MS=19999
    2551732 !TSF:SND:TNR
    2551736 !TSM:FPAR:FAIL
    2551738 TSM:FAIL:CNT=7
    2551740 TSM:FAIL:DIS
    2551742 TSF:TDI:TSL
    2552236 TSF:TDI:TSL
    2552238 MCO:SLP:WUP=-1
    2552240 TSF:TRI:TSB
    2552248 !TSF:SND:TNR
    Awake Now
    1002
    3.27
    Battery Voltage: 7.92 V
    Battery percent: 94 %
    sensorValue:1002
    Going to sleep
    2552256 MCO:SLP:MS=30000,SMS=1,I1=255,M1=255,I2=255,M2=255
    2552264 !MCO:SLP:TNR
    2562269 MCO:SLP:MS=19999
    2562271 !TSF:SND:TNR
    2562775 TSF:TDI:TSL
    
    

    Based on the parser. It seems it can't find a parent. I even plugged in my repeater and it's still saying the same thing. Haven't reset it at all yet, but kind of seems like maybe it's a problem with the radio?

    https://www.mysensors.org/build/parser?log=2541717 MCO%3ASLP%3AMS%3D30000%2CSMS%3D1%2CI1%3D255%2CM1%3D255%2CI2%3D255%2CM2%3D255 2541725 !MCO%3ASLP%3ATNR 2543659 TSM%3AFAIL%3ARE-INIT 2543661 TSM%3AINIT 2543669 TSM%3AINIT%3ATSP OK 2543671 TSM%3AINIT%3ASTATID%3D18 2543673 TSF%3ASID%3AOK%2CID%3D18 2543677 TSM%3AFPAR 2543679 %3FTSF%3AMSG%3ASEND%2C18-18-255-255%2Cs%3D255%2Cc%3D3%2Ct%3D7%2Cpt%3D0%2Cl%3D0%2Csg%3D0%2Cft%3D0%2Cst%3DOK%3A 2545688 !TSM%3AFPAR%3ANO REPLY 2545690 TSM%3AFPAR 2545694 %3FTSF%3AMSG%3ASEND%2C18-18-255-255%2Cs%3D255%2Cc%3D3%2Ct%3D7%2Cpt%3D0%2Cl%3D0%2Csg%3D0%2Cft%3D0%2Cst%3DOK%3A 2547703 !TSM%3AFPAR%3ANO REPLY 2547705 TSM%3AFPAR 2547709 %3FTSF%3AMSG%3ASEND%2C18-18-255-255%2Cs%3D255%2Cc%3D3%2Ct%3D7%2Cpt%3D0%2Cl%3D0%2Csg%3D0%2Cft%3D0%2Cst%3DOK%3A 2549719 !TSM%3AFPAR%3ANO REPLY 2549721 TSM%3AFPAR 2549725 %3FTSF%3AMSG%3ASEND%2C18-18-255-255%2Cs%3D255%2Cc%3D3%2Ct%3D7%2Cpt%3D0%2Cl%3D0%2Csg%3D0%2Cft%3D0%2Cst%3DOK%3A 2551730 MCO%3ASLP%3AMS%3D19999 2551732 !TSF%3ASND%3ATNR 2551736 !TSM%3AFPAR%3AFAIL 2551738 TSM%3AFAIL%3ACNT%3D7 2551740 TSM%3AFAIL%3ADIS 2551742 TSF%3ATDI%3ATSL 2552236 TSF%3ATDI%3ATSL 2552238 MCO%3ASLP%3AWUP%3D-1 2552240 TSF%3ATRI%3ATSB 2552248 !TSF%3ASND%3ATNR Going to sleep 2552256 MCO%3ASLP%3AMS%3D30000%2CSMS%3D1%2CI1%3D255%2CM1%3D255%2CI2%3D255%2CM2%3D255 2552264 !MCO%3ASLP%3ATNR 2562269 MCO%3ASLP%3AMS%3D19999 2562271 !TSF%3ASND%3ATNR 2562775 TSF%3ATDI%3ATSL 2562777 MCO%3ASLP%3AWUP%3D-1 2562779 TSF%3ATRI%3ATSB 2562787 !TSF%3ASND%3ATNR



  • @CrankyCoder Yes, your node tries to find his parent but gets no response. And additional the sleep and wake up happens at the same time. Interesting state, your node is in.



  • Well. I swapped the radio. No change. Reset the arduino. No change. So may be time to swap the arduino.



  • @CrankyCoder Yes, may be. But also may be the CE connection from Arduino to the radio is broken.



  • @virtualmkr CE is required to switch between send and receive mode of the radio.



  • Small update. I switched to a radio from different batch and seemed like that fixed it. Saw the smart sleep message in mqtt until I went to bed. But around 4:30am it stopped again. Im going to go pull it again and see what it's outputting. I feel like I need to hook up a bluetooth hc-05 or something so i can just connect over bluetooth at this point to get the serial data lol


Log in to reply
 

Suggested Topics

  • 4
  • 8
  • 20
  • 4
  • 9
  • 17

48
Online

11.4k
Users

11.1k
Topics

112.6k
Posts