code cleanups (removed unused vars) and futher prepare for ota
This commit is contained in:
@@ -2,11 +2,6 @@
|
||||
* Libraries and global scope code
|
||||
*/
|
||||
|
||||
unsigned long lastMillis = 0;
|
||||
|
||||
String devname; // Device identifier for MQTT
|
||||
char nodename[80] = "UNDEF";
|
||||
|
||||
struct Settings {
|
||||
String name = "";
|
||||
String ip = "";
|
||||
|
||||
@@ -13,6 +13,8 @@ WiFiClientSecure net;
|
||||
|
||||
//BearSSL::WiFiClientSecure net;
|
||||
|
||||
unsigned long ota_lastcheck = 0;
|
||||
|
||||
//
|
||||
// If the WifiManager configuration portal is called, we can do stuff
|
||||
//
|
||||
@@ -21,9 +23,13 @@ WiFiClientSecure net;
|
||||
//}
|
||||
|
||||
void wifi_associate() {
|
||||
char apname[80];
|
||||
settings.name.toCharArray(apname, 80);
|
||||
|
||||
WifiManager.setConfigPortalTimeout(300); // If no configuration is done in 5 mins, exit/restart quietly
|
||||
if (WifiManager.autoConnect(nodename)) { // @@@FIXME@@@ we should really set a PSK for the AP (but in my brief testing it crashed the ESP, so what's up with that)
|
||||
PRINTLN_SERIAL("Wifi connected");
|
||||
if (WifiManager.autoConnect(apname)) { // @@@FIXME@@@ we should really set a PSK for the AP (but in my brief testing it crashed the ESP, so what's up with that)
|
||||
settings.ip = WiFi.localIP().toString();
|
||||
PRINTLN_SERIAL("Wifi IP: " + settings.ip);
|
||||
|
||||
//wificlient.setFingerprint(WTR_SHA1);
|
||||
net.setInsecure(); // Do not check fingerprint
|
||||
@@ -55,10 +61,13 @@ void wifi_loop() {
|
||||
PRINTLN_SERIAL("Wifi disconnected, trying to reconnect");
|
||||
wifi_associate();
|
||||
}
|
||||
}
|
||||
|
||||
// OTA routine to be run once every X seconds
|
||||
unsigned long ota_check = millis()/1000;
|
||||
if((ota_lastcheck == 0) || ((ota_check - ota_lastcheck) > OTA_UPDATE_INTERVAL)) {
|
||||
PRINTLN_SERIAL("Checking for OTA update");
|
||||
/*
|
||||
// Check for firmware upgrades
|
||||
Serial.println("Checking for firmware upgrade");
|
||||
t_httpUpdate_return ret = ESPhttpUpdate.update(wificlient, WTR_SERVER, WTR_SRVPORT, "/fw/", nodeversion);
|
||||
switch(ret) {
|
||||
case HTTP_UPDATE_FAILED: // HTTP 403, 404
|
||||
@@ -72,4 +81,7 @@ void wifi_loop() {
|
||||
break;
|
||||
}
|
||||
|
||||
*/
|
||||
*/
|
||||
ota_lastcheck = ota_check;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ void mqtt_connect() {
|
||||
}
|
||||
|
||||
void mqtt_setup() {
|
||||
PRINTLN_SERIAL(devname + "initialising module MQTT");
|
||||
PRINTLN_SERIAL("Initialising MQTT");
|
||||
}
|
||||
|
||||
void mqtt_loop() {
|
||||
|
||||
@@ -23,7 +23,7 @@ void setup() {
|
||||
// If we run in to trouble, this can painlessly be removed and the resulting device name will just be longer
|
||||
settings.name.remove(devlen+1, 6);
|
||||
|
||||
PRINTLN_SERIAL("device name generated");
|
||||
PRINTLN_SERIAL("Device name: " + settings.name);
|
||||
|
||||
wifi_setup();
|
||||
|
||||
@@ -37,7 +37,7 @@ void setup() {
|
||||
moon_setup();
|
||||
#endif
|
||||
// Start the cooperative scheduler loops
|
||||
PRINTLN_SERIAL(devname + "done setting up, ready for main loop");
|
||||
PRINTLN_SERIAL(settings.name + " done setting up, ready for main loop");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
Reference in New Issue
Block a user