-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
59 lines (50 loc) · 1.59 KB
/
main.cpp
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
#include <Arduino.h>
// OTA Hub via GitHub
#define OTAGH_OWNER_NAME "Hard-Stuff"
#define OTAGH_REPO_NAME "OTA-Hub-diy-example_project"
#include <OTA-Hub-diy.hpp>
// Networking
static const char *WIFI_SSID = "Hard-Stuff.com";
static const char *WIFI_PASS = "password";
#include <WiFiClientSecure.h>
WiFiClientSecure wifi_client;
void setup()
{
// Initialise our board
Serial.begin(115200);
Serial.println("Started...");
WiFi.begin(WIFI_SSID, WIFI_PASS);
if (WiFi.waitForConnectResult() != WL_CONNECTED)
{
Serial.println("WiFi failure");
ESP.restart();
}
// Initialise OTA
wifi_client.setCACert(OTAGH_CA_CERT); // Set the api.github.cm SSL cert on the WiFiSecure modem
OTA::init(wifi_client);
// Check OTA for updates
OTA::UpdateObject details = OTA::isUpdateAvailable();
details.print();
if (OTA::NO_UPDATE != details.condition)
{
Serial.println("An update is available!");
// Perform OTA update
OTA::InstallCondition result = OTA::performUpdate(&details);
// GitHub hosts files on different server, so we have to follow the redirect, unfortunately.
if (result == OTA::REDIRECT_REQUIRED)
{
wifi_client.setCACert(OTAGH_REDIRECT_CA_CERT); // Now set the objects.githubusercontent.com SSL cert
OTA::continueRedirect(&details); // Follow the redirect and performUpdate.
}
}
else
{
Serial.println("No new update available. Continuing...");
}
Serial.print("Loop");
}
void loop()
{
delay(5000);
Serial.print("edy loop");
}