diff --git a/Makefile b/Makefile index c935555..3d4c186 100644 --- a/Makefile +++ b/Makefile @@ -29,11 +29,71 @@ ESPTOOL ?= $(abspath ../esp-open-sdk/esptool/esptool.py) ESPPORT ?= /dev/ttyUSB0 ESPBAUD ?= 460800 +# Build time Wifi Cfg +# STA_SSID ?= +# STA_PASS ?= + +# hostname or IP address for wifi flashing +ESP_HOSTNAME ?= esp-link + # --------------- chipset configuration --------------- # Pick your flash size: "512KB", "1MB", or "4MB" FLASH_SIZE ?= 4MB +# The pin assignments below are used when the settings in flash are invalid, they +# can be changed via the web interface +# GPIO pin used to reset attached microcontroller, acative low +MCU_RESET_PIN ?= 12 +# GPIO pin used with reset to reprogram MCU (ISP=in-system-programming, unused with AVRs), active low +MCU_ISP_PIN ?= 13 +# GPIO pin used for "connectivity" LED, active low +LED_CONN_PIN ?= 0 +# GPIO pin used for "serial activity" LED, active low +LED_SERIAL_PIN ?= 14 + +# --------------- esp-link config options --------------- + +# If CHANGE_TO_STA is set to "yes" the esp-link module will switch to station mode +# once successfully connected to an access point. Else it will stay in AP+STA mode. + +CHANGE_TO_STA ?= yes + +# --------------- esphttpd config options --------------- + +# If GZIP_COMPRESSION is set to "yes" then the static css, js, and html files will be compressed +# with gzip before added to the espfs image and will be served with gzip Content-Encoding header. +# This could speed up the downloading of these files, but might break compatibility with older +# web browsers not supporting gzip encoding because Accept-Encoding is simply ignored. +# Enable this option if you have large static files to serve (for e.g. JQuery, Twitter bootstrap) +# If you have text based static files with different extensions what you want to serve compressed +# then you will need to add the extension to the following places: +# - Add the extension to this Makefile at the webpages.espfs target to the find command +# - Add the extension to the gzippedFileTypes array in the user/httpd.c file +# +# Adding JPG or PNG files (and any other compressed formats) is not recommended, because GZIP +# compression does not work effectively on compressed files. + +#Static gzipping is disabled by default. +GZIP_COMPRESSION ?= yes + +# If COMPRESS_W_HTMLCOMPRESSOR is set to "yes" then the static css and js files will be compressed with +# htmlcompressor and yui-compressor. This option works only when GZIP_COMPRESSION is set to "yes". +# https://code.google.com/p/htmlcompressor/#For_Non-Java_Projects +# http://yui.github.io/yuicompressor/ +# enabled by default. +COMPRESS_W_HTMLCOMPRESSOR ?= yes +HTML-COMPRESSOR ?= htmlcompressor-1.5.3.jar +YUI-COMPRESSOR ?= yuicompressor-2.4.8.jar + +# Optional Modules +MODULES ?= mqtt rest + +# -------------- End of config options ------------- + +HTML_PATH = $(abspath ./html)/ +WIFI_PATH = $(HTML_PATH)wifi/ + ifeq ("$(FLASH_SIZE)","512KB") # Winbond 25Q40 512KB flash, typ for esp-01 thru esp-11 ESP_SPI_SIZE ?= 0 # 0->512KB (256KB+256KB) @@ -83,20 +143,6 @@ ET_FF ?= 80m # 80Mhz flash speed in esptool flash command ET_BLANK ?= 0x3FE000 # where to flash blank.bin to erase wireless settings endif -# hostname or IP address for wifi flashing -ESP_HOSTNAME ?= esp-link - -# The pin assignments below are used when the settings in flash are invalid, they -# can be changed via the web interface -# GPIO pin used to reset attached microcontroller, acative low -MCU_RESET_PIN ?= 12 -# GPIO pin used with reset to reprogram MCU (ISP=in-system-programming, unused with AVRs), active low -MCU_ISP_PIN ?= 13 -# GPIO pin used for "connectivity" LED, active low -LED_CONN_PIN ?= 0 -# GPIO pin used for "serial activity" LED, active low -LED_SERIAL_PIN ?= 14 - # --------------- esp-link version --------------- # This queries git to produce a version string like "esp-link v0.9.0 2015-06-01 34bc76" @@ -111,48 +157,6 @@ SHA := $(shell if git diff --quiet HEAD; then git rev-parse --short HEAD | c else echo "development"; fi) VERSION ?=esp-link $(BRANCH) - $(DATE) - $(SHA) -# --------------- esp-link config options --------------- - -# If CHANGE_TO_STA is set to "yes" the esp-link module will switch to station mode -# once successfully connected to an access point. Else it will stay in AP+STA mode. - -CHANGE_TO_STA ?= yes - -# --------------- esphttpd config options --------------- - -# If GZIP_COMPRESSION is set to "yes" then the static css, js, and html files will be compressed -# with gzip before added to the espfs image and will be served with gzip Content-Encoding header. -# This could speed up the downloading of these files, but might break compatibility with older -# web browsers not supporting gzip encoding because Accept-Encoding is simply ignored. -# Enable this option if you have large static files to serve (for e.g. JQuery, Twitter bootstrap) -# If you have text based static files with different extensions what you want to serve compressed -# then you will need to add the extension to the following places: -# - Add the extension to this Makefile at the webpages.espfs target to the find command -# - Add the extension to the gzippedFileTypes array in the user/httpd.c file -# -# Adding JPG or PNG files (and any other compressed formats) is not recommended, because GZIP -# compression does not work effectively on compressed files. - -#Static gzipping is disabled by default. -GZIP_COMPRESSION ?= yes - -# If COMPRESS_W_HTMLCOMPRESSOR is set to "yes" then the static css and js files will be compressed with -# htmlcompressor and yui-compressor. This option works only when GZIP_COMPRESSION is set to "yes". -# https://code.google.com/p/htmlcompressor/#For_Non-Java_Projects -# http://yui.github.io/yuicompressor/ -# enabled by default. -COMPRESS_W_HTMLCOMPRESSOR ?= yes -HTML-COMPRESSOR ?= htmlcompressor-1.5.3.jar -YUI-COMPRESSOR ?= yuicompressor-2.4.8.jar - -HTML_PATH = $(abspath ./html)/ -WIFI_PATH = $(HTML_PATH)wifi/ - -# Optional Modules -MODULES ?= mqtt rest - -# -------------- End of config options ------------- - # Output directors to store intermediate compiled files # relative to the project directory BUILD_BASE = build @@ -244,6 +248,14 @@ Q := @ vecho := @echo endif +ifneq ($(strip $(STA_SSID)),) +CFLAGS += -DSTA_SSID="$(STA_SSID)" +endif + +ifneq ($(strip $(STA_PASS)),) +CFLAGS += -DSTA_PASS="$(STA_PASS)" +endif + ifeq ("$(GZIP_COMPRESSION)","yes") CFLAGS += -DGZIP_COMPRESSION endif @@ -364,6 +376,10 @@ ifeq ("$(COMPRESS_W_HTMLCOMPRESSOR)","yes") $(Q) for file in `find html_compressed -type f -name "*.css"`; do \ java -jar tools/$(YUI-COMPRESSOR) $$file -o $$file; \ done +endif +ifeq (,$(findstring mqtt,$(MODULES))) + $(Q) rm -rf html_compressed/mqtt.html + $(Q) rm -rf html_compressed/mqtt.js endif $(Q) for file in `find html_compressed -type f -name "*.htm*"`; do \ cat html_compressed/head- $$file >$${file}-; \ diff --git a/esp-link.vcxproj b/esp-link.vcxproj index 5682d27..57e3a8d 100644 --- a/esp-link.vcxproj +++ b/esp-link.vcxproj @@ -10,66 +10,20 @@ ARM - - {A92F0CAA-F89B-4F78-AD2A-A042429BD87F} - MakeFileProj - - - - Makefile - - - - - - - - - - - __ets__;_STDINT_H;ICACHE_FLASH;__MINGW32__;__WIN32__ - .\rest;.\esp-link;.\mqtt;.\cmd;.\serial;.\user;.\espfs;.\httpd;.\include;..\esp_iot_sdk_v1.3.0\include;..\xtensa-lx106-elf\xtensa-lx106-elf\include;c:\tools\mingw64\x86_64-w64-mingw32\include;c:\tools\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.3\include - - - - - - - bin - build - - - espmake all wiflash - espmake clean all - espmake clean - - - espmake clean all wiflash - espmake clean all - espmake clean - - - - - - - - - - - - - - - + + + + + + + + - - - + @@ -78,44 +32,31 @@ - + - - - + + - - - - - - - - - - - - - - - - - + + - - - - + + + + + + + @@ -127,34 +68,89 @@ - + - - - + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {A92F0CAA-F89B-4F78-AD2A-A042429BD87F} + MakeFileProj + + + + Makefile + + + + + + + + + + + __ets__;_STDINT_H;ICACHE_FLASH;__MINGW32__;__WIN32__ + .\rest;.\esp-link;.\mqtt;.\cmd;.\serial;.\user;.\espfs;.\httpd;.\include;..\esp_iot_sdk_v1.3.0\include;..\xtensa-lx106-elf\xtensa-lx106-elf\include;c:\tools\mingw64\x86_64-w64-mingw32\include;c:\tools\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.3\include + + + + + + + bin + build + + + espmake all wiflash + espmake clean all + espmake clean + + + espmake clean all wiflash + espmake clean all + espmake clean + + + + + + diff --git a/esp-link/cgi.c b/esp-link/cgi.c index 5c0584c..0a52538 100644 --- a/esp-link/cgi.c +++ b/esp-link/cgi.c @@ -153,7 +153,9 @@ int ICACHE_FLASH_ATTR cgiMenu(HttpdConnData *connData) { "{\"menu\": [\"Home\", \"/home.html\", " "\"Wifi\", \"/wifi/wifi.html\"," "\"\xC2\xB5" "C Console\", \"/console.html\", " +#ifdef MQTT "\"REST/MQTT\", \"/mqtt.html\"," +#endif "\"Debug log\", \"/log.html\" ],\n" " \"version\": \"%s\" }", esp_link_version); httpdSend(connData, buff, -1); diff --git a/esp-link/cgimqtt.c b/esp-link/cgimqtt.c index e0dd92a..877f976 100644 --- a/esp-link/cgimqtt.c +++ b/esp-link/cgimqtt.c @@ -1,6 +1,5 @@ // Copyright 2015 by Thorsten von Eicken, see LICENSE.txt -// // TCP Client settings - +#ifdef MQTT #include #include "cgi.h" #include "config.h" @@ -175,3 +174,4 @@ int ICACHE_FLASH_ATTR cgiMqtt(HttpdConnData *connData) { return HTTPD_CGI_DONE; } } +#endif // MQTT \ No newline at end of file diff --git a/esp-link/cgimqtt.h b/esp-link/cgimqtt.h index 54a6011..ef58f38 100644 --- a/esp-link/cgimqtt.h +++ b/esp-link/cgimqtt.h @@ -1,8 +1,9 @@ +#ifdef MQTT #ifndef CGIMQTT_H #define CGIMQTT_H #include "httpd.h" - int cgiMqtt(HttpdConnData *connData); -#endif +#endif // CGIMQTT_H +#endif // MQTT diff --git a/esp-link/log.c b/esp-link/log.c index ca8e0ad..1a9a985 100644 --- a/esp-link/log.c +++ b/esp-link/log.c @@ -162,8 +162,9 @@ void ICACHE_FLASH_ATTR dumpMem(void *addr, int len) { int off = 0; while (off < len) { os_printf("%p ", a); - for (int i=0; i<16 && off+i 0x20 && *a < 0x3f ? *a : '.'); diff --git a/esp-link/main.c b/esp-link/main.c index 980fc11..e44d0a1 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -30,8 +30,6 @@ #include "log.h" #include -//#define SHOW_HEAP_USE - /* This is the main url->function dispatching data struct. In short, it's a struct with various URLs plus their handlers. The handlers can @@ -65,7 +63,9 @@ HttpdBuiltInUrl builtInUrls[] = { { "/wifi/special", cgiWiFiSpecial, NULL }, { "/pins", cgiPins, NULL }, { "/tcpclient", cgiTcp, NULL }, +#ifdef MQTT { "/mqtt", cgiMqtt, NULL }, +#endif { "*", cgiEspFsHook, NULL }, //Catch-all cgi function for the filesystem { NULL, NULL, NULL } @@ -79,8 +79,9 @@ static void ICACHE_FLASH_ATTR prHeapTimerCb(void *arg) { } #endif -void user_rf_pre_init(void) { -} +# define VERS_STR_STR(V) #V +# define VERS_STR(V) VERS_STR_STR(V) +char* esp_link_version = VERS_STR(VERSION); // address of espfs binary blob extern uint32_t _binary_espfs_img_start; @@ -93,13 +94,14 @@ static char *flash_maps[] = { "2MB:1024/1024", "4MB:1024/1024" }; -# define VERS_STR_STR(V) #V -# define VERS_STR(V) VERS_STR_STR(V) -char* esp_link_version = VERS_STR(VERSION); - extern void app_init(void); extern void mqtt_client_init(void); +void user_rf_pre_init(void) { + //default is enabled + system_set_os_print(DEBUG_SDK); +} + // Main routine to initialize esp-link. void user_init(void) { // get the flash config so we know how to init things @@ -115,11 +117,33 @@ void user_init(void) { os_delay_us(10000L); os_printf("\n\n** %s\n", esp_link_version); os_printf("Flash config restore %s\n", restoreOk ? "ok" : "*FAILED*"); + +#if defined(STA_SSID) && defined(STA_PASS) + int x = wifi_get_opmode() & 0x3; + + if (x == 2) { + struct station_config stconf; + wifi_station_get_config(&stconf); + + if (os_strlen((char*)stconf.ssid) == 0 && os_strlen((char*)stconf.password) == 0) { + os_strncpy((char*)stconf.ssid, VERS_STR(STA_SSID), 32); + os_strncpy((char*)stconf.password, VERS_STR(STA_PASS), 64); +#ifdef CGIWIFI_DBG + os_printf("Wifi pre-config trying to connect to AP %s pw %s\n", (char*)stconf.ssid, (char*)stconf.password); +#endif + wifi_set_opmode(3); + stconf.bssid_set = 0; + wifi_station_set_config(&stconf); + } + } +#endif + // Status LEDs statusInit(); serledInit(); // Wifi wifiInit(); + // init the flash filesystem with the html stuff espFsInit(&_binary_espfs_img_start); //EspFsInitResult res = espFsInit(&_binary_espfs_img_start); @@ -145,8 +169,9 @@ void user_init(void) { fid & 0xff, (fid&0xff00)|((fid>>16)&0xff)); os_printf("** esp-link ready\n"); - +#ifdef MQTT mqtt_client_init(); +#endif app_init(); } diff --git a/esp-link/mqtt_client.c b/esp-link/mqtt_client.c index 2fea118..cca4254 100644 --- a/esp-link/mqtt_client.c +++ b/esp-link/mqtt_client.c @@ -1,40 +1,145 @@ +#ifdef MQTT #include #include "cgiwifi.h" #include "config.h" #include "mqtt.h" +#ifdef MQTTCLIENT_DBG +#define DBG_MQTTCLIENT(format, ...) os_printf(format, ## __VA_ARGS__) +#else +#define DBG_MQTTCLIENT(format, ...) do { } while(0) +#endif + MQTT_Client mqttClient; +char* statusTopicStr; +static char* onlineMsgStr; -static ETSTimer mqttTimer; +static MqttCallback connected_cb; +static MqttCallback disconnected_cb; +static MqttCallback published_cb; +static MqttDataCallback data_cb; -static int once = 0; -static void ICACHE_FLASH_ATTR -mqttTimerCb(void *arg) -{ - if (once++ > 0) return; - if (flashConfig.mqtt_enable) - MQTT_Connect(&mqttClient); - //MQTT_Subscribe(&mqttClient, "system/time", 0); +void ICACHE_FLASH_ATTR +mqttConnectedCb(uint32_t *args) { + MQTT_Client* client = (MQTT_Client*)args; + DBG_MQTTCLIENT("MQTT Client: Connected\n"); + MQTT_Subscribe(client, "system/time", 0); + MQTT_Publish(client, "announce/all", onlineMsgStr, 0, 0); + if (connected_cb) + connected_cb(args); +} + +void ICACHE_FLASH_ATTR +mqttDisconnectedCb(uint32_t *args) { +// MQTT_Client* client = (MQTT_Client*)args; + DBG_MQTTCLIENT("MQTT Client: Disconnected\n"); + if (disconnected_cb) + disconnected_cb(args); +} + +void ICACHE_FLASH_ATTR +mqttPublishedCb(uint32_t *args) { +// MQTT_Client* client = (MQTT_Client*)args; + DBG_MQTTCLIENT("MQTT Client: Published\n"); + if (published_cb) + published_cb(args); +} + +void ICACHE_FLASH_ATTR +mqttDataCb(uint32_t *args, const char* topic, uint32_t topic_len, const char *data, uint32_t data_len) { + // MQTT_Client* client = (MQTT_Client*)args; + + char *topicBuf = (char*)os_zalloc(topic_len + 1); + char *dataBuf = (char*)os_zalloc(data_len + 1); + + os_memcpy(topicBuf, topic, topic_len); + topicBuf[topic_len] = 0; + + os_memcpy(dataBuf, data, data_len); + dataBuf[data_len] = 0; + + DBG_MQTTCLIENT("MQTT Client: Received topic: %s, data: %s\n", topicBuf, dataBuf); + os_free(topicBuf); + os_free(dataBuf); + + if (data_cb) + data_cb(args, topic, topic_len, data, data_len); } void ICACHE_FLASH_ATTR wifiStateChangeCb(uint8_t status) { - if (status == wifiGotIP) { - os_timer_disarm(&mqttTimer); - os_timer_setfn(&mqttTimer, mqttTimerCb, NULL); - os_timer_arm(&mqttTimer, 200, 0); + if (flashConfig.mqtt_enable) { + if (status == wifiGotIP && mqttClient.connState != TCP_CONNECTING) { + MQTT_Connect(&mqttClient); + } + else if (status == wifiIsDisconnected && mqttClient.connState == TCP_CONNECTING) { + MQTT_Disconnect(&mqttClient); + } } } - -// initialize the custom stuff that goes beyond esp-link void ICACHE_FLASH_ATTR mqtt_client_init() { - MQTT_Init(&mqttClient, flashConfig.mqtt_host, flashConfig.mqtt_port, 0, - flashConfig.mqtt_timeout, flashConfig.mqtt_clientid, - flashConfig.mqtt_username, flashConfig.mqtt_password, + if (flashConfig.mqtt_enable) { + MQTT_Init(&mqttClient, flashConfig.mqtt_host, flashConfig.mqtt_port, 0, flashConfig.mqtt_timeout, + flashConfig.mqtt_clientid, flashConfig.mqtt_username, flashConfig.mqtt_password, flashConfig.mqtt_keepalive); + + if (flashConfig.mqtt_status_enable) { +// removed client_id concat for now until a better solution is devised +// statusTopicStr = (char*)os_zalloc(strlen(flashConfig.mqtt_clientid) + strlen(flashConfig.mqtt_status_topic) + 2); +// os_strcpy(statusTopicStr, flashConfig.mqtt_clientid); +// os_strcat(statusTopicStr, "/"); + + statusTopicStr = (char*)os_zalloc(strlen(flashConfig.mqtt_status_topic) + 1); + os_strcpy(statusTopicStr, flashConfig.mqtt_status_topic); + } + + char* onlineMsg = " is online"; + onlineMsgStr = (char*)os_zalloc(strlen(flashConfig.mqtt_clientid) + strlen(onlineMsg) + 1); + os_strcpy(onlineMsgStr, flashConfig.mqtt_clientid); + os_strcat(onlineMsgStr, onlineMsg); + + char* offlineMsg = " is offline"; + char* offlineMsgStr = (char*)os_zalloc(strlen(flashConfig.mqtt_clientid) + strlen(offlineMsg) + 1); + os_strcpy(offlineMsgStr, flashConfig.mqtt_clientid); + os_strcat(offlineMsgStr, offlineMsg); + + char* lwt = "/lwt"; + char *lwtMsgStr = (char*)os_zalloc(strlen(flashConfig.mqtt_clientid) + strlen(lwt) + 1); + os_strcpy(lwtMsgStr, flashConfig.mqtt_clientid); + os_strcat(lwtMsgStr, lwt); + MQTT_InitLWT(&mqttClient, lwtMsgStr, offlineMsg, 0, 0); + + MQTT_OnConnected(&mqttClient, mqttConnectedCb); + MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); + MQTT_OnPublished(&mqttClient, mqttPublishedCb); + MQTT_OnData(&mqttClient, mqttDataCb); + } + wifiAddStateChangeCb(wifiStateChangeCb); } + +void ICACHE_FLASH_ATTR +mqtt_client_on_connected(MqttCallback connectedCb) { + connected_cb = connectedCb; +} + +void ICACHE_FLASH_ATTR +mqtt_client_on_disconnected(MqttCallback disconnectedCb) { + disconnected_cb = disconnectedCb; +} + +void ICACHE_FLASH_ATTR +mqtt_client_on_published(MqttCallback publishedCb) { + published_cb = publishedCb; +} + +void ICACHE_FLASH_ATTR +mqtt_client_on_data(MqttDataCallback dataCb) { + data_cb = dataCb; +} + +#endif // MQTT diff --git a/esp-link/mqtt_client.h b/esp-link/mqtt_client.h index 9ae07aa..75fc8dc 100644 --- a/esp-link/mqtt_client.h +++ b/esp-link/mqtt_client.h @@ -1,9 +1,15 @@ +#ifdef MQTT #ifndef MQTT_CLIENT_H #define MQTT_CLIENT_H - #include "mqtt.h" extern MQTT_Client mqttClient; +extern char* statusTopicStr; void mqtt_client_init(); +void mqtt_client_on_connected(MqttCallback connectedCb); +void mqtt_client_on_disconnected(MqttCallback disconnectedCb); +void mqtt_client_on_published(MqttCallback publishedCb); +void mqtt_client_on_data(MqttDataCallback dataCb); -#endif +#endif //MQTT_CLIENT_H +#endif // MQTT diff --git a/esp-link/status.c b/esp-link/status.c index ded4ea4..a1ca389 100644 --- a/esp-link/status.c +++ b/esp-link/status.c @@ -4,10 +4,46 @@ #include "config.h" #include "serled.h" #include "cgiwifi.h" -#include "mqtt.h" +#ifdef MQTT +#include "mqtt.h" +#include "mqtt_client.h" extern MQTT_Client mqttClient; +//===== MQTT Status update + +// Every minute... +#define MQTT_STATUS_INTERVAL (60*1000) + +static ETSTimer mqttStatusTimer; + +int ICACHE_FLASH_ATTR +mqttStatusMsg(char *buf) { + sint8 rssi = wifi_station_get_rssi(); + if (rssi > 0) rssi = 0; // not connected or other error + //os_printf("timer rssi=%d\n", rssi); + + // compose MQTT message + return os_sprintf(buf, + "{\"rssi\":%d, \"heap_free\":%ld}", + rssi, (unsigned long)system_get_free_heap_size()); +} + +// Timer callback to send an RSSI update to a monitoring system +static void ICACHE_FLASH_ATTR mqttStatusCb(void *v) { + if (!flashConfig.mqtt_status_enable || os_strlen(flashConfig.mqtt_status_topic) == 0 || + mqttClient.connState != MQTT_CONNECTED) + return; + + char buf[128]; + mqttStatusMsg(buf); + MQTT_Publish(&mqttClient, statusTopicStr, buf, 1, 0); +} + + + +#endif // MQTT + //===== "CONN" LED status indication static ETSTimer ledTimer; @@ -68,38 +104,6 @@ void ICACHE_FLASH_ATTR statusWifiUpdate(uint8_t state) { os_timer_arm(&ledTimer, 500, 0); } -//===== MQTT Status update - -// Every minute... -#define MQTT_STATUS_INTERVAL (60*1000) - -static ETSTimer mqttStatusTimer; - -int ICACHE_FLASH_ATTR -mqttStatusMsg(char *buf) { - sint8 rssi = wifi_station_get_rssi(); - if (rssi > 0) rssi = 0; // not connected or other error - //os_printf("timer rssi=%d\n", rssi); - - // compose MQTT message - return os_sprintf(buf, - "{\"rssi\":%d, \"heap_free\":%ld}", - rssi, (unsigned long)system_get_free_heap_size()); -} - -// Timer callback to send an RSSI update to a monitoring system -static void ICACHE_FLASH_ATTR mqttStatusCb(void *v) { - if (!flashConfig.mqtt_status_enable || os_strlen(flashConfig.mqtt_status_topic) == 0 || - mqttClient.connState != MQTT_CONNECTED) - return; - - char buf[128]; - mqttStatusMsg(buf); - MQTT_Publish(&mqttClient, flashConfig.mqtt_status_topic, buf, 1, 0); - - //espconn_disconnect(mqttClient.pCon); -} - //===== Init status stuff void ICACHE_FLASH_ATTR statusInit(void) { @@ -115,9 +119,11 @@ void ICACHE_FLASH_ATTR statusInit(void) { os_timer_setfn(&ledTimer, ledTimerCb, NULL); os_timer_arm(&ledTimer, 2000, 0); +#ifdef MQTT os_timer_disarm(&mqttStatusTimer); os_timer_setfn(&mqttStatusTimer, mqttStatusCb, NULL); os_timer_arm(&mqttStatusTimer, MQTT_STATUS_INTERVAL, 1); // recurring timer +#endif // MQTT } diff --git a/html/mqtt.html b/html/mqtt.html index 1afbb95..28d763c 100644 --- a/html/mqtt.html +++ b/html/mqtt.html @@ -90,6 +90,7 @@ +