Unstable after some days

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Roanyg
Posts: 7
Joined: Fri Apr 28, 2017 8:36 am

Unstable after some days

Post by Roanyg » Fri Apr 28, 2017 8:56 am

My MCU are getting unstable after some days.

I have 3 different ESP8266: ESP-01, ESP-12 and ESP-12E

I have programmed all of them to post temperature and humidity by using MQTT to adafruit.io. After 2-3 days, my MCUs stops sending info and I have to reset my MCUs by using WebREPL and import machine and machine.reset(). Then, everything works well for some days.

What I have done so far to eliminate the problem:

I have used two different power sources.
I have tried both simple.mqtt and robust.mqtt
I have tried deep sleep
I have tried three different ESPs
I have tried two DHT22s

Is this a typical problem with Micropython on ESP8266?
What can I do to make my MCUs stable?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Unstable after some days

Post by pythoncoder » Sat Apr 29, 2017 5:49 am

Does it produce an error message when it fails? Have you investigated the watchdog timer? http://docs.micropython.org/en/latest/e ... e.WDT.html
Peter Hinch
Index to my micropython libraries.

thetreerat
Posts: 15
Joined: Thu Apr 27, 2017 6:40 pm

Re: Unstable after some days

Post by thetreerat » Sat Apr 29, 2017 1:16 pm

I don't think Watch dog Timer works on the esp8266, the docs say that it not supported on this platform. The class is in the V1.8.7.673 build for ESP2866 and you can import it and list the Methods.

I tried it on my adafruit board and the loop ran for 6200 seconds and did not reboot. with not call the feed method so it should have rebooted. I tried this with the v1.8.7-673 build.
### test Code ####
from machine import WDT
>>> w = WDT()
>>> w.
feed deinit
>>> from utime import sleep
>>> def loop(count):
... while True:
... print('''here stil:%s''' % (count))
... count += 1
... sleep(1)
...
>>> loop(1)
here stil:1
here stil:2
##### Test Code ###


I bet if you could connected to serial repl, with your code running you get the error. It would take 2 to 3 days to get it. You can't get the error message if you connect after a crash, at least I don't if reboot and connect with the web repl with a bad main.py.

The other solution to till you find the bug and correct would be to reboot the controller once a day. I know sounds like a windows fix.

I hope that might help.

Hal

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Unstable after some days

Post by pythoncoder » Sun Apr 30, 2017 6:17 am

It seems the situation with the WDT is somewhat involved. The following may be informative https://github.com/micropython/micropython/issues/2154.

tl;dr It seems you're right and it doesn't (yet) work as you might expect.
Peter Hinch
Index to my micropython libraries.

Roanyg
Posts: 7
Joined: Fri Apr 28, 2017 8:36 am

Re: Unstable after some days

Post by Roanyg » Mon May 01, 2017 6:24 pm

Thank you. I am honoured to get help so fast from you!

I have run two of my ESP8266 conncted to my computers COM port for 30-40 hours, and suddenly my ESP01s failed. YES!

I got this message:

Traceback (most recent call last):
File "main.py", line 7, in <module>
File "dhtdemo9.py", line 27, in <module>
File "umqtt/simple.py", line 110, in publish
OSError: [Errno 104] ECONNRESET

MicroPython v1.8.7-7-gb5a1a20a3 on 2017-01-09; ESP module with ESP8266
Type "help()" for more information.
>>>

Line 27 in my dhtdemo9.py is:
c.publish("RoarN/feeds/u-temp", str(sensor.temperature()))

What I have found out so far, the error message, 104, means network failure / wifi connection issues.
Peterhinch has described a better code to trap and handle the OSError here https://github.com/micropython/micropython/issues/2055

Do you have any other suggestions to handle wifi errors?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Unstable after some days

Post by pythoncoder » Tue May 02, 2017 5:38 am

There is a tidier version of that code here viewtopic.php?f=16&t=2163.

