From e07426a94c422b1ad242b686a4e94b0d4bb9a309 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 20 Nov 2020 22:55:27 +0100 Subject: [PATCH] Code cleanup --- src/hasp_mqtt.cpp | 6 ------ src/hasp_oobe.cpp | 8 ++++---- src/hasp_ota.cpp | 16 ++++++++++------ src/main.cpp | 12 ++++++------ 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/hasp_mqtt.cpp b/src/hasp_mqtt.cpp index 0f826b85..2a310358 100644 --- a/src/hasp_mqtt.cpp +++ b/src/hasp_mqtt.cpp @@ -443,12 +443,6 @@ void mqttReconnect() mqtt_send_statusupdate(); } -void mqttPreSetup() -{ - // mqttClient.setCallback(mqtt_message_cb); - // mqttClient.setBufferSize(1024); -} - void mqttSetup() { mqttEnabled = strlen(mqttServer) > 0 && mqttPort > 0; diff --git a/src/hasp_oobe.cpp b/src/hasp_oobe.cpp index 115165b1..d25643b3 100644 --- a/src/hasp_oobe.cpp +++ b/src/hasp_oobe.cpp @@ -73,8 +73,9 @@ static void kb_event_cb(lv_obj_t * event_kb, lv_event_t event) } if(strlen(ssid) > 0) { - wifiSetConfig(settings.as()); - if(wifiTestConnection()) { + if(wifiValidateSsid(ssid, pass)) { + wifiSetConfig(settings.as()); + Log.notice(TAG_OOBE, F("SSID validated, rebooting...")); dispatchReboot(true); } } @@ -312,12 +313,11 @@ bool oobeSetup() oobeSetupQR(ssid, pass); oobeSetupSsid(); + lv_obj_set_click(lv_disp_get_layer_sys(NULL), true); if(oobeAutoCalibrate) { - lv_obj_set_click(lv_disp_get_layer_sys(NULL), true); lv_obj_set_event_cb(lv_disp_get_layer_sys(NULL), oobe_calibrate_cb); Log.trace(TAG_OOBE, F("Enabled Auto Calibrate on touch")); } else { - lv_obj_set_click(lv_disp_get_layer_sys(NULL), false); lv_obj_set_event_cb(lv_disp_get_layer_sys(NULL), gotoPage1_cb); Log.trace(TAG_OOBE, F("Already calibrated")); } diff --git a/src/hasp_ota.cpp b/src/hasp_ota.cpp index 42a763b4..4e02df0e 100644 --- a/src/hasp_ota.cpp +++ b/src/hasp_ota.cpp @@ -28,11 +28,10 @@ static WiFiClient otaClient; #define F_OTA_URL F("otaurl") -std::string otaUrl = "http://10.1.0.3"; +std::string otaUrl = "http://ota.netwize.be"; +int16_t otaPort = HASP_OTA_PORT; int8_t otaPrecentageComplete = -1; -int16_t otaPort = HASP_OTA_PORT; - void otaProgress() { Log.verbose(TAG_OTA, F("%s update in progress... %3u%"), @@ -118,7 +117,7 @@ void otaSetup() #endif // ArduinoOTA.setTimeout(1000); #endif - ArduinoOTA.setRebootOnSuccess(false); // We do that + ArduinoOTA.setRebootOnSuccess(false); // We do that ourselves ArduinoOTA.begin(); Log.trace(TAG_OTA, F("Over the Air firmware update ready")); @@ -139,9 +138,11 @@ void otaEverySecond() void otaHttpUpdate(const char * espOtaUrl) { // Update ESP firmware from HTTP - // nextionSendCmd("page 0"); - // nextionSetAttr("p[0].b[1].txt", "\"HTTP update\\rstarting...\""); + // nextionSendCmd("page 0"); + // nextionSetAttr("p[0].b[1].txt", "\"HTTP update\\rstarting...\""); +#if HASP_USE_MDNS > 0 mdnsStop(); // Keep mDNS responder from breaking things +#endif #if defined(ARDUINO_ARCH_ESP8266) @@ -194,7 +195,10 @@ void otaHttpUpdate(const char * espOtaUrl) } #endif + +#if HASP_USE_MDNS > 0 mdnsStart(); +#endif // nextionSendCmd("page " + String(nextionActivePage)); } #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 4eabd644..dbf1f0f5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,10 +45,6 @@ void setup() * Apply User Configuration ***************************/ -#if HASP_USE_GPIO > 0 - gpioSetup(); -#endif - #if HASP_USE_ETHERNET > 0 ethernetSetup(); #endif @@ -61,8 +57,7 @@ void setup() wifiSetup(); #endif - // The network stack needs to be initialized before calling debugSetup, cause syslog needs lwip - // debugSetup(); + debugSetup(); guiSetup(); if(!oobeSetup()) { @@ -89,7 +84,12 @@ void setup() slaveSetup(); #endif +#if HASP_USE_GPIO > 0 + gpioSetup(); +#endif + mainLastLoopTime = millis() - 1000; // reset loop counter + delay(250); } void loop()