Skip to content

Commit 83b035d

Browse files
committed
Merge pull request #1 from esp8266/master
pull master
2 parents 843e111 + 66c69b3 commit 83b035d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4716
-23
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Documentation for latest development version:
5050
- [Reference](doc/reference.md)
5151
- [Supported boards](doc/boards.md)
5252
- [Change log](doc/changes.md)
53+
- [OTA Update](doc/ota_updates.md)
5354

5455
### Issues and support ###
5556

doc/ota_updates.md

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
---
2+
title: OTA Update
3+
---
4+
5+
## Table of Contents
6+
* [Basic Requirements](#basic-requirements)
7+
* [Arduino IDE](#arduino-ide)
8+
* [HTTP Server](#http-server)
9+
* [Stream Interface](#stream-interface)
10+
11+
## Basic Requirements
12+
13+
- Flash chip size is 2x the size of the sketch
14+
15+
## Arduino IDE
16+
17+
TODO describe Arduino IDE OTA process
18+
19+
#### Requirements
20+
- The ESP and the Computer must be connected to the Same network.
21+
22+
23+
## HTTP Server
24+
25+
the ```ESPhttpUpdate``` class can check for updates and download a binary file form a HTTP web server.
26+
It is possible to download updates from every IP or domain address on the Network or Internet.
27+
28+
29+
#### Requirements
30+
- web server
31+
32+
33+
#### Arduino code
34+
35+
##### simple updater
36+
37+
the Simple Updater downloads the File every time the function is called.
38+
39+
```cpp
40+
ESPhttpUpdate.update("192.168.0.2", 80, "/arduino.bin");
41+
```
42+
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+
52+
```cpp
53+
t_httpUpdate_return ret = ESPhttpUpdate.update("192.168.0.2", 80, "/esp/update/arduino.php", "optional current version string here");
54+
switch(ret) {
55+
case HTTP_UPDATE_FAILED:
56+
Serial.println("[update] Update failed.");
57+
break;
58+
case HTTP_UPDATE_NO_UPDATES:
59+
Serial.println("[update] Update no Update.");
60+
break;
61+
case HTTP_UPDATE_OK:
62+
Serial.println("[update] Update ok."); // may not called we reboot the ESP
63+
break;
64+
}
65+
```
66+
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+
```
153+
154+
155+
## Stream Interface
156+
157+
TODO describe Stream Interface update proccess
158+
159+
```cpp
160+
ESP.updateSketch(client, length);
161+
```
162+

libraries/ArduinoOTA/ArduinoOTA.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ void ArduinoOTA::setup() {
5151
}
5252

5353
void ArduinoOTA::handle() {
54+
55+
if (!*_udp_ota) {
56+
_udp_ota->begin(_port);
57+
if (_serial_debug) {
58+
Serial.println("OTA restarted");
59+
}
60+
}
5461

5562
if (!_udp_ota->parsePacket()) return;
5663

libraries/EEPROM/library.properties

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ author=Ivan Grokhotkov
44
maintainer=Ivan Grokhotkov <[email protected]>
55
sentence=Enables reading and writing data to the permanent FLASH storage, up to 4kb.
66
paragraph=
7+
category=Data Storage
78
url=http://arduino.cc/en/Reference/EEPROM
89
architectures=esp8266

libraries/ESP8266WiFi/src/ESP8266WiFi.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ int8_t ESP8266WiFiClass::scanComplete() {
472472
return ESP8266WiFiClass::_scanCount;
473473
}
474474

475-
return WIFI_SCAN_FAILD;
475+
return WIFI_SCAN_FAILED;
476476
}
477477

478478
void ESP8266WiFiClass::scanDelete()
@@ -527,7 +527,7 @@ int8_t ESP8266WiFiClass::scanNetworks(bool async)
527527
esp_yield();
528528
return ESP8266WiFiClass::_scanCount;
529529
} else {
530-
return WIFI_SCAN_FAILD;
530+
return WIFI_SCAN_FAILED;
531531
}
532532

533533
}
@@ -702,12 +702,12 @@ void wifi_wps_status_cb(wps_cb_status status)
702702
switch (status) {
703703
case WPS_CB_ST_SUCCESS:
704704
if(!wifi_wps_disable()) {
705-
DEBUGV("wps disable faild\n");
705+
DEBUGV("wps disable failed\n");
706706
}
707707
wifi_station_connect();
708708
break;
709709
case WPS_CB_ST_FAILED:
710-
DEBUGV("wps FAILD\n");
710+
DEBUGV("wps FAILED\n");
711711
break;
712712
case WPS_CB_ST_TIMEOUT:
713713
DEBUGV("wps TIMEOUT\n");
@@ -738,23 +738,23 @@ bool ESP8266WiFiClass::beginWPSConfig(void) {
738738
DEBUGV("wps begin\n");
739739

740740
if(!wifi_wps_disable()) {
741-
DEBUGV("wps disable faild\n");
741+
DEBUGV("wps disable failed\n");
742742
return false;
743743
}
744744

745745
// so far only WPS_TYPE_PBC is supported (SDK 1.2.0)
746746
if(!wifi_wps_enable(WPS_TYPE_PBC)) {
747-
DEBUGV("wps enable faild\n");
747+
DEBUGV("wps enable failed\n");
748748
return false;
749749
}
750750

751751
if(!wifi_set_wps_cb((wps_st_cb_t) &wifi_wps_status_cb)) {
752-
DEBUGV("wps cb faild\n");
752+
DEBUGV("wps cb failed\n");
753753
return false;
754754
}
755755

756756
if(!wifi_wps_start()) {
757-
DEBUGV("wps start faild\n");
757+
DEBUGV("wps start failed\n");
758758
return false;
759759
}
760760

libraries/ESP8266WiFi/src/ESP8266WiFi.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern "C" {
3333
#include "WiFiServer.h"
3434

3535
#define WIFI_SCAN_RUNNING (-1)
36-
#define WIFI_SCAN_FAILD (-2)
36+
#define WIFI_SCAN_FAILED (-2)
3737

3838
enum WiFiMode { WIFI_OFF = 0, WIFI_STA = 1, WIFI_AP = 2, WIFI_AP_STA = 3 };
3939

libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ wl_status_t ESP8266WiFiMulti::run(void) {
133133
DEBUG_WIFI_MULTI("[WIFI] Channel: %d\n", WiFi.channel());
134134
break;
135135
case WL_NO_SSID_AVAIL:
136-
DEBUG_WIFI_MULTI("[WIFI] Connecting Faild AP not found.\n");
136+
DEBUG_WIFI_MULTI("[WIFI] Connecting Failed AP not found.\n");
137137
break;
138138
case WL_CONNECT_FAILED:
139-
DEBUG_WIFI_MULTI("[WIFI] Connecting Faild.\n");
139+
DEBUG_WIFI_MULTI("[WIFI] Connecting Failed.\n");
140140
break;
141141
default:
142-
DEBUG_WIFI_MULTI("[WIFI] Connecting Faild (%d).\n", status);
142+
DEBUG_WIFI_MULTI("[WIFI] Connecting Failed (%d).\n", status);
143143
break;
144144
}
145145
} else {

libraries/ESP8266httpUpdate/library.properties

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ author=Markus Sattler
44
maintainer=Markus Sattler
55
sentence=Http Update for ESP8266
66
paragraph=
7+
category=Data Processing
78
url=https://github.com/Links2004/Arduino/tree/esp8266/hardware/esp8266com/esp8266/libraries/ESP8266httpUpdate
89
architectures=esp8266

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ ESP8266HTTPUpdate::~ESP8266HTTPUpdate(void) {
3535

3636
t_httpUpdate_return ESP8266HTTPUpdate::update(const char * host, uint16_t port, const char * url, const char * current_version) {
3737

38-
t_httpUpdate_return ret = HTTP_UPDATE_FAILD;
38+
t_httpUpdate_return ret = HTTP_UPDATE_FAILED;
3939
WiFiClient tcp;
4040
DEBUG_HTTP_UPDATE("[httpUpdate] connected to %s:%u %s .... ", host, port, url);
4141

4242
if(!tcp.connect(host, port)) {
43-
DEBUG_HTTP_UPDATE("faild.\n");
43+
DEBUG_HTTP_UPDATE("failed.\n");
4444
return ret;
4545
}
4646
DEBUG_HTTP_UPDATE("ok.\n");
@@ -125,7 +125,7 @@ t_httpUpdate_return ESP8266HTTPUpdate::update(const char * host, uint16_t port,
125125
case 200: ///< OK (Start Update)
126126
if(len > 0) {
127127
if(len > ESP.getFreeSketchSpace()) {
128-
ret = HTTP_UPDATE_FAILD;
128+
ret = HTTP_UPDATE_FAILED;
129129
DEBUG_HTTP_UPDATE("[httpUpdate] FreeSketchSpace to low (%d) needed: %d\n", ESP.getFreeSketchSpace(), len);
130130
} else {
131131

@@ -140,13 +140,13 @@ t_httpUpdate_return ESP8266HTTPUpdate::update(const char * host, uint16_t port,
140140
tcp.stop();
141141
ESP.restart();
142142
} else {
143-
ret = HTTP_UPDATE_FAILD;
143+
ret = HTTP_UPDATE_FAILED;
144144
DEBUG_HTTP_UPDATE("[httpUpdate] Update failed\n");
145145
}
146146
}
147147
} else {
148-
ret = HTTP_UPDATE_FAILD;
149-
DEBUG_HTTP_UPDATE("[httpUpdate]Content-Length is 0?!\n");
148+
ret = HTTP_UPDATE_FAILED;
149+
DEBUG_HTTP_UPDATE("[httpUpdate] Content-Length is 0?!\n");
150150
}
151151
break;
152152
case 304:
@@ -157,7 +157,7 @@ t_httpUpdate_return ESP8266HTTPUpdate::update(const char * host, uint16_t port,
157157
///< Forbidden
158158
// todo handle login
159159
default:
160-
ret = HTTP_UPDATE_FAILD;
160+
ret = HTTP_UPDATE_FAILED;
161161
DEBUG_HTTP_UPDATE("[httpUpdate] Code is (%d)\n", code);
162162
break;
163163
}

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#endif
3939

4040
typedef enum {
41-
HTTP_UPDATE_FAILD,
41+
HTTP_UPDATE_FAILED,
4242
HTTP_UPDATE_NO_UPDATES,
4343
HTTP_UPDATE_OK
4444
} t_httpUpdate_return;

libraries/Ethernet/README.adoc

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
= Ethernet Library for Arduino =
2+
3+
With the Arduino Ethernet Shield, this library allows an Arduino board to connect to the internet.
4+
5+
For more information about this library please visit us at
6+
http://www.arduino.cc/en/Reference/Ethernet
7+
8+
modified to run on the ESP8266
9+
10+
== License ==
11+
12+
Copyright (c) 2010 Arduino LLC. All right reserved.
13+
14+
This library is free software; you can redistribute it and/or
15+
modify it under the terms of the GNU Lesser General Public
16+
License as published by the Free Software Foundation; either
17+
version 2.1 of the License, or (at your option) any later version.
18+
19+
This library is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22+
Lesser General Public License for more details.
23+
24+
You should have received a copy of the GNU Lesser General Public
25+
License along with this library; if not, write to the Free Software
26+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

0 commit comments

Comments
 (0)