Compare commits
	
		
			2 Commits
		
	
	
		
			4b571786ef
			...
			f00091ec99
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| f00091ec99 | |||
| 7bb74a43b9 | 
| @@ -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("Figured out my network \O/");   | ||||
|  | ||||
|     //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 | ||||
| @@ -73,3 +82,6 @@ void wifi_loop() { | ||||
|     } | ||||
|      | ||||
| */   | ||||
|     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("Figured out who I am \O/"); | ||||
|  | ||||
|   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("Done setting up, ready for main loop \O/"); | ||||
| } | ||||
|  | ||||
| void loop() { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user