1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

Squashed commit of the following:

commit 810ab68ae5
Author: Ivan Grokhotkov <igrokhotkov@gmail.com>
Date:   Mon Nov 9 01:37:22 2015 +0300

    Fix WiFiClientSecure::connected (#43)

    thanks @whyameye

commit 7384c3814b
Merge: 46468d4 464d891
Author: Markus <Links2004@users.noreply.github.com>
Date:   Sun Nov 8 23:04:52 2015 +0100

    Merge pull request #985 from Links2004/docu

    add missing exit in php sample

commit 464d891877
Author: Markus Sattler <help.markus+git@gmail.com>
Date:   Sun Nov 8 22:48:48 2015 +0100

    add missing exit in php sample

commit 46468d4af7
Author: Ivan Grokhotkov <igrokhotkov@gmail.com>
Date:   Mon Nov 9 00:18:08 2015 +0300

    I2C: generate STOP in case of NACK (fix #698, #254)

    thanks @petrd and @Yazzcat

commit 4cf72e7ef4
Author: Ivan Grokhotkov <igrokhotkov@gmail.com>
Date:   Sun Nov 8 23:44:25 2015 +0300

    Add libc time functions

    Merging https://github.com/igrr/axtls-8266/pull/1 by @Juppit into the core

commit 11340a5d76
Author: Ivan Grokhotkov <igrokhotkov@gmail.com>
Date:   Sun Nov 8 15:01:17 2015 +0300

    Fix some typos
This commit is contained in:
wemos
2015-11-09 13:09:30 +08:00
parent 3243b4ba0e
commit d1a0c53805
7 changed files with 211 additions and 59 deletions

View File

@ -7,47 +7,45 @@ title: OTA Update
* [Arduino IDE](#arduino-ide)
* [HTTP Server](#http-server)
* [Stream Interface](#stream-interface)
## Basic Requirements
- Flash chip size is 2x the size of the sketch
- Flash chip size is 2x the size of the sketch.
## Arduino IDE
TODO describe Arduino IDE OTA process
#### Requirements
- The ESP and the Computer must be connected to the Same network.
- The ESP and the computer must be connected to the same network.
## HTTP Server
the ```ESPhttpUpdate``` class can check for updates and download a binary file form a HTTP web server.
It is possible to download updates from every IP or domain address on the Network or Internet.
```ESPhttpUpdate``` class can check for updates and download a binary file from HTTP web server.
It is possible to download updates from every IP or domain address on the network or Internet.
#### Requirements
- web server
#### Arduino code
##### simple updater
##### Simple updater
the Simple Updater downloads the File every time the function is called.
Simple updater downloads the file every time the function is called.
```cpp
ESPhttpUpdate.update("192.168.0.2", 80, "/arduino.bin");
```
##### advanced updater
##### Advanced updater
Its possible to point to a script at the server.
If a version String is delivered to the Function this String will be send to the server.
A Server side Update check is now possible.
Its possible to point update function to a script at the server.
If version string argument is given, it will be sent to the server.
Server side script can use this to check if update should be performed.
the Server can return a binary file for update (Header 200)
or it return header 304 to notify the ESP that no Update is needed.
Server side script can respond as follows:
- response code 200, and send the firmware image,
- or response code 304 to notify ESP that no update is required.
```cpp
t_httpUpdate_return ret = ESPhttpUpdate.update("192.168.0.2", 80, "/esp/update/arduino.php", "optional current version string here");
@ -59,23 +57,23 @@ switch(ret) {
Serial.println("[update] Update no Update.");
break;
case HTTP_UPDATE_OK:
Serial.println("[update] Update ok."); // may not called we reboot the ESP
Serial.println("[update] Update ok."); // may not called we reboot the ESP
break;
}
```
#### Server request handling
##### simple updater
##### Simple updater
for the simple Updater the Server only needs to deliver the binary file for update.
For the simple updater the server only needs to deliver the binary file for update.
##### advanced updater
##### Advanced updater
for advanced update management a Script needs to run at the Server side, for example a PHP script.
at every Update request the the ESP sends some informations in the Header to the Server
For advanced update management a script needs to run at the server side, for example a PHP script.
At every update request the the ESP sends some information in HTTP headers to the server.
example Header data:
Example header data:
```
[HTTP_USER_AGENT] => ESP8266-http-Update
[HTTP_X_ESP8266_STA_MAC] => 18:FE:AA:AA:AA:AA
@ -87,10 +85,9 @@ example Header data:
[HTTP_X_ESP8266_VERSION] => DOOR-7-g14f53a19
```
with this information the script now can check if a update is needed.
It is also possible to deliver different binary<72>s based on the MAC address for example.
With this information the script now can check if a update is needed. It is also possible to deliver different binaries based on the MAC address for example.
script example:
Script example:
```php
<?PHP
@ -118,10 +115,10 @@ if(!check_header('HTTP_USER_AGENT', 'ESP8266-http-Update')) {
header($_SERVER["SERVER_PROTOCOL"].' 403 Forbidden', true, 403);
echo "only for ESP8266 updater!\n";
exit();
}
}
if(
!check_header('HTTP_X_ESP8266_STA_MAC') ||
!check_header('HTTP_X_ESP8266_STA_MAC') ||
!check_header('HTTP_X_ESP8266_AP_MAC') ||
!check_header('HTTP_X_ESP8266_FREE_SPACE') ||
!check_header('HTTP_X_ESP8266_SKETCH_SIZE') ||
@ -145,6 +142,7 @@ if(isset($db[$_SERVER['HTTP_X_ESP8266_STA_MAC']])) {
} else {
header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified', true, 304);
}
exit();
}
header($_SERVER["SERVER_PROTOCOL"].' 500 no version for ESP MAC', true, 500);
@ -152,11 +150,6 @@ header($_SERVER["SERVER_PROTOCOL"].' 500 no version for ESP MAC', true, 500);
```
## Stream Interface
## Updater class
TODO describe Stream Interface update proccess
```cpp
ESP.updateSketch(client, length);
```
TODO describe Updater class