Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of deepsleep #26

Open
shajek opened this issue Dec 15, 2017 · 3 comments
Open

Use of deepsleep #26

shajek opened this issue Dec 15, 2017 · 3 comments

Comments

@shajek
Copy link
Contributor

shajek commented Dec 15, 2017

Hello again,
if i try use DeepSleep, sometime its work sometime not ....


if (0 == strcmp(topic, (const char*) sleep.c_str())) {
       val = atoi(msg);
       //Serial.printf("i am in IF for slep");
        if(val > 0) {
            ESP.deepSleep(val * 1000000);
            delay(500); 
        }
    }

if i have uncommented Serial.print, deepsleep work correctly (delay on the end is the same story, without it deepsleep crash)
but if i dont have Serial.print or i have some delay deepsleep crash again

[onMqttMessage] Message arrived [esp8266-in/mesh_esp8266-1/sleep] '60'
[onMqttDisconnect] Disconnected from MQTT: 0

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v00000000
~ld

EDIT: okey, in higher numbers of sleep, it will crash with Serial.print either

@PhracturedBlue
Copy link
Owner

i don't think you can sleep with a mesh node. If you shut off the wireless, then you can't act as a relay, and you will miss all messages not just for yourself but for your child nodes.
I suppose we could define a new type of node that can only act as an endpoint and does not act as a relay. that node would likely need to shutdown its connections before entering sleep and then wake up and reconnect. That is an expensive process, but could be done for nodes that only send data. It doesn't seem like it would be that much work, but I haven't really looked yet

@shajek
Copy link
Contributor Author

shajek commented Dec 15, 2017

Yop, i think like you. This "battery node" cannot act like a relay (maybe yes, when broker send to all battery nodes same sleep time). But yep, is useless to starting AP for meshing ... because time and energy...
From serial output you see, that message
[onMqttDisconnect] Disconnected from MQTT: 0
Problem, is, that right now, deepsleep working, but very unstable ... 2/10 sleeps crash .. but 8/10 works good

@PhracturedBlue
Copy link
Owner

your crash report isn't helpful, since there is no backtrace to debug.
I am only guessing, but to make deepsleep work we probably need to take down any mqtt/socket connections before entering deep-sleep.
But because of the asynchronous nature of the code you probably need something like:

void loop() {
  if (sleep_ready) {
    sleep_ready = false;
    ESP.deepsleep(...);
  }
  if (sleep) {
   sleep = false;
   WiFi.disconnect();
   sleep_ready = true;
  }
}

As I said though, that is just a guess and is untested. Also, it would be better to have an ability to flush all messages before shutdown, since it is possible for the network layer to cache transmissions, and if you want to wakeup, do something, then go back to sleep we want to ensure that any messages are actually transmitted during 'do-something'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants