Open satssehgal opened 6 years ago
I haven't tested the code yet, but by looking at it, it looks like your doing to much to soon and not enough time given to the IP stack to actually send all the packets, not sure about this though.
Will test the code later.
Would be nice though if you could decode your stack trace. (Make sure the stack trace is from the exact same build)
@timpur thanks Tim. So maybe this can help zero in on the issue. when i comment out Homie.onEvent(onHomieEvent); it compiles and works fine, it just doesn't enter deep sleep. Also i changed ESP.deepsleep() to Homie.doDeepSleep() and the loop went away but now it just crashes after a few min. I just dont know what im doing wrong there.
Sorry what do you mean decide stack trace?
@satssehgal Thanks for opening a new ticket. You still need some practice how to format source code in a ticket though. ;) Using preview and the github markdown cheat-sheet might get you up and running.
I think @timpur wanted to write "decode" stack trace. For instance with one of these tools: https://github.com/me-no-dev/EspExceptionDecoder https://github.com/littleyoda/EspStackTraceDecoder
Does you code run, when you leave out the sleep stuff?
Can you really attach two pins to one debouncer? I haven't checked, but I don't think so. What do you think will happen when your ESP is sleeping and the door opens/closes or your water pin changes state?
You’re totally right Sorry I should have stated that I created another denounce. I’ll post the updated code soon when I’m home. That was the other change I made
Sent from my iPhone
On Jun 14, 2018, at 4:01 AM, luebbe notifications@github.com wrote:
Can you really attach two pins to one debouncer? I haven't checked, but I don't think so. What do you think will happen when your ESP is sleeping and the door opens/closes or your water pin changes state?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
@luebbe thanks for the markdown cheatsheet idea. Didn't know it existed. How did i do? :) So you're right i did add a debounce.
@timpur @luebbe So this code compiles and works only if i take out the deep sleep function. If i want to run this on a battery say using an ESP-01, it wont last long.
#include <Homie.h>
#include <ArduinoJson.h>
const int PIN_DOOR = D1;
const int PIN_WATER = D2;
bool sleepFlag = false;
Bounce debouncer_door = Bounce(); // Bounce is built into Homie, so you can use it without including it first
Bounce debouncer_water = Bounce(); // Bounce is built into Homie, so you can use it without including it first
int lastDoorValue = -1;
int lastWaterValue = -1;
HomieNode doorNode("door", "door");
HomieNode waterNode("water", "water");
void loopHandler() {
int doorValue = debouncer_door.read();
int waterValue = debouncer_water.read();
if (doorValue != lastDoorValue) {
Homie.getLogger() << "Door is now " << (doorValue ? "open" : "closed") << endl;
doorNode.setProperty("open").send(doorValue ? "true" : "false");
lastDoorValue = doorValue;
}
if (waterValue != lastWaterValue) {
Homie.getLogger() << "Water sensor state is " << (waterValue ? "Leak Detected" : "clear") <<
endl;
waterNode.setProperty("clear").send(waterValue ? "true" : "false");
lastWaterValue = waterValue;
}
}
void onHomieEvent(const HomieEvent& event) {
switch(event.type) {
case HomieEventType::MQTT_READY:
Homie.getLogger() << "MQTT connected, preparing for deep sleep..." << endl;
Homie.prepareToSleep();
break;
case HomieEventType::READY_TO_SLEEP:
Homie.getLogger() << "Ready to sleep" << endl;
Homie.doDeepSleep();
break;
}
}
void setup() {
Serial.begin(115200);
Serial << endl << endl;
Homie.disableResetTrigger();
pinMode(PIN_DOOR, INPUT);
pinMode(PIN_WATER, INPUT);
digitalWrite(PIN_DOOR, HIGH);
digitalWrite(PIN_WATER, HIGH);
debouncer_door.attach(PIN_DOOR);
debouncer_water.attach(PIN_WATER);
debouncer_door.interval(50);
debouncer_water.interval(50);
Homie_setFirmware("my-sensors", "1.0.0");
Homie.setLoopFunction(loopHandler);
doorNode.advertise("open");
waterNode.advertise("clear");
//Homie.onEvent(onHomieEvent);
Homie.setup();
}
void loop() {
Homie.loop();
debouncer_door.update();
debouncer_water.update();
}
Found updating the AsyncMqttClient
lib fixed this for me, pio lib install AsyncMqttClient
Also, make sure GPIO16 is connected to RESET, to be woken up from deep sleep.
@n8wj Thanks I actually didn’t do that. Would you suggest I solder a wire between DO and RST on the D1 mini or use a resistor?
For the ESP-01 can someone correct me if I’m wrong in saying that gpio is that really tiny pin just above the ground pin? Has anybody been able to solder that?
Sent from my iPhone
On Jun 14, 2018, at 9:22 AM, Jeremy McNamara notifications@github.com wrote:
Also, make sure GPIO16 is connected to RESET, to be woken up from deep sleep. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
@timpur I have version 0.8.2 installed so it looks like it’s updated. I still have the issue but will try the reset to D0 button connected
Sent from my iPhone
On Jun 14, 2018, at 9:13 AM, Tim P notifications@github.com wrote:
Found updating the AsyncMqttClient lib fixed this for me, pio lib install AsyncMqttClient
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
@n8twj @timpur so tying D0 and RST didnt fix the situation. In node red I have the correct status reporting but it continues to report every second. In serial monitor Arduino IDE, same crazy loop.
Any other suggestiosn?
@satssehgal Try the latest everything? 2.4.1 Arduino core also ?
Your code works for me now :)
@timpur yeah I’m running 2.4.1 Still same issue
My board is wires as follows. Maybe it’s my config
I’ll just put the config for the door sensors, water sensor is the same except different pin
D0 —-> RST Door sensor lead 1 —-> 3V3 Door sensor lead 2 ——> D1 D1 —-> 4.7k resistor —-> Ground ( I’ve tried this with a straight wire and resistors from 2.2k to 10k)
I’m sure it’s something silly I’ve missed
On Jun 14, 2018, at 5:52 PM, Tim P notifications@github.com wrote:
@satssehgal Try the latest everything? 2.4.1 Arduino core also ?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
@timpur the code compiles fine but when I put it on the D1 mini it goes through that crazy loop. :(
BTW here are my stacktrace results...again i have the latest libs and arduino core....
Decoding stack results
0x402145a6: std::function ::operator()(void*, AsyncClient*) const at /Users/MBP/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/functional line 2465
0x40214675: AsyncClient::_close() at /Users/MBP/Documents/Arduino/libraries/ESPAsyncTCP-master/src/ESPAsyncTCP.cpp line 339
0x402146f4: AsyncClient::close(bool) at /Users/MBP/Documents/Arduino/libraries/ESPAsyncTCP-master/src/ESPAsyncTCP.cpp line 206
0x40214329: AsyncClient::send() at /Users/MBP/Documents/Arduino/libraries/ESPAsyncTCP-master/src/ESPAsyncTCP.cpp line 266
0x4021236d: AsyncMqttClient::disconnect(bool) at /Users/MBP/Documents/Arduino/libraries/async-mqtt-client-master/src/AsyncMqttClient.cpp line 709
0x4020f44a: HomieInternals::BootNormal::_onMqttPublish(unsigned short) at /Users/MBP/Documents/Arduino/libraries/homie-esp8266-2.0.0/src/Homie/Boot/BootNormal.cpp line 555
0x40220b62: std::_Function_handler (HomieInternals::BootNormal*, std::_Placeholder1>)> >::_M_invoke(std::_Any_data const&, unsigned short) at /Users/MBP/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/functional line 2073
0x40212aef: std::function ::operator()(unsigned short) const at /Users/MBP/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/functional line 2465
0x40212b6d: AsyncMqttClient::_onPubAck(unsigned short) at /Users/MBP/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/functional line 2174
0x4020df9c: std::_Function_base::_Base_manager (HomieInternals::BootNormal*, std::_Placeholder1>)> >::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) at /Users/MBP/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/functional line 1931
0x40220b40: std::_Function_handler (HomieInternals::BootNormal*, std::_Placeholder1>)> >::_M_invoke(std::_Any_data const&, unsigned short) at /Users/MBP/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/functional line 2069
0x40220d8e: std::_Function_handler (AsyncMqttClient*, std::_Placeholder1>)> >::_M_invoke(std::_Any_data const&, unsigned short) at /Users/MBP/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/functional line 2073
0x402139d8: AsyncMqttClientInternals::PubAckPacket::parseVariableHeader(char*, unsigned int, unsigned int*) at /Users/MBP/Documents/Arduino/libraries/async-mqtt-client-master/src/AsyncMqttClient/Packets/PubAckPacket.cpp line 25
0x40212a41: AsyncMqttClient::_onData(AsyncClient*, char*, unsigned int) at /Users/MBP/Documents/Arduino/libraries/async-mqtt-client-master/src/AsyncMqttClient.cpp line 436
0x40211c50: std::_Function_base::_Base_manager (AsyncMqttClient*, std::_Placeholder1>)> >::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) at /Users/MBP/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/functional line 1931
0x40220d6c: std::_Function_handler (AsyncMqttClient*, std::_Placeholder1>)> >::_M_invoke(std::_Any_data const&, unsigned short) at /Users/MBP/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/functional line 2069
0x40212b40: AsyncMqttClient::_onPubAck(unsigned short) at /Users/MBP/Documents/Arduino/libraries/async-mqtt-client-master/src/AsyncMqttClient.cpp line 576
0x40212a74: std::_Function_handler ::_M_invoke(const std::_Any_data &, void *, AsyncClient *, void *, unsigned int) at /Users/MBP/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/functional line 2073
0x40214774: AsyncClient::_recv(tcp_pcb*, pbuf*, long) at /Users/MBP/Documents/Arduino/libraries/ESPAsyncTCP-master/src/ESPAsyncTCP.cpp line 415
0x402147b8: AsyncClient::_s_recv(void*, tcp_pcb*, pbuf*, long) at /Users/MBP/Documents/Arduino/libraries/ESPAsyncTCP-master/src/ESPAsyncTCP.cpp line 493
0x4022b15c: tcp_input at core/tcp_in.c line 435
0x4022f081: ip4_input at core/ipv4/ip4.c line 685
0x402286e1: ethernet_input_LWIP2 at netif/ethernet.c line 182
0x4010453c: esp2glue_ethernet_input at glue-lwip/lwip-git.c line 433
0x40245c86: ethernet_input at glue-esp/lwip-esp.c line 357
0x40245c98: ethernet_input at glue-esp/lwip-esp.c line 365
That's the error I got, but updated my mqtt lib and it went away ...
@timpur yeah it’s really odd I can’t seem to get it to work. My mqtt lib is updated. For me I’m not sure that is the issue because if I remove the deepsleep function it works without issue
On Jun 15, 2018, at 4:04 AM, Tim P notifications@github.com wrote:
That's the error I got, but updated my mqtt lib and it went away ...
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
There are quite a lot of matches when you google for "Exception (28)" https://arduino-esp8266.readthedocs.io/en/latest/exception_causes.html
@satssehgal did you delete all previous version of your libs inside the library path? I sometimes had trouble when an old version was found alongside a new library. In PlatformIO I delete the entire lib folder every now and then and let it rebuild, when I get spurious errors.
@luebbe thanks for the suggestion. I just did that and still didnt work.
I had exception 28 - A load referenced a page mapped with an attribute that does not permit loads. Dont even know what means :)
I think it means that a pointer is pointing to nirvana an something is trying to read/write from that location.
@luebbe i'll have to research the error 28...i'm just baffled how some of you got it to work while mine is throwing off this error still. I just tried to compile it with a new D1 mini and same issue.
@satssehgal , can you give us a break down of your environment (Platform IO?, arduino core version? ...ect), board your use and flash size ... everything ?
Have you set the right flash size, the right flash mode ect?
@timpur
Here are the details:
Board : Wemo D1 mini Env: Arduino Core 2.41 Tool: Arduino IDE Flash size: 4M (1M SPIFFS) Debug Port: Disabled Debug Level: None IwIP Variant: v2 Lower Memory CPU Frequency: 80 MHz Upload Speed: 115200 Erase Flash: Only Sketch Port: Port on Comp Programmer: AVRISP mkill
Anything else?
Sent from my iPhone
On Jun 15, 2018, at 9:53 AM, Tim P notifications@github.com wrote:
@satssehgal , can you give us a break down of your environment (Platform IO?, arduino core version? ...ect), board your use and flash size ... everything ?
Have you set the right flash size, the right flash mode ect?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
@satssehgal , thanks. Ive clean my libs in arduino and started from scratch with latest libs of everything needed for homie. I now have your issue again so ill solve this once and for all :) might take me a bit though ....
@timpur No problem I appreciate your help. Thanks :)
On Jun 17, 2018, at 2:50 AM, Tim P notifications@github.com wrote:
@satssehgal , thanks. Ive clean my libs in arduino and started from scratch with latest libs of everything needed for homie and have, your issue again so ill solve this once and for all :) might take me a bit though ....
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
Anybody make any headway? So it looks like it breaks even if i comment out deepsleep. Soon as it breaks from the case statement it breaks no matter what is in the case statement
Thanks for sharing that, im going to look at it over the weekend, sorry bussy week ...
No problem. I’ve been racking my brain with this one for a while. Thanks for your help
any luck on this one? ive been tinkering all week and cant get this deep sleep to work
I also got this problem. I worked around it, by disabling all mqtt publishing and wait for a certain amount of time before issuing the command to go to deep sleep. Have a look at the source code: https://github.com/jmozmoz/yagds/blob/master/uploadSensorData/src/main.cpp
Actually I do not call Homie.loop() anymore during waiting to go to deep sleep.
I experimented a lot and this is my current solution which seems to work.
Thanks and how is battery life for you on this?
Sent from my iPhone
On Jul 2, 2018, at 8:23 PM, Joachim notifications@github.com wrote:
I also got this problem. I worked around it, by disabling all mqtt publishing and wait for a certain amount of time before issuing the command to go to deep sleep. Have a look at the source code: https://github.com/jmozmoz/yagds/blob/master/uploadSensorData/src/main.cpp
Actually I do not call Homie.loop() anymore during waiting to go to deep sleep.
I experimented a lot and this is my current solution which seems to work.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
I had the exact same issue last week... Oddly it was only when compiled with Arduino IDE. Debug stack pointed out that Async MQTT was the source of the problem, but I was on the last version of all libs. I found 2 different workarounds:
I am using PlatformIO and see this problem. Here my platformio.ini:
[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
build_flags = -DASYNC_TCP_SSL_ENABLED=1 -Wl,-Teagle.flash.1m64.ld
lib_deps =
https://github.com/marvinroger/homie-esp8266.git#v2.1
simpleTimer
jled
@gaelgrasset I tried both methods and neither seem to work. I’ve just been using an outlet over batteries out of sheer frustration
I have also been fighting with this problem. My solution was to revert to 0.8.1 of AsyncMqtt: https://github.com/marvinroger/async-mqtt-client/releases/tag/v0.8.1 (remember to build clean and rebuild everything)
I ran in the exact same problem. Reverting AsyncMqtt to 0.8.1 resolved the error for me.
FWIW I couldn't figure out how to revert to v0.8.1 using PlatformIO without vendoring Homie and manually patching its library.json
. I didn't love that idea, but thankfully it wasn't necessary.
Instead, I used @jmozmoz's strategy above--once I was able to get my head around it--and get consistent deep-sleep without exceptions on a D1 Mini Pro. The trick, as @jmozmoz mentions, is to essentially stop the Homie loop once Homie.prepareSleep()
has been called. But once you stop the loop, the READY_TO_SLEEP
event either won't emit or the handler won't be invoked (not sure which), so you need to manually invoke deep sleep via a timer (sleepTimeoutId
in @jmozmoz's code).
I'm not sure how short that sleep timeout can be, but if it's too short, I imagine Homie wouldn't be fully "ready" for sleep when Homie.deepSleep()
is called. I'm also unsure of the necessity of the subsequent ESP.deepSleep()
call.
I combined this with the wifi reset strategy mentioned here, because wifi was not reconnecting after wake from deep sleep. To mitigate, it looks like you just need to call WiFiOff()
, delay a short period, then call WiFiOn()
again at the start of your setup()
function.
Just for the first part on reverting to v0.8.1. The order of the libs matters in the platformio.ini. This is how mine looks like:
lib_deps =
AsyncMqttClient@0.8.1,!=0.8.2
ArduinoJson@5.13.4
https://github.com/homieiot/homie-esp8266.git#develop-v3
Timer
Hi Guys, I’m new here so please dont shoot my head off if I’ve accidentally broken a rule while posting. So i’m new to the homie framework, i’ve successfully compiled code for my door sensor alone but now i want to use additional sensors for my wemos d1 mini. There are obviously a bunch of smart folks on this site and I wanted to seek some assistance.
I compiled the code but its going into an iterative loop in the serial monitor. can someone please spot where i may have gone wrong? Much appreciated in advance
`
`
this is the error loop ` Offline message acknowledged. Di✔ Wi-Fi connected, IP: 192.168.1.151 Triggering WIFI_CONNECTED event... ↕ Attempting to connect to MQTT... Sending initial information... ✔ MQTT ready Triggering MQTT_READY event... MQTT connected, preparing for deep sleep... Flagged for sleep by sketch Calling setup function... Device in preparation to sleep... 〽 Sending statistics... • Wi-Fi signal quality: 100% • Uptime: 2s Door is now open Water sensor state is Leak Detected Offline message acknowledged. Disconnecting MQTT... ✖ MQTT disconnected Triggering MQTT_DISCONNECTED event... Triggering READY_TO_SLEEP event... Ready to sleep
Exception (28): epc1=0x4022c5c2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000004c depc=0x00000000
ctx: sys sp: 3ffffbd0 end: 3fffffb0 offset: 01a0
ets Jan 8 2013,rst cause:2, boot mode:(3,2)
load 0x4010f000, len 1384, room 16 tail 8 chksum 0x2d csum 0x2d v614f7c32 ~ld ^H⸮H⸮💡 Firmware my-sensors (1.0.0) 🔌 Booting into normal mode 🔌 {} Stored configuration • Hardware device ID: b4e62d1b5e99 • Device ID: basement-sensors • Name: Basement Sensors • Device Stats Interval: 60 sec • Wi-Fi: ◦ SSID: mynet ◦ Password not shown • MQTT: ◦ Host: 192.168.1.200 ◦ Port: 1883 ◦ Base topic: homie/ ◦ Auth? yes ◦ Username: not shown ◦ Password not shown • OTA: ◦ Enabled? yes ↕ Attempting to connect to Wi-Fi... ✔ Wi-Fi connected, IP: 192.168.1.151 Triggering WIFI_CONNECTED event... ↕ Attempting to connect to MQTT... Sending initial information... ✔ MQTT ready Triggering MQTT_READY event... MQTT connected, preparing for deep sleep... Flagged for sleep by sketch Calling setup function... Device in preparation to sleep... 〽 Sending statistics... • Wi-Fi signal quality: 100% • Uptime: 2s Door is now open Water sensor state is Leak Detected Offline message acknowledged. Disconnecting MQTT... ✖ MQTT disconnected Triggering MQTT_DISCONNECTED event... Triggering READY_TO_SLEEP event... Ready to sleep
Exception (28): epc1=0x4022c5c2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000004c depc=0x00000000
ctx: sys sp: 3ffffbd0 end: 3fffffb0 offset: 01a0