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)
{
#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);
#else
@ -1413,6 +1413,7 @@ IRAM_ATTR void dispatchLoop()
#if 1 || ARDUINO
void dispatchEverySecond()
{
#if HASP_USE_MQTT > 0
if(dispatchSecondsToNextTeleperiod > 1) {
dispatchSecondsToNextTeleperiod--;
} else if(dispatch_setings.teleperiod > 0 && mqttIsConnected()) {
@ -1433,6 +1434,7 @@ void dispatchEverySecond()
dispatch_send_discovery(NULL, NULL, TAG_MSGR);
dispatchSecondsToNextDiscovery = dispatch_setings.teleperiod;
}
#endif
}
#else
#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)
{
#if HASP_USE_MQTT > 0
if(!mqttIsConnected()) return;
switch(task->repeat_count) {
@ -94,4 +95,5 @@ void task_teleperiod_cb(lv_task_t* task)
// task is about to get deleted
if(task->repeat_count == 1) task->repeat_count = 4;
#endif
}

View File

@ -126,7 +126,9 @@ IRAM_ATTR void loop()
guiLoop();
// haspLoop();
#if HASP_USE_WIFI > 0 || HASP_USE_EHTERNET > 0
networkLoop();
#endif
#if HASP_USE_GPIO > 0
// gpioLoop();
@ -197,10 +199,12 @@ IRAM_ATTR void loop()
break;
case 4:
#if HASP_USE_WIFI > 0 || HASP_USE_EHTERNET > 0
isConnected = networkEvery5Seconds(); // Check connection
#if HASP_USE_MQTT > 0
mqttEvery5Seconds(isConnected);
#endif
#endif
break;
@ -215,11 +219,11 @@ IRAM_ATTR void loop()
}
}
// allow the cpu to switch to other tasks
#ifdef ARDUINO_ARCH_ESP8266
delay(2); // ms
#else
delay(3); // ms
// delay((lv_task_get_idle() >> 5) + 3); // 2..5 ms
#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;
}
// Write directly to the client, don't use the buffer
if(mqttClient.beginPublish(topic, len, retain)) {
mqttPublishCount++;
mqttClient.write((uint8_t*)payload, len);
mqttClient.endPublish();
mqttPublishCount++;
return MQTT_ERR_OK;
}

View File

@ -505,8 +505,10 @@ static void webHandleApi()
add_json(jsondata, doc);
#endif
#if HASP_USE_WIFI > 0 || HASP_USE_EHTERNET > 0
network_get_info(doc);
add_json(jsondata, doc);
#endif
haspDevice.get_info(doc);
add_json(jsondata, doc);
@ -556,42 +558,62 @@ static void webHandleApiConfig()
if(webServer.method() == HTTP_POST || webServer.method() == HTTP_PUT) {
configOutput(settings, TAG_HTTP); // Log input JSON config
if(!strcasecmp_P(endpoint_key, PSTR("wifi"))) {
wifiSetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("mqtt"))) {
mqttSetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("hasp"))) {
if(!strcasecmp_P(endpoint_key, PSTR("hasp"))) {
haspSetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("http"))) {
httpSetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("gui"))) {
guiSetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("debug"))) {
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"))) {
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);
return;
}
}
settings = doc.to<JsonObject>();
if(!strcasecmp_P(endpoint_key, PSTR("wifi"))) {
wifiGetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("mqtt"))) {
mqttGetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("hasp"))) {
if(!strcasecmp_P(endpoint_key, PSTR("hasp"))) {
haspGetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("http"))) {
httpGetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("gui"))) {
guiGetConfig(settings);
} else if(!strcasecmp_P(endpoint_key, PSTR("debug"))) {
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"))) {
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");
return;
}
@ -2152,11 +2174,12 @@ static void httpHandleResetConfig()
} else {
// Form
httpMessage += F("<form method='POST' action='/resetConfig'>");
httpMessage += 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 "
"connect to the WiFi AP displayed on the panel to reconfigure the device before accessing it again.</p>"
"<p>ALL FILES WILL BE LOST!</p></div>");
httpMessage +=
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 "
"connect to the WiFi AP displayed on the panel to reconfigure the device before accessing it "
"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
"</button></p></form>");
@ -2190,7 +2213,8 @@ void httpStart()
LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%s"),
(WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str()));
#endif
#else
#endif
#if HASP_USE_ETHERNET > 0
IPAddress ip;
#if defined(ARDUINO_ARCH_ESP32)
ip = ETH.localIP();
@ -2252,8 +2276,10 @@ static inline void webStartConfigPortal()
dnsServer.start(DNS_PORT, "*", apIP);
#endif // HASP_USE_CAPTIVE_PORTAL
#if HASP_USE_WIFI > 0
// replay to all requests with same HTML
webServer.onNotFound([]() { webHandleWifiConfig(); });
#endif
webServer.on(F("/style.css"), httpHandleFileFromFlash);
webServer.on(F("/script.js"), httpHandleFileFromFlash);