I spent much time on umqtt last summer, with simple and robust versions, in an attempt to achieve 24/7 running. I failed. It remained vulnerable to WiFi disruptions despite my best efforts at trapping errors and adapting the libraries. I eventually put my fail down to a lack of network programming experience and moved on to other things in the hope that someone better equipped would achieve results.

You might like to read the issue I raised on the subject and the maintainer's response. https://github.com/micropython/micropyt ... issues/103
Peter Hinch
Index to my micropython libraries.

Roanyg
Posts: 7
Joined: Fri Apr 28, 2017 8:36 am

Re: Unstable after some days

Post by Roanyg » Thu May 04, 2017 3:07 pm

I haven't programmed for years, so I really appreciate your support.

What my goal is?
1. I have a dream to learn some programming again.
2. I will have some devices (esp8266) in my house to controll from a web site. IoT
3. From a web site I want to:
- Remote controll garage port
- Have status on doors (open / locked)
- Monitor temperature and humidity
- etc

What I have done so far:
1. I have learned some Python (codecademy.com) and Micropython (micropython.org) and written some hundred lines on my WebREPL and Notepad++. I enjoy programming a lot more than my wife. It really has a low WAF, see: https://en.wikipedia.org/wiki/Wife_acceptance_factor

2. I have made a couple of ESP8266 with temperature and humiditysensors posting data to adafruit.io with MQTT. I am working to make a ESP8266 subscribe to MQTT now. Turning a led on and off... What really made me dissapointed was that my ESPs became unstable and stopped posing data to adafruit.io. It seems like I have to make better scripts and deal with network interrupts. That wasn't in my mind when I began learing Micropython and controlling my ESPs.

3. What is my next step?

Should I use PyBoard (WDT compatible) in stead of ESP?
Should I make my sensors post data to adafruit.io / a website whith HTTP REST API in stead of MQTT? Is that more stable and solid if network errors occurs?
Shoud I give up Micropython and learn C, Lua or JavaScript instead? Will my ESPs be more stable, or do I still have to deal with WiFi disruptions?

Since I enjoy writing Micropython so much, I have to develope my skills and make some useful IoT services with higher WAF. :roll:

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Unstable after some days

Post by pythoncoder » Fri May 05, 2017 7:41 am

The question is whether the poor long term stability of the ESP8266 is a function of the MicroPython port or of the underlying RTOS/WiFi stack of the device. I don't know the answer to that one.

By contrast the Pyboard is rock-solid. It would be interesting to try one with a CC3100 WiFi adaptor; the chip is officially supported.

I think that even with a stable WiFi adaptor there will still be rare circumstances in which RF disruption will cause UMQTT to fail, and this may well apply to other protocols. Implementing communications protocols over inevitably imperfect wireless links is difficult - it's hard to anticipate all possible failure modes. So a WDT is probably essential. The Pyboard has one which, though unsupported in the firmware, can be used https://github.com/peterhinch/micropyth ... r/watchdog.

I think a hardware WDT is the solution to the ESP8266 ills. It could easily be done...
Peter Hinch
Index to my micropython libraries.

slzatz
Posts: 92
Joined: Mon Feb 09, 2015 1:09 am

Re: Unstable after some days

Post by slzatz » Fri May 05, 2017 11:25 am

I have several Adafruit Feather HUZZAH ESP8266 boards with either BME280 or BMP180 sensors and they've run for weeks without any issue. It has taken some testing to figure out how long an interval I can go without publishing an MQTT message -- if I exceed that interval I can't publish another message and I haven't figured out any way to recover other than to reboot the board. So in some cases I just set the timer interrupt for a shorter interval than I need for the readings I am taking and just send a dummy message to keep the problem from happening. The interval length seems to depend on the WiFi network I am connecting to -- in some cases 5 minutes between readings is fine and in other cases if I don't send some MQTT message every 2 minutes at some point it becomes impossible to send messages. So not a perfect world and I don't know what causes the problem but for me there has been a solution that keeps the ESP8266s running for weeks measuring temperature/humidity and publishing the data via MQTT.

Post Reply