Skip to content

Commit aefdf82

Browse files
committed
add HTTP Updater docu
1 parent c1c2eba commit aefdf82

File tree

1 file changed

+104
-10
lines changed

1 file changed

+104
-10
lines changed

doc/ota_updates.md

+104-10
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ title: OTA Update
33
---
44

55
## Table of Contents
6-
* [Requirements](#Requirements)
6+
* [Basic Requirements](#basic-requirements)
77
* [Arduino IDE](#arduino-ide)
88
* [HTTP Server](#http-server)
99
* [Stream Interface](#stream-interface)
1010

11-
## Requirements
11+
## Basic Requirements
1212

13-
Basic requirement:
1413
- Flash chip size is 2x the size of the sketch
1514

1615
## Arduino IDE
1716

1817
TODO describe Arduino IDE OTA process
1918

20-
### Requirements
19+
#### Requirements
2120
- The ESP and the Computer must be connected to the Same network.
2221

2322

@@ -27,18 +26,29 @@ the ```ESPhttpUpdate``` class can check for updates and download a binary file f
2726
It is possible to download updates from every IP or domain address on the Network or Internet.
2827

2928

30-
### Requirements
29+
#### Requirements
3130
- web server
3231

3332

34-
### Arduino code
33+
#### Arduino code
34+
35+
##### simple updater
36+
37+
the Simple Updater downloads the File every time the function is called.
3538

36-
simple updater:
3739
```cpp
3840
ESPhttpUpdate.update("192.168.0.2", 80, "/arduino.bin");
3941
```
4042

41-
advanced:
43+
##### advanced updater
44+
45+
Its possible to point to a script at the server.
46+
If a version String is delivered to the Function this String will be send to the server.
47+
A Server side Update check is now possible.
48+
49+
the Server can return a binary file for update (Header 200)
50+
or it return header 304 to notify the ESP that no Update is needed.
51+
4252
```cpp
4353
t_httpUpdate_return ret = ESPhttpUpdate.update("192.168.0.2", 80, "/esp/update/arduino.php", "optional current version string here");
4454
switch(ret) {
@@ -54,9 +64,93 @@ switch(ret) {
5464
}
5565
```
5666

57-
### Server request handling
67+
#### Server request handling
68+
69+
##### simple updater
70+
71+
for the simple Updater the Server only needs to deliver the binary file for update.
72+
73+
##### advanced updater
74+
75+
for advanced update management a Script needs to run at the Server side, for example a PHP script.
76+
at every Update request the the ESP sends some informations in the Header to the Server
77+
78+
example Header data:
79+
```
80+
[HTTP_USER_AGENT] => ESP8266-http-Update
81+
[HTTP_X_ESP8266_STA_MAC] => 18:FE:AA:AA:AA:AA
82+
[HTTP_X_ESP8266_AP_MAC] => 1A:FE:AA:AA:AA:AA
83+
[HTTP_X_ESP8266_FREE_SPACE] => 671744
84+
[HTTP_X_ESP8266_SKETCH_SIZE] => 373940
85+
[HTTP_X_ESP8266_CHIP_SIZE] => 524288
86+
[HTTP_X_ESP8266_SDK_VERSION] => 1.3.0
87+
[HTTP_X_ESP8266_VERSION] => DOOR-7-g14f53a19
88+
```
89+
90+
with this information the script now can check if a update is needed.
91+
It is also possible to deliver different binary´s based on the MAC address for example.
92+
93+
script example:
94+
```php
95+
<?PHP
96+
97+
header('Content-type: text/plain; charset=utf8', true);
98+
99+
function check_header($name, $value = false) {
100+
if(!isset($_SERVER[$name])) {
101+
return false;
102+
}
103+
if($value && $_SERVER[$name] != $value) {
104+
return false;
105+
}
106+
return true;
107+
}
108+
109+
function sendFile($path) {
110+
header($_SERVER["SERVER_PROTOCOL"].' 200 OK', true, 200);
111+
header('Content-Type: application/octet-stream', true);
112+
header('Content-Disposition: attachment; filename='.basename($path));
113+
header('Content-Length: '.filesize($path), true);
114+
readfile($path);
115+
}
116+
117+
if(!check_header('HTTP_USER_AGENT', 'ESP8266-http-Update')) {
118+
header($_SERVER["SERVER_PROTOCOL"].' 403 Forbidden', true, 403);
119+
echo "only for ESP8266 updater!\n";
120+
exit();
121+
}
122+
123+
if(
124+
!check_header('HTTP_X_ESP8266_STA_MAC') ||
125+
!check_header('HTTP_X_ESP8266_AP_MAC') ||
126+
!check_header('HTTP_X_ESP8266_FREE_SPACE') ||
127+
!check_header('HTTP_X_ESP8266_SKETCH_SIZE') ||
128+
!check_header('HTTP_X_ESP8266_CHIP_SIZE') ||
129+
!check_header('HTTP_X_ESP8266_SDK_VERSION') ||
130+
!check_header('HTTP_X_ESP8266_VERSION')
131+
) {
132+
header($_SERVER["SERVER_PROTOCOL"].' 403 Forbidden', true, 403);
133+
echo "only for ESP8266 updater! (header)\n";
134+
exit();
135+
}
136+
137+
$db = array(
138+
"18:FE:AA:AA:AA:AA" => "DOOR-7-g14f53a19",
139+
"18:FE:AA:AA:AA:BB" => "TEMP-1.0.0"
140+
);
141+
142+
if(isset($db[$_SERVER['HTTP_X_ESP8266_STA_MAC']])) {
143+
if($db[$_SERVER['HTTP_X_ESP8266_STA_MAC']] != $_SERVER['HTTP_X_ESP8266_VERSION']) ) {
144+
sendFile("./bin/".$db[$_SERVER['HTTP_X_ESP8266_STA_MAC']]."bin");
145+
} else {
146+
header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified', true, 304);
147+
}
148+
}
149+
150+
header($_SERVER["SERVER_PROTOCOL"].' 500 no version for ESP MAC', true, 500);
151+
152+
```
58153

59-
TODO server side
60154

61155
## Stream Interface
62156

0 commit comments

Comments
 (0)