Skip to content

Commit 0b390d7

Browse files
Add HTTPUpdate class to pull updates from HTTP(S) (#789)
* Add HTTPUpdate class to pull updates from HTTP(S) * Increase GH runners for pulls WiFi builds and examples are taking some serious time now * HTTPUpdate tests build on Pico W
1 parent a3f5fee commit 0b390d7

File tree

10 files changed

+788
-4
lines changed

10 files changed

+788
-4
lines changed

.github/workflows/pull-request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
runs-on: ubuntu-latest
5858
strategy:
5959
matrix:
60-
chunk: [0, 1, 2, 3]
60+
chunk: [0, 1, 2, 3, 4, 5]
6161
steps:
6262
- uses: actions/checkout@v3
6363
with:
@@ -76,7 +76,7 @@ jobs:
7676
TRAVIS_BUILD_DIR: ${{ github.workspace }}
7777
TRAVIS_TAG: ${{ github.ref }}
7878
BUILD_PARITY: custom
79-
mod: 4
79+
mod: 6
8080
rem: ${{ matrix.chunk }}
8181
run: |
8282
cd pico-sdk
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
httpUpdate.ino
3+
4+
Created on: 27.11.2015
5+
6+
*/
7+
8+
#include <Arduino.h>
9+
10+
#include <WiFi.h>
11+
#include <HTTPClient.h>
12+
#include <HTTPUpdate.h>
13+
14+
#ifndef STASSID
15+
#define STASSID "your-ssid"
16+
#define STAPSK "your-password"
17+
#endif
18+
19+
const char *ssid = STASSID;
20+
const char *pass = STAPSK;
21+
22+
#define UPDATE_URL "http://192.168.1.8/xfer/file.bin"
23+
24+
WiFiMulti WiFiMulti;
25+
26+
void setup() {
27+
28+
Serial.begin(115200);
29+
30+
Serial.println();
31+
Serial.println();
32+
Serial.println();
33+
34+
for (uint8_t t = 4; t > 0; t--) {
35+
Serial.printf("[SETUP] WAIT %d...\n", t);
36+
Serial.flush();
37+
delay(1000);
38+
}
39+
40+
WiFi.mode(WIFI_STA);
41+
WiFiMulti.addAP(ssid, pass);
42+
}
43+
44+
void update_started() {
45+
Serial.println("CALLBACK: HTTP update process started");
46+
}
47+
48+
void update_finished() {
49+
Serial.println("CALLBACK: HTTP update process finished");
50+
}
51+
52+
void update_progress(int cur, int total) {
53+
Serial.printf("CALLBACK: HTTP update process at %d of %d bytes...\n", cur, total);
54+
}
55+
56+
void update_error(int err) {
57+
Serial.printf("CALLBACK: HTTP update fatal error code %d\n", err);
58+
}
59+
60+
61+
void loop() {
62+
// wait for WiFi connection
63+
if ((WiFiMulti.run() == WL_CONNECTED)) {
64+
65+
// Add optional callback notifiers
66+
httpUpdate.onStart(update_started);
67+
httpUpdate.onEnd(update_finished);
68+
httpUpdate.onProgress(update_progress);
69+
httpUpdate.onError(update_error);
70+
71+
t_httpUpdate_return ret = httpUpdate.update(UPDATE_URL);
72+
// Or:
73+
// t_httpUpdate_return ret = httpUpdate.update("server", 80, "file.bin");
74+
75+
switch (ret) {
76+
case HTTP_UPDATE_FAILED: Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); break;
77+
78+
case HTTP_UPDATE_NO_UPDATES: Serial.println("HTTP_UPDATE_NO_UPDATES"); break;
79+
80+
case HTTP_UPDATE_OK: Serial.println("HTTP_UPDATE_OK"); break;
81+
}
82+
}
83+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
httpUpdateSecure.ino
3+
4+
Created on: 27.11.2015
5+
6+
*/
7+
8+
#include <Arduino.h>
9+
10+
#include <WiFi.h>
11+
#include <HTTPClient.h>
12+
#include <HTTPUpdate.h>
13+
14+
#ifndef STASSID
15+
#define STASSID "your-ssid"
16+
#define STAPSK "your-password"
17+
#endif
18+
19+
const char *ssid = STASSID;
20+
const char *pass = STAPSK;
21+
22+
#define UPDATE_URL "https://www.ziplabel.com/file.bin"
23+
24+
WiFiMulti WiFiMulti;
25+
26+
void setup() {
27+
28+
Serial.begin(115200);
29+
30+
Serial.println();
31+
Serial.println();
32+
Serial.println();
33+
34+
for (uint8_t t = 4; t > 0; t--) {
35+
Serial.printf("[SETUP] WAIT %d...\n", t);
36+
Serial.flush();
37+
delay(1000);
38+
}
39+
40+
WiFi.mode(WIFI_STA);
41+
WiFiMulti.addAP(ssid, pass);
42+
}
43+
44+
void update_started() {
45+
Serial.println("CALLBACK: HTTP update process started");
46+
}
47+
48+
void update_finished() {
49+
Serial.println("CALLBACK: HTTP update process finished");
50+
}
51+
52+
void update_progress(int cur, int total) {
53+
Serial.printf("CALLBACK: HTTP update process at %d of %d bytes...\n", cur, total);
54+
}
55+
56+
void update_error(int err) {
57+
Serial.printf("CALLBACK: HTTP update fatal error code %d\n", err);
58+
}
59+
60+
61+
void loop() {
62+
// wait for WiFi connection
63+
if ((WiFiMulti.run() == WL_CONNECTED)) {
64+
65+
// Add optional callback notifiers
66+
httpUpdate.onStart(update_started);
67+
httpUpdate.onEnd(update_finished);
68+
httpUpdate.onProgress(update_progress);
69+
httpUpdate.onError(update_error);
70+
71+
WiFiClientSecure client;
72+
client.setInsecure();
73+
t_httpUpdate_return ret = httpUpdate.update(client, UPDATE_URL);
74+
// Or:
75+
// t_httpUpdate_return ret = httpUpdate.update("server", 80, "file.bin");
76+
77+
switch (ret) {
78+
case HTTP_UPDATE_FAILED: Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); break;
79+
80+
case HTTP_UPDATE_NO_UPDATES: Serial.println("HTTP_UPDATE_NO_UPDATES"); break;
81+
82+
case HTTP_UPDATE_OK: Serial.println("HTTP_UPDATE_OK"); break;
83+
}
84+
}
85+
}

