Add compiler flags checks to build offline version

This commit is contained in:
fvanroie 2022-04-20 00:43:12 +02:00
parent 36f5c37888
commit 84d62ecb9e
5 changed files with 60 additions and 25 deletions

View File

@ -56,7 +56,7 @@ uint8_t saved_jsonl_page = 0;
*/ */
void dispatch_state_subtopic(const char* subtopic, const char* payload) void dispatch_state_subtopic(const char* subtopic, const char* payload)
{ {
#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_CLIENT) #if HASP_USE_MQTT == 0 && HASP_USE_TASMOTA_CLIENT == 0
LOG_TRACE(TAG_MSGR, F("%s => %s"), subtopic, payload); LOG_TRACE(TAG_MSGR, F("%s => %s"), subtopic, payload);
#else #else
@ -1413,6 +1413,7 @@ IRAM_ATTR void dispatchLoop()
#if 1 || ARDUINO #if 1 || ARDUINO
void dispatchEverySecond() void dispatchEverySecond()
{ {
#if HASP_USE_MQTT > 0
if(dispatchSecondsToNextTeleperiod > 1) { if(dispatchSecondsToNextTeleperiod > 1) {
dispatchSecondsToNextTeleperiod--; dispatchSecondsToNextTeleperiod--;
} else if(dispatch_setings.teleperiod > 0 && mqttIsConnected()) { } else if(dispatch_setings.teleperiod > 0 && mqttIsConnected()) {
@ -1433,6 +1434,7 @@ void dispatchEverySecond()
dispatch_send_discovery(NULL, NULL, TAG_MSGR); dispatch_send_discovery(NULL, NULL, TAG_MSGR);
dispatchSecondsToNextDiscovery = dispatch_setings.teleperiod; dispatchSecondsToNextDiscovery = dispatch_setings.teleperiod;
} }
#endif
} }
#else #else
#include <chrono> #include <chrono>

View File

@ -78,6 +78,7 @@ void task_every_second_cb(lv_task_t* task)
void task_teleperiod_cb(lv_task_t* task) void task_teleperiod_cb(lv_task_t* task)
{ {
#if HASP_USE_MQTT > 0
if(!mqttIsConnected()) return; if(!mqttIsConnected()) return;
switch(task->repeat_count) { switch(task->repeat_count) {
@ -94,4 +95,5 @@ void task_teleperiod_cb(lv_task_t* task)
// task is about to get deleted // task is about to get deleted
if(task->repeat_count == 1) task->repeat_count = 4; if(task->repeat_count == 1) task->repeat_count = 4;
#endif
} }

View File

@ -126,7 +126,9 @@ IRAM_ATTR void loop()
guiLoop(); guiLoop();
// haspLoop(); // haspLoop();
#if HASP_USE_WIFI > 0 || HASP_USE_EHTERNET > 0
networkLoop(); networkLoop();
#endif
#if HASP_USE_GPIO > 0 #if HASP_USE_GPIO > 0
// gpioLoop(); // gpioLoop();
@ -197,10 +199,12 @@ IRAM_ATTR void loop()
break; break;
case 4: case 4:
#if HASP_USE_WIFI > 0 || HASP_USE_EHTERNET > 0
isConnected = networkEvery5Seconds(); // Check connection isConnected = networkEvery5Seconds(); // Check connection
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
mqttEvery5Seconds(isConnected); mqttEvery5Seconds(isConnected);
#endif
#endif #endif
break; break;
@ -215,11 +219,11 @@ IRAM_ATTR void loop()
} }
} }
// allow the cpu to switch to other tasks
#ifdef ARDUINO_ARCH_ESP8266 #ifdef ARDUINO_ARCH_ESP8266
delay(2); // ms delay(2); // ms
#else #else
delay(3); // ms delay(3); // ms
// delay((lv_task_get_idle() >> 5) + 3); // 2..5 ms
#endif #endif
} }

View File

@ -71,10 +71,11 @@ int mqttPublish(const char* topic, const char* payload, size_t len, bool retain)
return MQTT_ERR_NO_CONN; return MQTT_ERR_NO_CONN;
} }
// Write directly to the client, don't use the buffer
if(mqttClient.beginPublish(topic, len, retain)) { if(mqttClient.beginPublish(topic, len, retain)) {
mqttPublishCount++;
mqttClient.write((uint8_t*)payload, len); mqttClient.write((uint8_t*)payload, len);
mqttClient.endPublish(); mqttClient.endPublish();
mqttPublishCount++;
return MQTT_ERR_OK; return MQTT_ERR_OK;
} }

View File

