Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Barnabybear
#27688 Hi, try putting a reset in strieght after it wakes from deepsleep. I read someware that wake from deepsleep & reset are not quite the same.
Code: Select all  } else {
       Serial.println("Can't get HVAC status") ;

What do you get if you swap this to print (acState) I see from the //, you have checked the line earlier.
User avatar
By BryanLee
#27758
Barnabybear wrote:Hi, try putting a reset in strieght after it wakes from deepsleep. I read someware that wake from deepsleep & reset are not quite the same.


When waking from deep sleep, the ESP starts over with the setup function. If I put and ESP.reset() there, I will only have an endless loop of resetting the ESP. Unless there is a way of determining if the ESP is in it's initial boot, or if it's woken from deep sleep.
Barnabybear wrote:
Code: Select all  } else {
       Serial.println("Can't get HVAC status") ;

What do you get if you swap this to print (acState) I see from the //, you have checked the line earlier.


I do print out acState, before the if, else if, else statement. Except for initial boot, it always returns the null string.
Code: Select allSerial.print("HVAC State: ") ;
  Serial.println(acState) ;
 
  if (acState == "cooling") {
       Serial.println("HVAC cooling, check vibration sensor to see if window AC is running") ;
       if (!acRunning()) {
         powerAC() ;
       }
  } else if (acState == "off") {
       Serial.println("HVAC off, check vibration sensor to see if window AC is off") ;
       if (acRunning()) {
         powerAC() ;
       }
  } else {
       Serial.println("Can't get HVAC status") ;
  }
User avatar
By martinayotte
#27760
BryanLee wrote:Unless there is a way of determining if the ESP is in it's initial boot


I don't know if that can help since I didn't tried it in deepsleep context.

Code: Select allrst_info *rinfo;
rinfo = ESP.getResetInfoPtr();
Serial.println(String("ResetInfo.reason = ") + (*rinfo).reason);
User avatar
By BryanLee
#27761
martinayotte wrote:
BryanLee wrote:Unless there is a way of determining if the ESP is in it's initial boot


I don't know if that can help since I didn't tried it in deepsleep context.

Code: Select allrst_info *rinfo;
rinfo = ESP.getResetInfoPtr();
Serial.println(String("ResetInfo.reason = ") + (*rinfo).reason);


Looks like it's working. Initially I got a compile error, but then I found your post at viewtopic.php?p=26862

Turns out I didn't need to include Arduino.h, but the external C include I did:

Code: Select allextern "C" {
  #include <user_interface.h>
}


From there I found all the values for rst_info.reason at https://github.com/devicehive/esp8266-f ... nterface.h . 0 = boot, 4 = soft reset, 5 = wake from deep sleep.

So I added this code to my setup() function, right after setting up the serial debugging port

Code: Select all  Serial.println("We're alive") ;
  rst_info *rinfo;
  rinfo = ESP.getResetInfoPtr();
  Serial.println(String("ResetInfo.reason = ") + (*rinfo).reason);

  // if we woke from deep sleep, do a full reset
  // this is needed because http gets from deep sleep are not properly returned.
  // test to see if this is fixed in future esp8266 libraries

  if ((*rinfo).reason == REASON_DEEP_SLEEP_AWAKE) {
    Serial.println("Woke from deep sleep, performing full reset") ;
    ESP.restart() ;
  }


This very much feels like a work-around for a bug, perhaps somewhere in the esp8266 libraries, or maybe the chip itself? It will take better programmers than I to determine that.

But the good news is, I have gone through many sleep/wake cycles, and it now works great. I have yet to see a null string returned. Thank you! :D