Is loading an Arduino sketch on an ESP8266 module erasing existing firmware?

I am stumped by what is happening.... I hooked up a newly received ESP-07S module and checked that its AT-interface is working. I also saw that there is an AP running by the name "AI-THINKER_0382F3", I guess it is the out-of-factory firmware.

Then I added an AD2302 temp/humidity sensor to the breadboard and used the Arduino examples sketch DHTtester to check if the sensor is OK. Worked fine as far as I can tell. But to my surprise the AP from the new module is still there!!!

So therefore questions:

  • Why is not the factory firmware fully removed when I upload a new sketch from Arduino IDE?
  • What kind of AP is this in the first place? Is it a built-in OTA, which is located elsewhere than the standard sketch?

the WiFi handling is in the Espressif SDK libraries. they are a part of your esp sketch build and upload and they start the AP or connect to WiFi network with settings remembered on the flash

But when I tested earlier using an ESP-07 (no S) with a built-on ceramic antenna this did not happen. My programmed AP appears only if I initialize it properly in the sketch setup() function etc. But this test sketch programmed from the Arduino IDE as a check that the sensor worked performs differently by starting up an AP even though there is no trace of that inside the setup() or loop() functions.

Maybe if I repeat the exercise on Sloeber it will be different? I will ditch the Arduino IDE and move this too to Sloeber since thta is the IDE I prefer. In the feedback during flashing in the Arduino IDE I noted output that indicates that the ESP flash size has not been correctly set even though I tried to tell it to use the 4Mbytes flash size (which I believe is correct for the ESP-07S module). This is what is displayed after the linker is done:

Linking everything together...
...
Using library DHT at version 1.3.0 in folder: C:\Programs\Arduino\arduino-1.8.2\libraries\DHT 
Using library Adafruit_Unified_Sensor at version 1.0.2 in folder: C:\Users\Bosse\Documents\Arduino\libraries\Adafruit_Unified_Sensor 
Sketch uses 254091 bytes (24%) of program storage space. Maximum is 1044464 bytes.
Global variables use 33140 bytes (40%) of dynamic memory, leaving 48780 bytes for local variables. Maximum is 81920 bytes.
C:\Users\Bosse\AppData\Local\Arduino15\packages\esp8266\tools\esptool\0.4.12/esptool.exe -vv -cd ck -cb 115200 -cp COM29 -ca 0x00000 -cf C:\Users\Bosse\AppData\Local\Temp\arduino_build_371857/DHTtester.ino.bin

Maximum should be 4Mbytes for a 32 Mbit flash chip, right? But it says 1 Mbytes..

that is a sketch max size. next 1 MB is for OTA upload, next for SPIFFS, for WiFi data, EEPROM emulation, esp settings

use esptool.py. it will report the size of the flash.

esp8266 arduino 2.4.1 has the Erase setting.

OK, I did not know that the sketch itself has a maximum size of 1 Mb irrespective of flash size…

I have tried to use esptool, and it is installed on my Windows 7 computer but it does not work.
Cannot be started.
On the command prompt:

D:\Engineering\Projects\Subversion\EI\Readme>where esptool.py
C:\Programs\Python\Scripts\esptool.py.exe   <== so it is on path!

D:\Engineering\Projects\Subversion\EI\Readme>esptool.py
Traceback (most recent call last):
  File "C:\Programs\Python\Scripts\esptool.py-script.py", line 5, in <module>
    from pkg_resources import load_entry_point
  File "C:\Programs\Python\lib\site-packages\pkg_resources.py", line 2671, in <module>
    working_set.require(__requires__)
  File "C:\Programs\Python\lib\site-packages\pkg_resources.py", line 654, in require
    needed = self.resolve(parse_requirements(requirements))
  File "C:\Programs\Python\lib\site-packages\pkg_resources.py", line 552, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: ecdsa

D:\Engineering\Projects\Subversion\EI\Readme>python --version
Python 2.7.1

I think that it is working only on Linux…
And I have never programmed Python myself.

What do you mean by: “esp8266 arduino 2.4.1 has the Erase setting.”
I am using the esp8266 api 2.4.1 (at least in Sloeber).

I had more problems to install esptool.py on Linux then on Windows

the "Erase Flash" setting in Arduino project settings in Eclipse and in Tools menu in Arduino IDE

I have now returned to the Sloeber IDE and my main project where I am going to switch from ESP-07 to ESP-07S. The main difference is the flash size, so I need to choose one from the list. I find the following two 4M items:

  • 4M (1M SPIFFS)
  • 4M (3M SPIFFS)

And the existing setting is 1M (64K SPIFFS)

I want the existing sketch loaded into the new ESP module with OTA enabled (WebUpdater) and EEPROM the same size as before.

Which type should I select (maybe 4M (1M SPIFFS))?

And concerning Erase Flash I found these options:

  • All Flash Contents
  • Only Sketch
  • Sketch + WiFi Settings

If I select All Flash Contents, will the EEPROM area also be affected?

If that is the case, maybe I should do a first flash load using All Flash Contents and then switch to Only Sketch? The WiFi is always set up in my setup() function so I don't know what that option will do. Do these settings apply also if the sketch is later rebuilt but programmed using the WebUpdater OTA system instead of the built-in programmer? OTA should not be able to erase itself, right?

[u]OOPS![/u] Before sending this I tested to change the properties of the project to use the 4M(1MSPIFFS) setting, but when I hit the Close+Apply button I got an error message saying that the Release directory is not possible to write to. And this is correct! I have no idea how this has happened because that directory is entirely handled by Sloeber... Now even though I have closed Sloeber I cannot enter or change owner or even display the security settings for the Release directory... Any advice on how to proceed to be able to build the sketch?

[u]I think I know the reason for the failure to write to or erase the Release folder:[/u] What has happened is that I had a FireFox window open with the WebUpdater webpage on the ESP-07 after I had last updated the firmware. During the update I had navigated with the browser to the Release/sketchname.bin file and commanded an upload. After this I just left the FireFox window as is and forgot all about it. When the problem now happened I started to close down various open windows and then I checked the sketch dir and suddenly the Release dir disappeared. I think it was when I closed the last FireFox window, but it could also have been when I closed the firmware update page. In any case I did not have to reboot Windows, which was in my plans until the dir disappeared.

And I can verify that the EEPROM contents survives re-flashing the same firmware as was loaded with the "Erase All Flash Content". So the flash erase seems to be a function of the flsah loader itself in Sloeber rather than in the flash bin file.

BosseB: Which type should I select (maybe 4M (1M SPIFFS))?

you do not use SPIFFS file system, so 1 MB not used is better then 3 MB not used :-)

BosseB: Do these settings apply also if the sketch is later rebuilt but programmed using the WebUpdater OTA system instead of the built-in programmer? OTA should not be able to erase itself, right?

the erasing of the flash is extra operation before upload over USB. it doesn't apply for OTA

BosseB: If that is the case, maybe I should do a first flash load using All Flash Contents and then switch to Only Sketch?

I recommend the All Flash erase after some major change like changing lwip version, updating the core package, using some firmware

BosseB: The WiFi is always set up in my setup() function so I don't know what that option will do.

your temperature sensor sketch started AP, because the settings where there :-)