@ -505,8 +505,10 @@ static void webHandleApi()
add_json(jsondata, doc); add_json(jsondata, doc);
#endif #endif
#if HASP_USE_WIFI > 0 || HASP_USE_EHTERNET > 0
network_get_info(doc); network_get_info(doc);
add_json(jsondata, doc); add_json(jsondata, doc);
#endif
haspDevice.get_info(doc); haspDevice.get_info(doc);
add_json(jsondata, doc); add_json(jsondata, doc);
@ -556,42 +558,62 @@ static void webHandleApiConfig()
if(webServer.method() == HTTP_POST || webServer.method() == HTTP_PUT) { if(webServer.method() == HTTP_POST || webServer.method() == HTTP_PUT) {
configOutput(settings, TAG_HTTP); // Log input JSON config configOutput(settings, TAG_HTTP); // Log input JSON config
if(!strcasecmp_P(endpoint_key, PSTR("wifi"))) { if(!strcasecmp_P(endpoint_key, PSTR("hasp"))) {
wifiSetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("mqtt"))) {
mqttSetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("hasp"))) {
haspSetConfig(settings); haspSetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("http"))) {
httpSetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("gui"))) { } else if(!strcasecmp_P(endpoint_key, PSTR("gui"))) {
guiSetConfig(settings); guiSetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("debug"))) { } else if(!strcasecmp_P(endpoint_key, PSTR("debug"))) {
debugSetConfig(settings); debugSetConfig(settings);
} else
#if HASP_USE_WIFI > 0
if(!strcasecmp_P(endpoint_key, PSTR("wifi"))) {
wifiSetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("time"))) { } else if(!strcasecmp_P(endpoint_key, PSTR("time"))) {
timeSetConfig(settings); timeSetConfig(settings);
} else { } else
#endif
#if HASP_USE_MQTT > 0
if(!strcasecmp_P(endpoint_key, PSTR("mqtt"))) {
mqttSetConfig(settings);
} else
#endif
#if HASP_USE_HTTP > 0
if(!strcasecmp_P(endpoint_key, PSTR("http"))) {
httpSetConfig(settings);
} else
#endif
{
LOG_WARNING(TAG_HTTP, F("Invalid module %s"), endpoint_key); LOG_WARNING(TAG_HTTP, F("Invalid module %s"), endpoint_key);
return; return;
} }
} }
settings = doc.to<JsonObject>(); settings = doc.to<JsonObject>();
if(!strcasecmp_P(endpoint_key, PSTR("wifi"))) { if(!strcasecmp_P(endpoint_key, PSTR("hasp"))) {
wifiGetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("mqtt"))) {
mqttGetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("hasp"))) {
haspGetConfig(settings); haspGetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("http"))) {
httpGetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("gui"))) { } else if(!strcasecmp_P(endpoint_key, PSTR("gui"))) {
guiGetConfig(settings); guiGetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("debug"))) { } else if(!strcasecmp_P(endpoint_key, PSTR("debug"))) {
debugGetConfig(settings); debugGetConfig(settings);
} else
#if HASP_USE_WIFI > 0
if(!strcasecmp_P(endpoint_key, PSTR("wifi"))) {
wifiGetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("time"))) { } else if(!strcasecmp_P(endpoint_key, PSTR("time"))) {
timeGetConfig(settings); timeGetConfig(settings);
} else { } else
#endif
#if HASP_USE_MQTT > 0
if(!strcasecmp_P(endpoint_key, PSTR("mqtt"))) {
mqttGetConfig(settings);
} else
#endif
#if HASP_USE_HTTP > 0
if(!strcasecmp_P(endpoint_key, PSTR("http"))) {
httpGetConfig(settings);
} else
#endif
{
webServer.send(400, contentType, "Bad Request"); webServer.send(400, contentType, "Bad Request");
return; return;
} }
@ -2152,11 +2174,12 @@ static void httpHandleResetConfig()
} else { } else {
// Form // Form
httpMessage += F("<form method='POST' action='/resetConfig'>"); httpMessage += F("<form method='POST' action='/resetConfig'>");
httpMessage += F( httpMessage +=
"<div class=\"warning\"><b>Warning</b><p>This process will reset all settings to the " F("<div class=\"warning\"><b>Warning</b><p>This process will reset all settings to the "
"default values. The internal flash will be erased and the device is restarted. You may need to " "default values. The internal flash will be erased and the device is restarted. You may need to "
"connect to the WiFi AP displayed on the panel to reconfigure the device before accessing it again.</p>" "connect to the WiFi AP displayed on the panel to reconfigure the device before accessing it "
"<p>ALL FILES WILL BE LOST!</p></div>"); "again.</p>"
"<p>ALL FILES WILL BE LOST!</p></div>");
httpMessage += F("<p><button class='red' type='submit' name='confirm' value='yes'>" D_HTTP_ERASE_DEVICE httpMessage += F("<p><button class='red' type='submit' name='confirm' value='yes'>" D_HTTP_ERASE_DEVICE
"</button></p></form>"); "</button></p></form>");
@ -2190,7 +2213,8 @@ void httpStart()
LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%s"), LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%s"),
(WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str())); (WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str()));
#endif #endif
#else #endif
#if HASP_USE_ETHERNET > 0
IPAddress ip; IPAddress ip;
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
ip = ETH.localIP(); ip = ETH.localIP();
@ -2252,8 +2276,10 @@ static inline void webStartConfigPortal()
dnsServer.start(DNS_PORT, "*", apIP); dnsServer.start(DNS_PORT, "*", apIP);
#endif // HASP_USE_CAPTIVE_PORTAL #endif // HASP_USE_CAPTIVE_PORTAL
#if HASP_USE_WIFI > 0
// replay to all requests with same HTML // replay to all requests with same HTML
webServer.onNotFound([]() { webHandleWifiConfig(); }); webServer.onNotFound([]() { webHandleWifiConfig(); });
#endif
webServer.on(F("/style.css"), httpHandleFileFromFlash); webServer.on(F("/style.css"), httpHandleFileFromFlash);
webServer.on(F("/script.js"), httpHandleFileFromFlash); webServer.on(F("/script.js"), httpHandleFileFromFlash);