libraries/HTTPUpdate/keywords.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#######################################
2+
# Syntax Coloring Map For ESP8266httpUpdate
3+
#######################################
4+
5+
#######################################
6+
# Library (KEYWORD3)
7+
#######################################
8+
9+
HTTPUpdate KEYWORD3 RESERVED_WORD
10+
11+
#######################################
12+
# Datatypes (KEYWORD1)
13+
#######################################
14+
15+
HTTPUpdateResult KEYWORD1 DATA_TYPE
16+
ESPhttpUpdate KEYWORD1 DATA_TYPE
17+
18+
#######################################
19+
# Methods and Functions (KEYWORD2)
20+
#######################################
21+
22+
rebootOnUpdate KEYWORD2
23+
update KEYWORD2
24+
updateSpiffs KEYWORD2
25+
getLastError KEYWORD2
26+
getLastErrorString KEYWORD2
27+
setAuthorization KEYWORD2
28+
29+
#######################################
30+
# Constants (LITERAL1)
31+
#######################################
32+
33+
HTTP_UE_TOO_LESS_SPACE LITERAL1 RESERVED_WORD_2
34+
HTTP_UE_SERVER_NOT_REPORT_SIZE LITERAL1 RESERVED_WORD_2
35+
HTTP_UE_SERVER_FILE_NOT_FOUND LITERAL1 RESERVED_WORD_2
36+
HTTP_UE_SERVER_FORBIDDEN LITERAL1 RESERVED_WORD_2
37+
HTTP_UE_SERVER_WRONG_HTTP_CODE LITERAL1 RESERVED_WORD_2
38+
HTTP_UE_SERVER_FAULTY_MD5 LITERAL1 RESERVED_WORD_2
39+
HTTP_UE_BIN_VERIFY_HEADER_FAILED LITERAL1 RESERVED_WORD_2
40+
HTTP_UE_BIN_FOR_WRONG_FLASH LITERAL1 RESERVED_WORD_2
41+
HTTP_UE_SERVER_UNAUTHORIZED LITERAL1 RESERVED_WORD_2
42+
HTTP_UPDATE_FAILED LITERAL1 RESERVED_WORD_2
43+
HTTP_UPDATE_NO_UPDATES LITERAL1 RESERVED_WORD_2
44+
HTTP_UPDATE_OK LITERAL1 RESERVED_WORD_2
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=HTTPUpdate
2+
version=1.3
3+
author=Markus Sattler
4+
maintainer=Earle F. Philhower, III <[email protected]>
5+
sentence=Http Update for ESP8266, ported to Pico
6+
paragraph=
7+
category=Data Processing
8+
url=https://github.com/earlephilhower/arduino-pico
9+
architectures=rp2040
10+
dot_a_linkage=true

0 commit comments

Comments
 (0)