Issues installing emonESP firmware to Sonoff20 (Solved)


I have demandshaper installed.

Moved on to loading firmware onto the sonoff S20.

I saw there was a platform.ini so I tried to use platform. I followed the Huzzah instructions as there are none in the sonoff branch. Got the following error when I tried $ pio run.

#include <NTPClient.h>
compilation terminated.
*** [.pioenvs/emonesp/src/src.ino.cpp.o] Error 1
src/ota.cpp: In function ‘t_httpUpdate_return ota_http_update()’:
src/ota.cpp:75:120: warning: ‘t_httpUpdate_return ESP8266HTTPUpdate::update(cons t String&, const String&)’ is deprecated (declared at /home/pi/.platformio/packa ges/framework-arduinoespressif8266/libraries/ESP8266httpUpdate/src/ESP8266httpUp date.h:87) [-Wdeprecated-declarations]
t_httpUpdate_return ret = ESPhttpUpdate.update(“http://” + String(u_host) + Stri ng(u_url) + “?tag=” + currentfirmware);
Do I need to switch to the Arduino IDE to get around this?

Hi @TrystanLea

I have now tried Arduino ide to compile the S20 firmware.

I first received an error: NTPClient.h: No such file or directory

I found the file on github and installed it but then got further errors.error.txt (2.3 KB)

Can you advise next best step? Have I got the wrong library files?

Hello @ian

The ESPAsyncTCP library can be installed from the Arduino Libraries Manager

Sketch > Include Library > Manage Libraries

You can install the NTPClient using the same process

You will also need PubSubClient via the same approach:

When compiling for most of the newer SonOff S20 plugs I find I need to use Generic ESP8285 Module not the ESP8266

Hi @TrystanLea

Still struggling with this. I had all the ESPAsync libraries installed but they dated back to 2017. So I deleted them and installed the latest. At last the firmware compiled, but now it is too big! Could I still have an old library that creates larger code size? I am using Arduino 1.8.7 on Windows 10. Is there a different version I should use?

Edit. Just tried Arduino 1.8.8, still same problem.

libraries.txt (6.7 KB)

Did you note my earlier post that shows platform.IO does not compile either? (My preferred ESP platform as I seem to always have Library issues using Arduino)

Arduino: 1.8.7 (Windows 10), Board: "Generic ESP8285 Module, 80 MHz, Flash, Disabled, ck, 26 MHz, 1M (512K SPIFFS), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"

Sketch uses 512840 bytes (102%) of program storage space. Maximum is 499696 bytes.
Global variables use 36368 bytes (44%) of dynamic memory, leaving 45552 bytes for local variables. Maximum is 81920 bytes.
Sketch too big; see for tips on reducing it.
Error compiling for board Generic ESP8285 Module.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences. 

Also I am following the instructions here:-> (6.7 KB)md

There are a few minor errors if following verbatim. Do you want details for corrections?

Hello @ian, did you select the flash size to be 1M (512k SPIFFS). It would be great to get this working with platformio, it probably only needs a few minor changes. Perhaps @glyn.hudson can help


Yes I did, it shows in the compile listing in previous post.

O dear, not sure what the issue is.

Turns out adding NTPClient to the platformio ini file was fairly straightforward, I’ve made the change here:

It can be compiled for the esp8285 with the env set to sonoff_s20b:

 sudo pio run -e sonoff_s20b

Let me know if that uploads ok

Hi @TrystanLea

Some progress. After a couple of false starts and switching from Windows to Linux on a Pi I was able to use compile and upload. I followed the instructions for uploading from EmonESP on the Huzzah.
I had to use Sudo to upload. Next issue is that I see no AP access point on my phone. I am still connected and powered from the FTDI cable and the serial port connects OK. Where do you enable debug so that you can see debug print on the serial port? It may give a clue to whats happening.

To check I was using platform.IO correctly I tried installing EmonESP huzzah version on a new ESP8266 and on that I see data on the serial port.


Can I hard code my SSID and password in the correct file to force the wifi connection and bypass AP mode?

I’ve had this happen in the past caused by EEPROM or flash data from the previous firmware tripping up the new firmware. There’s a tool that does a complete errase that’s worth running first and then re-uploading the firmware as before, see:

Noting your comment on the NanodeRF thread. Maybe its worth getting to the bottom of the sketch size issue?

Here are my arduino IDE and library versions:

  • Arduino 1.8.5
  • NTPClient 3.1.0
  • ESP Async TCP 1.1.0
  • ESP Async Web Server 1.1.0
  • ESP8266 1.0.0
  • ESP8266HTTPClient 1.1.0
  • ESP8266Wifi 1.0.0
  • PubSubClient 2.6.0

Downloading Arduino 1.8.8 and compiling without updating any libraries I get:

Sketch uses 432252 bytes (86%) of program storage space. Maximum is 499696 bytes.
Global variables use 41888 bytes (51%) of dynamic memory, leaving 40032 bytes for local variables. Maximum is 81920 bytes.

Compiling on Arduino 1.8.5:

Sketch uses 432252 bytes (86%) of program storage space. Maximum is 499696 bytes.
Global variables use 41872 bytes (51%) of dynamic memory, leaving 40048 bytes for local variables. Maximum is 81920 bytes.

Global variables use is 0.04% higher with 1.8.8 but that should not be an use given 49% availability left.

These compiled values are very different from your:

Sketch uses 512840 bytes (102%) of program storage space. Maximum is 499696 bytes.
Global variables use 36368 bytes (44%) of dynamic memory, leaving 45552 bytes for local variables. Maximum is 81920 bytes.

Could this be a Linux versus Windows issue?

I am using Arduino on Windows 10. One immediate difference I see is the libraries manager.

I cannot see all the libraries I am using in the Libraries Manager so it is not easy to match the libraries you are using. Also you mention ESP8266 1.0.0 which does not appear on the list I get if I turn on verbose compile

Usinglibrary Hash at version 1.0 
Using library ESPAsyncTCP-master at version 1.2.0 
Using library ESPAsyncWebServer-master at version 1.2.0 
Using library ESP8266WiFi at version 1.0 
Using library ESP8266httpUpdate at version 1.3
Using library ESP8266HTTPClient at version 1.2 
Using library NTPClient at version 3.1.0 
Using library EEPROM at version 1.0 
Using library PubSubClient at version 2.7
Using library ArduinoOTA at version 1.0 
Using library ESP8266mDNS at version 1.2 
Using library DNSServer at version 1.1.1 

I am out today but maybe I should set up a Linux Arduino. It would have to be on a Pi3 if that is capable of running Arduino.

In response to your other post:-

I did the erase and uploaded again using platform.IO but still no AP. Should I see output on the serial port which would confirm the firmware uploaded OK?

Yes it should print something to the effect of starting access point & server started. I dont have one with me right here to get the printout, but it does detail what it is doing.

Hi Trystan.

I am totally baffled. I installed a new version of Arduino on another windows PC with its own separate library folder. I installed latest ESP boards file.

I installed only the libraries required, all new downloads from github.

Still compiled to large for upload.

I then did the same thing on a Pi 3 just in case something was different in the Linux Arduino distribution. Exactly the same result.

I must be doing something different from you but I cannot think what it is.


Should this thread be split to something about EmonESP sonoff20?

Thanks Ian thats interesting, I will have to try a fresh install. Did you get anything from the serial printout?

Hi Trystan

Just to make sure I had made no errors I did the following.
Erase S20
Successfully completed.

Delete EmonESP folder and start again with a new git clone.
sudo pio run -e sonoff_s20b
sudo pio run -t upload
sudo pio run -t uploadfs

All completed successfully.
Disconnected S20 and reconnected.
Monitored serial port. Nothing showing.
No AP showing on phone.
The only thing left for me to try is a different S20.

I notice the pio upload command always recompiles.
Is there a way to just upload the 2 binary files? If so I am thinking you could possibly provide files that you have compiled that are known to work. This might enable me to move forward and see it the demand shaper will do what I want to do. I had started to work on a node red solution but it makes sense to use emoncms if I can as that is where I monitor consumption and solar generation.

Thinking about it, maybe you have the sonoff s20 with the esp8266 board rather than the esp8285 that I seem to have. Earlier versions were esp8266, or perhaps they are different batches…

could you try

 sudo pio run -e sonoff_s20

The symptoms that you are seeing is what I experienced from flashing the firmware compiled for the wrong board

Hi Trystan

You are correct if esptool reporting is to be believed. Carrying out the erase command I noticed this morning it reports the chip type as 8266.

So I tried:

sudo pio run -e sonoff_s20

Sadly the result is still no AP and nothing showing on serial.

So I tried the complete process on a second S20. Exactly the same result. I then thought the best thing to do is see if the sonoff is faulty so I tried uploading Tasmota firmware. This uploaded without any problems, I set up mqtt and am able to control the sonoff.

I don’t know what to do next. Can you sell flashed S20 sockets from the shop? I would really like to try this out.

O dear, that’s a shame. I will double check that the firmware works when compiled with platformIO tomorrow. Then upload pre-compiled binaries for you to test.

Yes, we are planning on stocking these in the shop soon :slight_smile:

Hi @TrystanLea

Some progress. I remembered when I first used EmomESP on the huzzah I had trouble installing the firmware. To learn more about the process I used a Wemos D1 mini ESP.
I just tried uploading the sonoff firmware onto a Wemos and it worked first time. I saw the AP, entered my SSiD and password and SMARTPLUG1 shows up on my router! I have followed all the installation steps and I am now at this stage:-

2. Connect back to your home WIFI network. Login to emoncms and navigate to inputs. Refresh the page until a popup appears asking to connect:

So far no popup has appeared. I do see 2 new nodes . Smartplug1 & hpmon5 which must indicate something. I also see the demandshaper module on the taskbar but clicking shows:-

No devices found

Log shows

2019-02-28 12:38:29.477|WARN|device_model.php|Device model: Requested device does not exist for id=0

What do I need to do to see whats amiss?
Server Info

ServerInfo.txt (3.4 KB)