So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By lapgoch
#75459 Hi.

I am trying to update a sketch on a Sonoff Basic using Esp Http Update.
My sketch binaries are on a RPI web server.
The problem is that it looks like the sketch size is too big for the update , but I can't see why.
The Sonoff Basic is a 1MB and the sketch size is 321Kb.
I am using Spiffs which is set to 64Kb in the Arduino 1.8.5 IDE.
Here is a snippet from the com port output when the update fails.

Update Check
IDE size = 1048576
Flash size = 1048576
Sketch size = 321536
Space size = 638976
Sketch url = http://192.168.0.22/php/updateCheck.php
Update status = 0
HTTP_UPDATE_FAILED Error (-107): New Binary Does Not Fit Flash Size
[34647] Connecting to 192.168.0.22:8080
[34665] Ready (ping: 11ms).
[35218] Time sync: OK

Strangely when I load a smaller sketch 315Kb to the Sonoff and do an update , all works ok.
Here is a snippet from the com port output when the update works.

Update check
IDE size = 1048576
Flash size = 1048576
Sketch size = 315328
Space size = 647168
Sketch url = http://192.168.0.22/php/updateCheck.php

ets Jan 8 2013,rst cause:1, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
@cp:0
ld

/alexaSetup.txt file open failed
/vpinSetup.txt configuration read
/networkSetup.txt configuration read
SSID match found
Configuring network settings for COLIN_Next
IP address = 192.168.0.200
Gateway = 192.168.0.1
Server = 192.168.0.22
Auth token = xxxxxxxxxxxxxx
Bridge 1 token = xxxxxxxxxxxxxx
Bridge 2 token = 0
Bridge 3 token = 0
Device vPin = 0
Bins = 31 32 33 34 0 0 0 0
Bridge 2 virtual pins = 0 0 0 0 0 0 0 0
Bridge 3 virtual pins = 0 0 0 0 0 0 0 0
Device name / port = /
All name / port = /
Scene 1 name / port = /
Scene 2 name / port = /
[8334]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.5.1 on Arduino

[8348] Connecting to 192.168.0.22:8080
[13349] Connecting to 192.168.0.22:8080
[18588] Connecting to 192.168.0.22:8080
[18610] Ready (ping: 13ms).
[18885] Time sync: OK
Sketch version = SWITCH-102
Minutes remaining to sketch update check = 1424
IDE size = 1048576
Flash size = 1048576
Sketch size = 315440
Space size = 643072

Does anyone know why a sketch size 321Kb with free space 639Kb fails.
But a sketch size 315Kb with free space 647Kb works.

Attached are the working / failed com port output files and a screenshot of the RPI file sizes.
You do not have the required permissions to view the files attached to this post.
User avatar
By btidey
#75483 When using OTA the firmware is transferred first while the original firmware is still running. So there has to be twice the size of the sketch total space available.

What I am not sure about is why you have 640K space out of 1MB. Maybe using SPIFFS has a minimum usage.
User avatar
By lapgoch
#75490 Hi.

The original sketch uses 321k and I am using 64k for spiffs , so I thought that would be roughly right for 640k of free space. So why won't a 321k sketch load over OTA into 640k fo free space ?
User avatar
By lapgoch
#75533 Hi.

Some more info on my issue which hopefully someone knows what is going on.

When I call the following code from the sketch I get a magic size of 524288
Serial.println(ESP.magicFlashChipSize((buf[3] & 0xf0) >> 4));

When the same code is called from the esp8266HttpUpdate library I get a magic size of 4194304
8 times the value that it got from the sketch call.

Update Check
IDE size = 1048576
Flash size = 1048576
Sketch size = 321600
Space size = 638976
Sketch Magic size = 524288
Sketch url = http://192.168.0.22/php/updateCheck.php
Library Magic size = 4194304
Update status = 0
HTTP_UPDATE_FAILED Error (-107): New Binary Does Not Fit Flash Size

Does anyone know what the ESP.magicFlashChipSize((buf[3] & 0xf0) >> 4) code does?
Also any idea why it is returning different values?