-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.cpp
75 lines (59 loc) · 2.16 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#include <Ticker.h>
#define CHECK_INTERVAL 60
// Stringifying the BUILD_TAG parameter
#define TEXTIFY(A) #A
#define ESCAPEQUOTE(A) TEXTIFY(A)
String buildTag = ESCAPEQUOTE(BUILD_TAG);
ESP8266WiFiMulti WiFiMulti;
Ticker updateCheck;
boolean doUpdateCheck = true;
void enableUpdateCheck() {
doUpdateCheck = true;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Now starting...");
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
//reset saved settings
//wifiManager.resetSettings();
wifiManager.autoConnect("AutoConnectAP");
//or use this for auto generated name ESP + ChipID
//wifiManager.autoConnect();
Serial.println("Started..");
Serial.println("BUILD_TAG: "+ buildTag);
// don't wanna miss a thing... Check every 60 seconds
updateCheck.attach(CHECK_INTERVAL, enableUpdateCheck);
}
void loop() {
// press nodemcu's flash button
int flashButtonState = digitalRead(0);
if (flashButtonState == LOW || doUpdateCheck) {
Serial.println("Going to update firmware...");
if((WiFiMulti.run() == WL_CONNECTED)) {
Serial.println("Checking for Update. Current version: " + buildTag);
t_httpUpdate_return ret = ESPhttpUpdate.update("http://www.squix.org/blog/firmware.php?tag=" + buildTag);
switch(ret) {
case HTTP_UPDATE_FAILED:
Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.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;
}
}
doUpdateCheck = false;
}
}