* 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
85 lines
1.9 KiB
C++
85 lines
1.9 KiB
C++
/**
|
|
httpUpdateSecure.ino
|
|
|
|
Created on: 27.11.2015
|
|
|
|
*/
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <WiFi.h>
|
|
#include <HTTPClient.h>
|
|
#include <HTTPUpdate.h>
|
|
|
|
#ifndef STASSID
|
|
#define STASSID "your-ssid"
|
|
#define STAPSK "your-password"
|
|
#endif
|
|
|
|
const char *ssid = STASSID;
|
|
const char *pass = STAPSK;
|
|
|
|
#define UPDATE_URL "https://www.ziplabel.com/file.bin"
|
|
|
|
WiFiMulti WiFiMulti;
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println();
|
|
Serial.println();
|
|
Serial.println();
|
|
|
|
for (uint8_t t = 4; t > 0; t--) {
|
|
Serial.printf("[SETUP] WAIT %d...\n", t);
|
|
Serial.flush();
|
|
delay(1000);
|
|
}
|
|
|
|
WiFi.mode(WIFI_STA);
|
|
WiFiMulti.addAP(ssid, pass);
|
|
}
|
|
|
|
void update_started() {
|
|
Serial.println("CALLBACK: HTTP update process started");
|
|
}
|
|
|
|
void update_finished() {
|
|
Serial.println("CALLBACK: HTTP update process finished");
|
|
}
|
|
|
|
void update_progress(int cur, int total) {
|
|
Serial.printf("CALLBACK: HTTP update process at %d of %d bytes...\n", cur, total);
|
|
}
|
|
|
|
void update_error(int err) {
|
|
Serial.printf("CALLBACK: HTTP update fatal error code %d\n", err);
|
|
}
|
|
|
|
|
|
void loop() {
|
|
// wait for WiFi connection
|
|
if ((WiFiMulti.run() == WL_CONNECTED)) {
|
|
|
|
// Add optional callback notifiers
|
|
httpUpdate.onStart(update_started);
|
|
httpUpdate.onEnd(update_finished);
|
|
httpUpdate.onProgress(update_progress);
|
|
httpUpdate.onError(update_error);
|
|
|
|
WiFiClientSecure client;
|
|
client.setInsecure();
|
|
t_httpUpdate_return ret = httpUpdate.update(client, UPDATE_URL);
|
|
// Or:
|
|
// t_httpUpdate_return ret = httpUpdate.update("server", 80, "file.bin");
|
|
|
|
switch (ret) {
|
|
case HTTP_UPDATE_FAILED: Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); break;
|
|
|
|
case HTTP_UPDATE_NO_UPDATES: Serial.println("HTTP_UPDATE_NO_UPDATES"); break;
|
|
|
|
case HTTP_UPDATE_OK: Serial.println("HTTP_UPDATE_OK"); break;
|
|
}
|
|
}
|
|
}
|