-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathota_github_yxms.ino
88 lines (73 loc) · 2.67 KB
/
ota_github_yxms.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
GitHub_Upgrade.ino - Example for ESP library for auto updating code from GitHub releases.
Created by Gavin Smalley, November 13th 2019.
Released under the LGPL v2.1.
It is the author's intention that this work may be used freely for private
and commercial use so long as any changes/improvements are freely shared with
the community under the same terms.
*/
#include <ESP8266WiFi.h>
#include <FS.h>
#ifndef STASSID
#define STASSID "xxj"
#define STAPSK "jihuihui"
#endif
// A single, global CertStore which can be used by all
// connections. Needs to stay live the entire time any of
// the WiFiClientBearSSLs are present.
#include <CertStoreBearSSL.h>
BearSSL::CertStore certStore;
/* Set up values for your repository and binary names */
#define GHOTA_USER "xxj1991"
#define GHOTA_REPO "OTA"
#define GHOTA_CURRENT_TAG "0.1.0"
#define GHOTA_BIN_FILE "yxms.bin"
#define GHOTA_ACCEPT_PRERELEASE 0
#include <ESP_OTA_GitHub.h>
void handle_upgade() {
// Initialise Update Code
//We do this locally so that the memory used is freed when the function exists.
ESPOTAGitHub ESPOTAGitHub(&certStore, GHOTA_USER, GHOTA_REPO, GHOTA_CURRENT_TAG, GHOTA_BIN_FILE, GHOTA_ACCEPT_PRERELEASE);
Serial.println("Checking for update...");
if (ESPOTAGitHub.checkUpgrade()) {
Serial.print("Upgrade found at: ");
Serial.println(ESPOTAGitHub.getUpgradeURL());
if (ESPOTAGitHub.doUpgrade()) {
Serial.println("Upgrade complete."); //This should never be seen as the device should restart on successful upgrade.
} else {
Serial.print("Unable to upgrade: ");
Serial.println(ESPOTAGitHub.getLastError());
}
} else {
Serial.print("Not proceeding to upgrade: ");
Serial.println(ESPOTAGitHub.getLastError());
}
}
void setup() {
// Start serial for debugging (not used by library, just this sketch).
Serial.begin(115200);
// Start SPIFFS and retrieve certificates.
SPIFFS.begin();
int numCerts = certStore.initCertStore(SPIFFS, PSTR("/certs.idx"), PSTR("/certs.ar"));
Serial.print(F("Number of CA certs read: "));
Serial.println(numCerts);
if (numCerts == 0) {
Serial.println(F("No certs found. Did you run certs-from-mozill.py and upload the SPIFFS directory before running?"));
return; // Can't connect to anything w/o certs!
}
// Connect to WiFi
Serial.print("Connecting to WiFi... ");
WiFi.mode(WIFI_STA);
WiFi.begin(STASSID, STAPSK);
if ((WiFi.status() != WL_CONNECTED)) {
Serial.print("... ");
}
Serial.println();
/* This is the actual code to check and upgrade */
handle_upgade();
/* End of check and upgrade code */
// Your setup code goes here
}
void loop () {
// Your loop code goes here
}