From 394f75253bd2f4b9736615f8ee3ec79d9cf67110 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Sat, 4 Apr 2020 12:13:43 +0200 Subject: [PATCH] Remove settings Json from setup --- src/hasp.h | 2 +- src/hasp_button.cpp | 2 +- src/hasp_config.cpp | 5 +++-- src/hasp_config.h | 2 +- src/hasp_debug.cpp | 4 +--- src/hasp_debug.h | 2 +- src/hasp_gpio.cpp | 2 +- src/hasp_gpio.h | 2 +- src/hasp_http.cpp | 4 ++-- src/hasp_http.h | 2 +- src/hasp_mdns.cpp | 2 +- src/hasp_mdns.h | 2 +- src/hasp_mqtt.h | 6 +++--- src/hasp_ota.cpp | 17 +++++++++++------ src/hasp_ota.h | 2 +- src/hasp_telnet.h | 2 +- src/hasp_tft.cpp | 2 +- src/hasp_tft.h | 3 +-- src/hasp_wifi.cpp | 10 +++------- src/hasp_wifi.h | 2 +- src/main.cpp | 32 ++++++++++++-------------------- 21 files changed, 49 insertions(+), 58 deletions(-) diff --git a/src/hasp.h b/src/hasp.h index d8f6e71c..9d967e6f 100644 --- a/src/hasp.h +++ b/src/hasp.h @@ -59,7 +59,7 @@ enum lv_hasp_obj_type_t { /** * Create a hasp application */ -void haspSetup(JsonObject settings); +void haspSetup(); void haspLoop(void); void haspFirstSetup(void); diff --git a/src/hasp_button.cpp b/src/hasp_button.cpp index 9aa764d2..400a0b84 100644 --- a/src/hasp_button.cpp +++ b/src/hasp_button.cpp @@ -12,7 +12,7 @@ using namespace ace_button; static AceButton * button[HASP_NUM_INPUTS]; // Connect your button between pin 2 and GND -static void IRAM_ATTR button_event_cb(AceButton * button, uint8_t eventType, uint8_t buttonState) +static void button_event_cb(AceButton * button, uint8_t eventType, uint8_t buttonState) { char buffer[8]; switch(eventType) { diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp index 1aaafe39..9cf284ee 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -73,6 +73,7 @@ void configStartDebug(bool setupdebug, String & configFile) if(setupdebug) { debugStart(); // Debug started, now we can use it; HASP header sent Log.notice(F("FILE: [SUCCESS] SPI flash FS mounted")); + spiffsInfo(); spiffsList(); } Log.notice(F("CONF: Loading %s"), configFile.c_str()); @@ -112,7 +113,7 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false) Log.verbose(F("CONF: %s"), output.c_str()); Log.notice(F("CONF: [SUCCESS] Loaded %s"), configFile.c_str()); - if(setupdebug) debugSetup(settings[F("debug")]); + if(setupdebug) debugSetup(); return; } } @@ -179,7 +180,7 @@ void configWriteConfig() } } -void configSetup(JsonObject dummy) +void configSetup() { if(!SPIFFS.begin()) { Log.error(F("FILE: SPI flash init failed. Unable to mount FS: Using default settings...")); diff --git a/src/hasp_config.h b/src/hasp_config.h index 615b9a73..ee425190 100644 --- a/src/hasp_config.h +++ b/src/hasp_config.h @@ -32,7 +32,7 @@ const char F_DEBUG_TELEPERIOD[] PROGMEM = "teleperiod"; const char HASP_CONFIG_FILE[] PROGMEM = "/config.json"; -void configSetup(JsonObject settings); +void configSetup(); void configStop(void); void configSetConfig(JsonObject & settings); diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp index 7b802938..b5c15ae1 100644 --- a/src/hasp_debug.cpp +++ b/src/hasp_debug.cpp @@ -190,10 +190,8 @@ void syslogSend(uint8_t priority, const char * debugText) } #endif -void debugSetup(JsonObject settings) +void debugSetup() { - // debugSetConfig(settings); - #if HASP_USE_SYSLOG != 0 syslog = new Syslog(syslogClient, debugSyslogProtocol == 0 ? SYSLOG_PROTO_IETF : SYSLOG_PROTO_BSD); syslog->server(debugSyslogHost, debugSyslogPort); diff --git a/src/hasp_debug.h b/src/hasp_debug.h index dc670a7b..72a3c0a8 100644 --- a/src/hasp_debug.h +++ b/src/hasp_debug.h @@ -7,7 +7,7 @@ String debugHaspHeader(void); void debugPreSetup(JsonObject settings); -void debugSetup(JsonObject settings); +void debugSetup(); void debugLoop(void); void debugEverySecond(void); void debugStart(void); diff --git a/src/hasp_gpio.cpp b/src/hasp_gpio.cpp index 76b552e5..1ab5cefb 100644 --- a/src/hasp_gpio.cpp +++ b/src/hasp_gpio.cpp @@ -1,7 +1,7 @@ #include #include "ArduinoJson.h" -void gpioSetup(JsonObject settings) +void gpioSetup() { #if defined(ARDUINO_ARCH_ESP8266) pinMode(D1, OUTPUT); diff --git a/src/hasp_gpio.h b/src/hasp_gpio.h index 91911db6..075f3a12 100644 --- a/src/hasp_gpio.h +++ b/src/hasp_gpio.h @@ -1,3 +1,3 @@ #include "ArduinoJson.h" -void gpioSetup(JsonObject settings); +void gpioSetup(); diff --git a/src/hasp_http.cpp b/src/hasp_http.cpp index 0727ff3c..1b76337f 100644 --- a/src/hasp_http.cpp +++ b/src/hasp_http.cpp @@ -331,7 +331,7 @@ void webHandleFirmware() } //////////////////////////////////////////////////////////////////////////////////////////////////// -void httpSetup(const JsonObject & settings) +void httpSetup() { if(WiFi.getMode() == WIFI_AP) { debugPrintln(F("HTTP: Wifi access point")); @@ -1791,7 +1791,7 @@ void webStop() } //////////////////////////////////////////////////////////////////////////////////////////////////// -void httpSetup(const JsonObject & settings) +void httpSetup() { // httpSetConfig(settings); diff --git a/src/hasp_http.h b/src/hasp_http.h index 261a701b..d7a17db5 100644 --- a/src/hasp_http.h +++ b/src/hasp_http.h @@ -4,7 +4,7 @@ #include #include "ArduinoJson.h" -void httpSetup(const JsonObject & settings); +void httpSetup(); void httpLoop(void); void httpEvery5Seconds(void); void httpReconnect(void); diff --git a/src/hasp_mdns.cpp b/src/hasp_mdns.cpp index b39896fd..cfd6419d 100644 --- a/src/hasp_mdns.cpp +++ b/src/hasp_mdns.cpp @@ -20,7 +20,7 @@ uint8_t mdnsEnabled = true; -void mdnsSetup(const JsonObject & settings) +void mdnsSetup() { // mdnsSetConfig(settings); Log.verbose(F("MDNS: Setup Complete")); diff --git a/src/hasp_mdns.h b/src/hasp_mdns.h index d9c0e483..88d9414a 100644 --- a/src/hasp_mdns.h +++ b/src/hasp_mdns.h @@ -3,7 +3,7 @@ #include "ArduinoJson.h" -void mdnsSetup(const JsonObject & settings); +void mdnsSetup(); void mdnsLoop(void); void mdnsStart(void); void mdnsStop(void); diff --git a/src/hasp_mqtt.h b/src/hasp_mqtt.h index bd8d7d92..c0300cd6 100644 --- a/src/hasp_mqtt.h +++ b/src/hasp_mqtt.h @@ -3,18 +3,18 @@ #include "ArduinoJson.h" -void mqttSetup(const JsonObject & settings); +void mqttSetup(); void mqttLoop(); void mqttEvery5Seconds(bool wifiIsConnected); void mqttStop(); void mqttReconnect(); void IRAM_ATTR mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload); -void IRAM_ATTR mqtt_send_input(uint8_t id, const char * payload); +void mqtt_send_input(uint8_t id, const char * payload); void IRAM_ATTR mqtt_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data); void mqtt_send_statusupdate(void); -bool IRAM_ATTR mqttIsConnected(void); +bool IRAM_ATTR mqttIsConnected(); bool mqttGetConfig(const JsonObject & settings); bool mqttSetConfig(const JsonObject & settings); diff --git a/src/hasp_ota.cpp b/src/hasp_ota.cpp index 32cf6b9c..8f82d8a5 100644 --- a/src/hasp_ota.cpp +++ b/src/hasp_ota.cpp @@ -27,7 +27,7 @@ #include #endif -WiFiClient wifiClient; +static WiFiClient otaClient; #define F_OTA_URL F("otaurl") @@ -41,10 +41,9 @@ void otaProgress() (ArduinoOTA.getCommand() == U_FLASH ? PSTR("Firmware") : PSTR("Filesystem")), otaPrecentageComplete); } -void otaSetup(JsonObject settings) +void otaSetup() { - if(!settings[F_OTA_URL].isNull()) { - otaUrl = settings[F_OTA_URL].as().c_str(); + if(strlen(otaUrl.c_str())) { Log.verbose(F("ORA url: %s"), otaUrl.c_str()); } @@ -134,7 +133,13 @@ void otaHttpUpdate(const char * espOtaUrl) mdnsStop(); // Keep mDNS responder from breaking things #if defined(ARDUINO_ARCH_ESP8266) - t_httpUpdate_return returnCode = ESPhttpUpdate.update(wifiClient, espOtaUrl); + + ESPhttpUpdate.onStart(update_started); + ESPhttpUpdate.onEnd(update_finished); + ESPhttpUpdate.onProgress(update_progress); + ESPhttpUpdate.onError(update_error); + + t_httpUpdate_return returnCode = ESPhttpUpdate.update(otaClient, espOtaUrl); switch(returnCode) { case HTTP_UPDATE_FAILED: @@ -156,7 +161,7 @@ void otaHttpUpdate(const char * espOtaUrl) } #else - t_httpUpdate_return returnCode = httpUpdate.update(wifiClient, espOtaUrl); + t_httpUpdate_return returnCode = httpUpdate.update(otaClient, espOtaUrl); switch(returnCode) { case HTTP_UPDATE_FAILED: diff --git a/src/hasp_ota.h b/src/hasp_ota.h index 4d439b38..3004691a 100644 --- a/src/hasp_ota.h +++ b/src/hasp_ota.h @@ -3,7 +3,7 @@ #include "ArduinoJson.h" -void otaSetup(JsonObject settings); +void otaSetup(); void otaLoop(void); void otaEverySecond(void); void otaHttpUpdate(const char * espOtaUrl); diff --git a/src/hasp_telnet.h b/src/hasp_telnet.h index e61c46e5..7bf4fecc 100644 --- a/src/hasp_telnet.h +++ b/src/hasp_telnet.h @@ -7,7 +7,7 @@ #include "ArduinoJson.h" -void telnetSetup(const JsonObject & settings); +void telnetSetup(); void telnetLoop(void); void telnetStop(void); diff --git a/src/hasp_tft.cpp b/src/hasp_tft.cpp index f6a73d8f..32e34ae8 100644 --- a/src/hasp_tft.cpp +++ b/src/hasp_tft.cpp @@ -10,7 +10,7 @@ ADC_MODE(ADC_VCC); // tftShowConfig measures the voltage on the pin int8_t getPinName(int8_t pin); -void tftSetup(TFT_eSPI & tft, const JsonObject & settings) +void tftSetup(TFT_eSPI & tft) { tftShowConfig(tft); } diff --git a/src/hasp_tft.h b/src/hasp_tft.h index b3e5bca2..7b79a3da 100644 --- a/src/hasp_tft.h +++ b/src/hasp_tft.h @@ -2,9 +2,8 @@ #define HASP_TFT_H #include "TFT_eSPI.h" -#include "ArduinoJson.h" -void tftSetup(TFT_eSPI & screen, const JsonObject & settings); +void tftSetup(TFT_eSPI & screen); void tftLoop(void); void tftStop(void); diff --git a/src/hasp_wifi.cpp b/src/hasp_wifi.cpp index 6b2b3586..7df3a4c0 100644 --- a/src/hasp_wifi.cpp +++ b/src/hasp_wifi.cpp @@ -52,7 +52,7 @@ String wifiGetMacAddress(int start, const char * seperator) byte mac[6]; WiFi.macAddress(mac); String cMac((char *)0); - cMac.reserve(128); + cMac.reserve(32); for(int i = start; i < 6; ++i) { if(mac[i] < 0x10) cMac += "0"; @@ -131,12 +131,10 @@ void wifiSTADisconnected(WiFiEventStationModeDisconnected info) } #endif -void wifiSetup(JsonObject settings) +void wifiSetup() { char buffer[128]; - // wifiSetConfig(settings); - if(strlen(wifiSsid) == 0) { String apSsdid = F("HASP-"); apSsdid += wifiGetMacAddress(3, ""); @@ -176,9 +174,7 @@ void wifiSetup(JsonObject settings) bool wifiEvery5Seconds() { - if(WiFi.getMode() == WIFI_AP) return true; - - if(WiFi.status() == WL_CONNECTED) { + if(WiFi.getMode() == WIFI_AP || WiFi.status() == WL_CONNECTED) { return true; } else { wifiReconnectCounter++; diff --git a/src/hasp_wifi.h b/src/hasp_wifi.h index d09f9a59..1898caa7 100644 --- a/src/hasp_wifi.h +++ b/src/hasp_wifi.h @@ -3,7 +3,7 @@ #include "ArduinoJson.h" -void wifiSetup(JsonObject settings); +void wifiSetup(); bool wifiEvery5Seconds(void); void wifiStop(void); diff --git a/src/main.cpp b/src/main.cpp index a590e3fb..a0bba760 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,5 @@ #include "hasp_conf.h" // load first #include -#include "ArduinoJson.h" #include "hasp_debug.h" #include "hasp_spiffs.h" @@ -76,48 +75,41 @@ void setup() /**************************** * Read & Apply User Configuration ***************************/ - DynamicJsonDocument settings(128); - configSetup(settings[F("debug")]); + configSetup(); /**************************** * Apply User Configuration ***************************/ - debugSetup(settings[F("debug")]); - gpioSetup(settings[F("gpio")]); - - /* Init Graphics */ - // TFT_eSPI screen = TFT_eSPI(); - guiSetup(settings[F("gui")]); + debugSetup(); + gpioSetup(); + guiSetup(); #if HASP_USE_WIFI - wifiSetup(settings[F("wifi")]); + wifiSetup(); #endif + haspSetup(); - /* Init GUI Application */ - haspSetup(settings[F("hasp")]); - - /* Init Network Services */ #if HASP_USE_WIFI - wifiSetup(settings[F("wifi")]); + wifiSetup(); #if HASP_USE_HTTP - httpSetup(settings[F("http")]); + httpSetup(); #endif #if HASP_USE_MQTT - mqttSetup(settings[F("mqtt")]); + mqttSetup(); #endif #if HASP_USE_TELNET - telnetSetup(settings[F("telnet")]); + telnetSetup(); #endif #if HASP_USE_MDNS - mdnsSetup(settings[F("mdns")]); + mdnsSetup(); #endif #if HASP_USE_OTA - otaSetup(settings[F("ota")]); + otaSetup(); #endif #endif // WIFI