homieiot / homie-esp8266

💡 ESP8266 framework for Homie, a lightweight MQTT convention for the IoT
http://homieiot.github.io/homie-esp8266
MIT License
1.36k stars 308 forks source link

Exception on going to deep sleep #113

Closed EpoxyRaisin closed 8 years ago

EpoxyRaisin commented 8 years ago

On my sensor node i want to fall into deep sleep for a specific time span.

I am doing this:

void loopHandler() {
    //some code before

    Homie.disconnectMQTT();
    delay(100);
}

After MQTT has disconnected i´m catchig the event to fall into deepsleep.

void onHomieEvent(HomieEvent event) {
  switch(event) {
    case HOMIE_MQTT_DISCONNECTED:
      // Do whatever you want when MQTT is disconnected in normal mode
      ESP.deepSleep(5000000);
      delay(100);
      break;
  }
}

On reaching the deep sleep command all i got is a exception.

Has anybody undertaken same issue?

marvinroger commented 8 years ago

Please try something like this:

bool sleepFlag = false;

void onHomieEvent(HomieEvent event) {
  switch(event) {
    case HOMIE_MQTT_DISCONNECTED:
      sleepFlag = true;
      break;
  }
}

void loop() { // The main Arduino loop, not the loopHandler
  if (sleepFlag == true) {
    ESP.deepSleep(5000000);
  }
}
marvinroger commented 8 years ago

Just pinging you @DaSepp, any news? Otherwise I'll close this, as this is moreover an esp8266/Arduino issue more than an issue with homie-esp8266.

EpoxyRaisin commented 8 years ago

As i´m very busy the last weeks i didn´t verify your solution. But anyway, as nobody else is effected you can close this thread.

marvinroger commented 8 years ago

No problem, feel free to reopen if needed. :)