diff --git a/esp-link/cgimqtt.c b/esp-link/cgimqtt.c index cbf4c16..ea46fad 100644 --- a/esp-link/cgimqtt.c +++ b/esp-link/cgimqtt.c @@ -4,18 +4,39 @@ #include #include "cgi.h" #include "config.h" +#include "status.h" +#include "mqtt_client.h" #include "cgimqtt.h" +static char *mqtt_states[] = { + "disconnected", "reconnecting", "connecting", "connected", +}; + // Cgi to return MQTT settings int ICACHE_FLASH_ATTR cgiMqttGet(HttpdConnData *connData) { - char buff[2048]; + char buff[1024]; int len; if (connData->conn==NULL) return HTTPD_CGI_DONE; + // get the current status topic for display + char status_buf1[128], *sb1=status_buf1; + char status_buf2[128], *sb2=status_buf2; + mqttStatusMsg(status_buf1); + // quote all " for the json, sigh... + for (int i=0; i<127 && *sb1; i++) { + if (*sb1 == '"') { + *sb2++ = '\\'; + i++; + } + *sb2++ = *sb1++; + } + *sb2 = 0; + len = os_sprintf(buff, "{ " "\"slip-enable\":%d, " "\"mqtt-enable\":%d, " + "\"mqtt-state\":\"%s\", " "\"mqtt-status-enable\":%d, " "\"mqtt-port\":%d, " "\"mqtt-host\":\"%s\", " @@ -23,11 +44,12 @@ int ICACHE_FLASH_ATTR cgiMqttGet(HttpdConnData *connData) { "\"mqtt-username\":\"%s\", " "\"mqtt-password\":\"%s\", " "\"mqtt-status-topic\":\"%s\", " - "\"mqtt-state\":\"%s\" }", - flashConfig.slip_enable, flashConfig.mqtt_enable, flashConfig.mqtt_status_enable, + "\"mqtt-status-value\":\"%s\" }", + flashConfig.slip_enable, flashConfig.mqtt_enable, + mqtt_states[mqttClient.connState], flashConfig.mqtt_status_enable, flashConfig.mqtt_port, flashConfig.mqtt_hostname, flashConfig.mqtt_client, flashConfig.mqtt_username, flashConfig.mqtt_password, - flashConfig.mqtt_status_topic, "connected"); + flashConfig.mqtt_status_topic, status_buf2); jsonHeader(connData, 200); httpdSend(connData, buff, len); diff --git a/esp-link/mqtt_client.c b/esp-link/mqtt_client.c index 229d996..9d7f331 100644 --- a/esp-link/mqtt_client.c +++ b/esp-link/mqtt_client.c @@ -8,7 +8,9 @@ MQTT_Client mqttClient; static ETSTimer mqttTimer; static int once = 0; -static void ICACHE_FLASH_ATTR mqttTimerCb(void *arg) { +static void ICACHE_FLASH_ATTR +mqttTimerCb(void *arg) +{ if (once++ > 0) return; MQTT_Init(&mqttClient, flashConfig.mqtt_hostname, flashConfig.mqtt_port, 0, 2, flashConfig.mqtt_client, flashConfig.mqtt_username, flashConfig.mqtt_password, 60); @@ -28,7 +30,9 @@ wifiStateChangeCb(uint8_t status) // initialize the custom stuff that goes beyond esp-link -void mqtt_client_init() { +void ICACHE_FLASH_ATTR +mqtt_client_init() +{ wifiAddStateChangeCb(wifiStateChangeCb); } diff --git a/esp-link/status.c b/esp-link/status.c index 2b08b20..1cb4069 100644 --- a/esp-link/status.c +++ b/esp-link/status.c @@ -75,7 +75,7 @@ void ICACHE_FLASH_ATTR statusWifiUpdate(uint8_t state) { static ETSTimer mqttStatusTimer; -static int ICACHE_FLASH_ATTR +int ICACHE_FLASH_ATTR mqttStatusMsg(char *buf) { sint8 rssi = wifi_station_get_rssi(); if (rssi > 0) rssi = 0; // not connected or other error diff --git a/esp-link/status.h b/esp-link/status.h index 0f89edf..c6fb855 100644 --- a/esp-link/status.h +++ b/esp-link/status.h @@ -1,6 +1,7 @@ #ifndef STATUS_H #define STATUS_H +int mqttStatusMsg(char *buf); void statusWifiUpdate(uint8_t state); void statusInit(void); diff --git a/html/home.html b/html/home.html index 46a984d..e7454f9 100644 --- a/html/home.html +++ b/html/home.html @@ -1,87 +1,63 @@
-
JEELABS
+
JEELABS

esp-link

-
-
-
-

The JeeLabs esp-link firmware bridges the ESP8266 serial port to Wifi and can - program microcontrollers over the serial port, in particular Arduinos, AVRs, and - NXP's LPC800 and other ARM processors.

-

Program an Arduino/AVR using avrdude using a command - line similar to:

-
/home/arduino-1.0.5/hardware/tools/avrdude \
-   -DV -patmega328p -Pnet:esp-link.local:23 -carduino -b115200 -U \
-   -C /home/arduino-1.0.5/hardware/tools/avrdude.conf flash:w:my_sketch.hex:i -
-

where -Pnet:esp-link.local:23 tells avrdude to connect to port 23 of esp-link. - You can substitute the IP address of your esp-link for esp-link.local if necessary.

-

Please refer to - the online README - for up-to-date help and to the forthcoming - JeeLabs blog for an intro to the codebase.

-
-
-
-
-
-

Wifi summary

-
- - - - - - - - -
-
-

TCP client

-
- TCP client support in esp-link -
- - -
-
- Grovestreams data push -
- - -
-
- - -
- -
-
-
-
-

Pin assignment

- Select one of the following signal/pin assignments to match your hardware -
-
-
-
-
-
-
+
+
+
+

The JeeLabs esp-link firmware bridges the ESP8266 serial port to Wifi and can + program microcontrollers over the serial port, in particular Arduinos, AVRs, and + NXP's LPC800 and other ARM processors.

+

Program an Arduino/AVR using avrdude using a command + line similar to:

+
/home/arduino-1.0.5/hardware/tools/avrdude \
+   -DV -patmega328p -Pnet:esp-link.local:23 -carduino -b115200 -U \
+   -C /home/arduino-1.0.5/hardware/tools/avrdude.conf flash:w:my_sketch.hex:i +
+

where -Pnet:esp-link.local:23 tells avrdude to connect to port 23 of esp-link. + You can substitute the IP address of your esp-link for esp-link.local if necessary.

+

Please refer to + the online README + for up-to-date help and to the forthcoming + JeeLabs blog for an intro to the codebase.

+
+
+
+
+
+

Wifi summary

+
+ + + + + + + + +
+
+
+

Pin assignment

+ Select one of the following signal/pin assignments to match your hardware +
+
+
+
+
+
+
diff --git a/html/mqtt.html b/html/mqtt.html index 257c137..033dfe8 100644 --- a/html/mqtt.html +++ b/html/mqtt.html @@ -69,9 +69,9 @@
Status reporting settings
- + - Suffixes: rssi, heap-free, ... + Message: