Prvni ulozeni z chegewara githubu
This commit is contained in:
@ -0,0 +1,283 @@
|
||||
/**
|
||||
AWS S3 OTA Update
|
||||
Date: 14th June 2017
|
||||
Author: Arvind Ravulavaru <https://github.com/arvindr21>
|
||||
Purpose: Perform an OTA update from a bin located in Amazon S3 (HTTP Only)
|
||||
|
||||
Upload:
|
||||
Step 1 : Download the sample bin file from the examples folder
|
||||
Step 2 : Upload it to your Amazon S3 account, in a bucket of your choice
|
||||
Step 3 : Once uploaded, inside S3, select the bin file >> More (button on top of the file list) >> Make Public
|
||||
Step 4 : You S3 URL => http://bucket-name.s3.ap-south-1.amazonaws.com/sketch-name.ino.bin
|
||||
Step 5 : Build the above URL and fire it either in your browser or curl it `curl -I -v http://bucket-name.ap-south-1.amazonaws.com/sketch-name.ino.bin` to validate the same
|
||||
Step 6: Plug in your SSID, Password, S3 Host and Bin file below
|
||||
|
||||
Build & upload
|
||||
Step 1 : Menu > Sketch > Export Compiled Library. The bin file will be saved in the sketch folder (Menu > Sketch > Show Sketch folder)
|
||||
Step 2 : Upload bin to S3 and continue the above process
|
||||
|
||||
// Check the bottom of this sketch for sample serial monitor log, during and after successful OTA Update
|
||||
*/
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <Update.h>
|
||||
|
||||
WiFiClient client;
|
||||
|
||||
// Variables to validate
|
||||
// response from S3
|
||||
long contentLength = 0;
|
||||
bool isValidContentType = false;
|
||||
|
||||
// Your SSID and PSWD that the chip needs
|
||||
// to connect to
|
||||
const char* SSID = "YOUR-SSID";
|
||||
const char* PSWD = "YOUR-SSID-PSWD";
|
||||
|
||||
// S3 Bucket Config
|
||||
String host = "bucket-name.s3.ap-south-1.amazonaws.com"; // Host => bucket-name.s3.region.amazonaws.com
|
||||
int port = 80; // Non https. For HTTPS 443. As of today, HTTPS doesn't work.
|
||||
String bin = "/sketch-name.ino.bin"; // bin file name with a slash in front.
|
||||
|
||||
// Utility to extract header value from headers
|
||||
String getHeaderValue(String header, String headerName) {
|
||||
return header.substring(strlen(headerName.c_str()));
|
||||
}
|
||||
|
||||
// OTA Logic
|
||||
void execOTA() {
|
||||
Serial.println("Connecting to: " + String(host));
|
||||
// Connect to S3
|
||||
if (client.connect(host.c_str(), port)) {
|
||||
// Connection Succeed.
|
||||
// Fecthing the bin
|
||||
Serial.println("Fetching Bin: " + String(bin));
|
||||
|
||||
// Get the contents of the bin file
|
||||
client.print(String("GET ") + bin + " HTTP/1.1\r\n" +
|
||||
"Host: " + host + "\r\n" +
|
||||
"Cache-Control: no-cache\r\n" +
|
||||
"Connection: close\r\n\r\n");
|
||||
|
||||
// Check what is being sent
|
||||
// Serial.print(String("GET ") + bin + " HTTP/1.1\r\n" +
|
||||
// "Host: " + host + "\r\n" +
|
||||
// "Cache-Control: no-cache\r\n" +
|
||||
// "Connection: close\r\n\r\n");
|
||||
|
||||
unsigned long timeout = millis();
|
||||
while (client.available() == 0) {
|
||||
if (millis() - timeout > 5000) {
|
||||
Serial.println("Client Timeout !");
|
||||
client.stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Once the response is available,
|
||||
// check stuff
|
||||
|
||||
/*
|
||||
Response Structure
|
||||
HTTP/1.1 200 OK
|
||||
x-amz-id-2: NVKxnU1aIQMmpGKhSwpCBh8y2JPbak18QLIfE+OiUDOos+7UftZKjtCFqrwsGOZRN5Zee0jpTd0=
|
||||
x-amz-request-id: 2D56B47560B764EC
|
||||
Date: Wed, 14 Jun 2017 03:33:59 GMT
|
||||
Last-Modified: Fri, 02 Jun 2017 14:50:11 GMT
|
||||
ETag: "d2afebbaaebc38cd669ce36727152af9"
|
||||
Accept-Ranges: bytes
|
||||
Content-Type: application/octet-stream
|
||||
Content-Length: 357280
|
||||
Server: AmazonS3
|
||||
|
||||
{{BIN FILE CONTENTS}}
|
||||
|
||||
*/
|
||||
while (client.available()) {
|
||||
// read line till /n
|
||||
String line = client.readStringUntil('\n');
|
||||
// remove space, to check if the line is end of headers
|
||||
line.trim();
|
||||
|
||||
// if the the line is empty,
|
||||
// this is end of headers
|
||||
// break the while and feed the
|
||||
// remaining `client` to the
|
||||
// Update.writeStream();
|
||||
if (!line.length()) {
|
||||
//headers ended
|
||||
break; // and get the OTA started
|
||||
}
|
||||
|
||||
// Check if the HTTP Response is 200
|
||||
// else break and Exit Update
|
||||
if (line.startsWith("HTTP/1.1")) {
|
||||
if (line.indexOf("200") < 0) {
|
||||
Serial.println("Got a non 200 status code from server. Exiting OTA Update.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// extract headers here
|
||||
// Start with content length
|
||||
if (line.startsWith("Content-Length: ")) {
|
||||
contentLength = atol((getHeaderValue(line, "Content-Length: ")).c_str());
|
||||
Serial.println("Got " + String(contentLength) + " bytes from server");
|
||||
}
|
||||
|
||||
// Next, the content type
|
||||
if (line.startsWith("Content-Type: ")) {
|
||||
String contentType = getHeaderValue(line, "Content-Type: ");
|
||||
Serial.println("Got " + contentType + " payload.");
|
||||
if (contentType == "application/octet-stream") {
|
||||
isValidContentType = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Connect to S3 failed
|
||||
// May be try?
|
||||
// Probably a choppy network?
|
||||
Serial.println("Connection to " + String(host) + " failed. Please check your setup");
|
||||
// retry??
|
||||
// execOTA();
|
||||
}
|
||||
|
||||
// Check what is the contentLength and if content type is `application/octet-stream`
|
||||
Serial.println("contentLength : " + String(contentLength) + ", isValidContentType : " + String(isValidContentType));
|
||||
|
||||
// check contentLength and content type
|
||||
if (contentLength && isValidContentType) {
|
||||
// Check if there is enough to OTA Update
|
||||
bool canBegin = Update.begin(contentLength);
|
||||
|
||||
// If yes, begin
|
||||
if (canBegin) {
|
||||
Serial.println("Begin OTA. This may take 2 - 5 mins to complete. Things might be quite for a while.. Patience!");
|
||||
// No activity would appear on the Serial monitor
|
||||
// So be patient. This may take 2 - 5mins to complete
|
||||
size_t written = Update.writeStream(client);
|
||||
|
||||
if (written == contentLength) {
|
||||
Serial.println("Written : " + String(written) + " successfully");
|
||||
} else {
|
||||
Serial.println("Written only : " + String(written) + "/" + String(contentLength) + ". Retry?" );
|
||||
// retry??
|
||||
// execOTA();
|
||||
}
|
||||
|
||||
if (Update.end()) {
|
||||
Serial.println("OTA done!");
|
||||
if (Update.isFinished()) {
|
||||
Serial.println("Update successfully completed. Rebooting.");
|
||||
ESP.restart();
|
||||
} else {
|
||||
Serial.println("Update not finished? Something went wrong!");
|
||||
}
|
||||
} else {
|
||||
Serial.println("Error Occurred. Error #: " + String(Update.getError()));
|
||||
}
|
||||
} else {
|
||||
// not enough space to begin OTA
|
||||
// Understand the partitions and
|
||||
// space availability
|
||||
Serial.println("Not enough space to begin OTA");
|
||||
client.flush();
|
||||
}
|
||||
} else {
|
||||
Serial.println("There was no content in the response");
|
||||
client.flush();
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
//Begin Serial
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
|
||||
Serial.println("Connecting to " + String(SSID));
|
||||
|
||||
// Connect to provided SSID and PSWD
|
||||
WiFi.begin(SSID, PSWD);
|
||||
|
||||
// Wait for connection to establish
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
Serial.print("."); // Keep the serial monitor lit!
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// Connection Succeed
|
||||
Serial.println("");
|
||||
Serial.println("Connected to " + String(SSID));
|
||||
|
||||
// Execute OTA Update
|
||||
execOTA();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// chill
|
||||
}
|
||||
|
||||
/*
|
||||
* Serial Monitor log for this sketch
|
||||
*
|
||||
* If the OTA succeeded, it would load the preference sketch, with a small modification. i.e.
|
||||
* Print `OTA Update succeeded!! This is an example sketch : Preferences > StartCounter`
|
||||
* And then keeps on restarting every 10 seconds, updating the preferences
|
||||
*
|
||||
*
|
||||
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
configsip: 0, SPIWP:0x00
|
||||
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
|
||||
mode:DIO, clock div:1
|
||||
load:0x3fff0008,len:8
|
||||
load:0x3fff0010,len:160
|
||||
load:0x40078000,len:10632
|
||||
load:0x40080000,len:252
|
||||
entry 0x40080034
|
||||
Connecting to SSID
|
||||
......
|
||||
Connected to SSID
|
||||
Connecting to: bucket-name.s3.ap-south-1.amazonaws.com
|
||||
Fetching Bin: /StartCounter.ino.bin
|
||||
Got application/octet-stream payload.
|
||||
Got 357280 bytes from server
|
||||
contentLength : 357280, isValidContentType : 1
|
||||
Begin OTA. This may take 2 - 5 mins to complete. Things might be quite for a while.. Patience!
|
||||
Written : 357280 successfully
|
||||
OTA done!
|
||||
Update successfully completed. Rebooting.
|
||||
ets Jun 8 2016 00:22:57
|
||||
|
||||
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
configsip: 0, SPIWP:0x00
|
||||
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
|
||||
mode:DIO, clock div:1
|
||||
load:0x3fff0008,len:8
|
||||
load:0x3fff0010,len:160
|
||||
load:0x40078000,len:10632
|
||||
load:0x40080000,len:252
|
||||
entry 0x40080034
|
||||
|
||||
OTA Update succeeded!! This is an example sketch : Preferences > StartCounter
|
||||
Current counter value: 1
|
||||
Restarting in 10 seconds...
|
||||
E (102534) wifi: esp_wifi_stop 802 wifi is not init
|
||||
ets Jun 8 2016 00:22:57
|
||||
|
||||
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
configsip: 0, SPIWP:0x00
|
||||
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
|
||||
mode:DIO, clock div:1
|
||||
load:0x3fff0008,len:8
|
||||
load:0x3fff0010,len:160
|
||||
load:0x40078000,len:10632
|
||||
load:0x40080000,len:252
|
||||
entry 0x40080034
|
||||
|
||||
OTA Update succeeded!! This is an example sketch : Preferences > StartCounter
|
||||
Current counter value: 2
|
||||
Restarting in 10 seconds...
|
||||
|
||||
....
|
||||
*
|
||||
*/
|
BIN
libraries/Update/examples/AWS_S3_OTA_Update/StartCounter.ino.bin
Normal file
BIN
libraries/Update/examples/AWS_S3_OTA_Update/StartCounter.ino.bin
Normal file
Binary file not shown.
@ -0,0 +1,98 @@
|
||||
// This sketch provide the functionality of OTA Firmware Upgrade
|
||||
#include "WiFi.h"
|
||||
#include "HttpsOTAUpdate.h"
|
||||
// This sketch shows how to implement HTTPS firmware update Over The Air.
|
||||
// Please provide your WiFi credentials, https URL to the firmware image and the server certificate.
|
||||
|
||||
static const char *ssid = "your-ssid"; // your network SSID (name of wifi network)
|
||||
static const char *password = "your-password"; // your network password
|
||||
|
||||
static const char *url = "https://example.com/firmware.bin"; //state url of your firmware image
|
||||
|
||||
static const char *server_certificate = "-----BEGIN CERTIFICATE-----\n" \
|
||||
"MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/\n" \
|
||||
"MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" \
|
||||
"DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow\n" \
|
||||
"SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT\n" \
|
||||
"GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC\n" \
|
||||
"AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF\n" \
|
||||
"q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8\n" \
|
||||
"SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0\n" \
|
||||
"Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA\n" \
|
||||
"a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj\n" \
|
||||
"/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T\n" \
|
||||
"AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG\n" \
|
||||
"CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv\n" \
|
||||
"bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k\n" \
|
||||
"c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw\n" \
|
||||
"VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC\n" \
|
||||
"ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz\n" \
|
||||
"MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu\n" \
|
||||
"Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF\n" \
|
||||
"AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo\n" \
|
||||
"uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n" \
|
||||
"wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n" \
|
||||
"X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n" \
|
||||
"PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n" \
|
||||
"KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n" \
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static HttpsOTAStatus_t otastatus;
|
||||
|
||||
void HttpEvent(HttpEvent_t *event)
|
||||
{
|
||||
switch(event->event_id) {
|
||||
case HTTP_EVENT_ERROR:
|
||||
Serial.println("Http Event Error");
|
||||
break;
|
||||
case HTTP_EVENT_ON_CONNECTED:
|
||||
Serial.println("Http Event On Connected");
|
||||
break;
|
||||
case HTTP_EVENT_HEADER_SENT:
|
||||
Serial.println("Http Event Header Sent");
|
||||
break;
|
||||
case HTTP_EVENT_ON_HEADER:
|
||||
Serial.printf("Http Event On Header, key=%s, value=%s\n", event->header_key, event->header_value);
|
||||
break;
|
||||
case HTTP_EVENT_ON_DATA:
|
||||
break;
|
||||
case HTTP_EVENT_ON_FINISH:
|
||||
Serial.println("Http Event On Finish");
|
||||
break;
|
||||
case HTTP_EVENT_DISCONNECTED:
|
||||
Serial.println("Http Event Disconnected");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setup(){
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
Serial.print("Connected to ");
|
||||
Serial.println(ssid);
|
||||
|
||||
HttpsOTA.onHttpEvent(HttpEvent);
|
||||
Serial.println("Starting OTA");
|
||||
HttpsOTA.begin(url, server_certificate);
|
||||
|
||||
Serial.println("Please Wait it takes some time ...");
|
||||
}
|
||||
|
||||
void loop(){
|
||||
otastatus = HttpsOTA.status();
|
||||
if(otastatus == HTTPS_OTA_SUCCESS) {
|
||||
Serial.println("Firmware written successfully. To reboot device, call API ESP.restart() or PUSH restart button on device");
|
||||
} else if(otastatus == HTTPS_OTA_FAIL) {
|
||||
Serial.println("Firmware Upgrade Fail");
|
||||
}
|
||||
delay(1000);
|
||||
}
|
32
libraries/Update/examples/HTTPS_OTA_Update/Readme.md
Normal file
32
libraries/Update/examples/HTTPS_OTA_Update/Readme.md
Normal file
@ -0,0 +1,32 @@
|
||||
# OTA Firmware Upgrade for Arduino
|
||||
This sketch allows Arduino user to perform Over The Air (OTA) firmware upgrade. It uses HTTPS.
|
||||
|
||||
# API introduced for OTA
|
||||
|
||||
## HttpsOTA.begin(const char * url, const char * server_certificate, bool skip_cert_common_name_check)
|
||||
|
||||
Main API which starts firmware upgrade
|
||||
|
||||
### Parameters
|
||||
* url : URL for the uploaded firmware image
|
||||
* server_certificate : Provide the ota server certificate for authentication via HTTPS
|
||||
* skip_cert_common_name_check : Skip any validation of server certificate CN field
|
||||
|
||||
The default value provided to skip_cert_common_name_check is true
|
||||
|
||||
## HttpsOTA.onHttpEvent(function)
|
||||
|
||||
This API exposes HTTP Events to the user
|
||||
|
||||
### Parameter
|
||||
Function passed has following signature
|
||||
void HttpEvent (HttpEvent_t * event);
|
||||
|
||||
# HttpsOTA.otaStatus()
|
||||
|
||||
It tracks the progress of OTA firmware upgrade.
|
||||
* HTTPS_OTA_IDLE : OTA upgrade have not started yet.
|
||||
* HTTPS_OTA_UPDATNG : OTA upgarde is in progress.
|
||||
* HTTPS_OTA_SUCCESS : OTA upgrade is successful.
|
||||
* HTTPS_OTA_FAIL : OTA upgrade failed.
|
||||
* HTTPS_OTA_ERR : Error occured while creating xEventGroup().
|
112
libraries/Update/examples/SD_Update/SD_Update.ino
Normal file
112
libraries/Update/examples/SD_Update/SD_Update.ino
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
Name: SD_Update.ino
|
||||
Created: 12.09.2017 15:07:17
|
||||
Author: Frederik Merz <frederik.merz@novalight.de>
|
||||
Purpose: Update firmware from SD card
|
||||
|
||||
Steps:
|
||||
1. Flash this image to the ESP32 an run it
|
||||
2. Copy update.bin to a SD-Card, you can basically
|
||||
compile this or any other example
|
||||
then copy and rename the app binary to the sd card root
|
||||
3. Connect SD-Card as shown in SD example,
|
||||
this can also be adapted for SPI
|
||||
3. After successfull update and reboot, ESP32 shall start the new app
|
||||
*/
|
||||
|
||||
#include <Update.h>
|
||||
#include <FS.h>
|
||||
#include <SD.h>
|
||||
|
||||
// perform the actual update from a given stream
|
||||
void performUpdate(Stream &updateSource, size_t updateSize) {
|
||||
if (Update.begin(updateSize)) {
|
||||
size_t written = Update.writeStream(updateSource);
|
||||
if (written == updateSize) {
|
||||
Serial.println("Written : " + String(written) + " successfully");
|
||||
}
|
||||
else {
|
||||
Serial.println("Written only : " + String(written) + "/" + String(updateSize) + ". Retry?");
|
||||
}
|
||||
if (Update.end()) {
|
||||
Serial.println("OTA done!");
|
||||
if (Update.isFinished()) {
|
||||
Serial.println("Update successfully completed. Rebooting.");
|
||||
}
|
||||
else {
|
||||
Serial.println("Update not finished? Something went wrong!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Serial.println("Error Occurred. Error #: " + String(Update.getError()));
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Not enough space to begin OTA");
|
||||
}
|
||||
}
|
||||
|
||||
// check given FS for valid update.bin and perform update if available
|
||||
void updateFromFS(fs::FS &fs) {
|
||||
File updateBin = fs.open("/update.bin");
|
||||
if (updateBin) {
|
||||
if(updateBin.isDirectory()){
|
||||
Serial.println("Error, update.bin is not a file");
|
||||
updateBin.close();
|
||||
return;
|
||||
}
|
||||
|
||||
size_t updateSize = updateBin.size();
|
||||
|
||||
if (updateSize > 0) {
|
||||
Serial.println("Try to start update");
|
||||
performUpdate(updateBin, updateSize);
|
||||
}
|
||||
else {
|
||||
Serial.println("Error, file is empty");
|
||||
}
|
||||
|
||||
updateBin.close();
|
||||
|
||||
// whe finished remove the binary from sd card to indicate end of the process
|
||||
fs.remove("/update.bin");
|
||||
}
|
||||
else {
|
||||
Serial.println("Could not load update.bin from sd root");
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
uint8_t cardType;
|
||||
Serial.begin(115200);
|
||||
Serial.println("Welcome to the SD-Update example!");
|
||||
|
||||
// You can uncomment this and build again
|
||||
// Serial.println("Update successfull");
|
||||
|
||||
//first init and check SD card
|
||||
if (!SD.begin()) {
|
||||
rebootEspWithReason("Card Mount Failed");
|
||||
}
|
||||
|
||||
cardType = SD.cardType();
|
||||
|
||||
if (cardType == CARD_NONE) {
|
||||
rebootEspWithReason("No SD_MMC card attached");
|
||||
}else{
|
||||
updateFromFS(SD);
|
||||
}
|
||||
}
|
||||
|
||||
void rebootEspWithReason(String reason){
|
||||
Serial.println(reason);
|
||||
delay(1000);
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
//will not be reached
|
||||
void loop() {
|
||||
|
||||
}
|
Reference in New Issue
Block a user