ESP8266 Wifi disconnects due to analogRead()

I’m trying to use an ESP8266 / NodeMCU with emonlib and MQTT (pubsubclient). The problem I’m having is that the wifi disconnects every 11 seconds or so, which in turn causes the mqtt client to disconnect.

I stripped all the code down and have discovered that analogRead is causing the wifi client to disconnect, which in turn causes MQTT to disconnect. The only way I can make it not disconnect is by introducing a delay into the main loop, which of course is going to mess up the measurements.

I know that people are using ESP8266s for energy monitoring, but I can’t figure out how to program around this problem.

The ESP8266 has a single processor. It’s not possible to do many ADC reads and keep the network active. You will need to use an external ADC. This is what the IoTaWatt uses. Possibly the ESP32 could be better since it’s dual core I believe three core.

Thanks Glyn. I thought I could get away with a simple/cheap multiplexer + ESP8266, but I guess I was sorely mistaken!

You may also need to call the yield() function if you are programming using the Arduino libraries for the ESP8266 unit, when you call delay() it does this for you.

Thats the odd thing. I expected that yield() should work for this, but it definitely doesn’t.