ESP8266 Wifi reliability

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
kevinkk525
Posts: 439
Joined: Sat Feb 03, 2018 7:02 pm

ESP8266 Wifi reliability

Post by kevinkk525 » Wed Aug 28, 2019 2:21 pm

I'm running multiple esp8266 nodes in my house, some have a very stable wifi (or just not much traffic) while most of them reconnect every few minutes. Even the node 3 meters away from the wifi router reconnects up to 10 times per day despite the RSSI of -50dB. The node further away with a RSSI of -80 dB reconnects almost every 2 minutes (ping interval 1.5 minutes).
This really got onto my nerves so I looked for a solution. I won't mention everything I tried but the solution that seems to work:

The wifi has different sleep modes and the default is SLEEP_MODEM. You can change the mode to SLEEP_NONE with:

Code: Select all

import esp
esp.sleep_type(esp.SLEEP_NONE)
This will increase the power consumption a bit but on a non-battery powered device I don't care. https://bbs.espressif.com/viewtopic.php ... modem#p485 I didn't measure it myself.
Since I changed this more than 24 hours ago, the node with RSSI -80dB has only reconnect twice and one time was a reconnect every other device also did so doesn't really count.
So the difference is really impressive: From reconnecting every ~2 minutes it now only reconnects 1-2 times a day!

This function was of course implemented a long time ago but I couldn't find any information on the forum about it so I thought I'd share this in case someone else has trouble with his wifi reliability too. (I only found this function after searching for the reconnect error, going through the arduino implementation of sleep_type and then looking for it in micropyhton source :oops: )

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

Re: ESP8266 Wifi reliability

Post by pythoncoder » Thu Aug 29, 2019 8:31 am

That is very useful information. Thank you :D

One to bear in mind if you're writing portable code is that it's ESP8266 specific: ESP32 does not have an equivalent function.
Peter Hinch

cristian.spiescu
Posts: 7
Joined: Wed Aug 28, 2019 5:07 am

Re: ESP8266 Wifi reliability

Post by cristian.spiescu » Sat Aug 31, 2019 8:18 pm

In your program do you put the board in sleep mode? Or maybe the setting you are mentioning affects the board for "normal" operation as well?

I recently implemented a project in my house and I log to a file the disconnect/connect events. They seem to be quite often. However I find strange that there are days with a few disconnects per day, but most often we are talking about several disconnects per hour.

kevinkk525
Posts: 439
Joined: Sat Feb 03, 2018 7:02 pm

Re: ESP8266 Wifi reliability

Post by kevinkk525 » Sun Sep 01, 2019 5:52 am

I don't put my board into sleep mode. The setting esp.sleep_type only affects the wifi part of the board and doesn't interfere with anything else. It's basically a power consumption feature of the wifi module.

I saw the same problems, there were days with only a few reconnects but these were very rare and usually multiple reconnects per hour.

Change that setting (e.g. in your boot.py as it is the easiest way without changing any project files) and your reconnects should drop significantly.

by the way: I wouldn't log these to flash, it'll destroy your flash at some point. In my project I log those reconnects over mqtt after the reconnect is done. But maybe you meant that by "log to a file".

cristian.spiescu
Posts: 7
Joined: Wed Aug 28, 2019 5:07 am

Re: ESP8266 Wifi reliability

Post by cristian.spiescu » Mon Sep 02, 2019 5:02 am

Thanks. I will try this asap.
by the way: I wouldn't log these to flash
Indeed. I was thinking that this is not a good practice. My log file contains about 50 lines per day. Once I stabilize the system, I will try an alternate solution to store the semi-verbose settings. 2 questions here: 1) is any periodic writing writing to a log file stored in flash not recommended? E.g. even 10 new lines of text per day? 2) are there ready made mqtt logging solutions? Or do I need to have an MQTT server app (a Raspberry probably) that receives MQTT messages and stores them in a file?

Best regards,
Cristian

kevinkk525
Posts: 439
Joined: Sat Feb 03, 2018 7:02 pm

Re: ESP8266 Wifi reliability

Post by kevinkk525 » Mon Sep 02, 2019 6:01 am

I wrote you a PM about the flash to keep this thread on-topic.

Post Reply