diff --git a/esp-link/cgioptiboot.c b/esp-link/cgioptiboot.c index ed87d0e..b75f4de 100644 --- a/esp-link/cgioptiboot.c +++ b/esp-link/cgioptiboot.c @@ -8,6 +8,7 @@ #include "uart.h" #include "stk500.h" #include "serbridge.h" +#include "mqtt_cmd.h" #include "serled.h" #define INIT_DELAY 150 // wait this many millisecs before sending anything @@ -76,6 +77,7 @@ static void ICACHE_FLASH_ATTR optibootInit() { progState = stateInit; baudCnt = 0; uart0_baud(flashConfig.baud_rate); + mqtt_unblock(); ackWait = 0; errMessage[0] = 0; responseLen = 0; @@ -128,6 +130,7 @@ int ICACHE_FLASH_ATTR cgiOptibootSync(HttpdConnData *connData) { } else if (connData->requestType == HTTPD_METHOD_POST) { // issue reset optibootInit(); + mqtt_block(); // prevent MQTT from interfering baudRate = flashConfig.baud_rate; programmingCB = optibootUartRecv; initBaud(); diff --git a/mqtt/mqtt_cmd.c b/mqtt/mqtt_cmd.c index 0f40b79..b6bb909 100644 --- a/mqtt/mqtt_cmd.c +++ b/mqtt/mqtt_cmd.c @@ -13,8 +13,16 @@ #define DBG(format, ...) do { } while(0) #endif +static bool blocked; // flag to prevent MQTT from sending on serial while trying to PGM uC + +void ICACHE_FLASH_ATTR +mqtt_block() { blocked = true; } +void ICACHE_FLASH_ATTR +mqtt_unblock() { blocked = false; } + void ICACHE_FLASH_ATTR cmdMqttConnectedCb(MQTT_Client* client) { + if (blocked) return; MqttCmdCb* cb = (MqttCmdCb*)client->user_data; DBG("MQTT: Connected Cb=%p\n", (void*)cb->connectedCb); cmdResponseStart(CMD_RESP_CB, cb->connectedCb, 0); @@ -23,6 +31,7 @@ cmdMqttConnectedCb(MQTT_Client* client) { void ICACHE_FLASH_ATTR cmdMqttDisconnectedCb(MQTT_Client* client) { + if (blocked) return; MqttCmdCb* cb = (MqttCmdCb*)client->user_data; DBG("MQTT: Disconnected cb=%p\n", (void*)cb->disconnectedCb); cmdResponseStart(CMD_RESP_CB, cb->disconnectedCb, 0); @@ -31,6 +40,7 @@ cmdMqttDisconnectedCb(MQTT_Client* client) { void ICACHE_FLASH_ATTR cmdMqttPublishedCb(MQTT_Client* client) { + if (blocked) return; MqttCmdCb* cb = (MqttCmdCb*)client->user_data; DBG("MQTT: Published cb=%p\n", (void*)cb->publishedCb); cmdResponseStart(CMD_RESP_CB, cb->publishedCb, 0); @@ -41,6 +51,7 @@ void ICACHE_FLASH_ATTR cmdMqttDataCb(MQTT_Client* client, const char* topic, uint32_t topic_len, const char* data, uint32_t data_len) { + if (blocked) return; MqttCmdCb* cb = (MqttCmdCb*)client->user_data; DBG("MQTT: Data cb=%p topic=%s len=%u\n", (void*)cb->dataCb, topic, data_len); diff --git a/mqtt/mqtt_cmd.h b/mqtt/mqtt_cmd.h index 6a14a63..e7121c7 100644 --- a/mqtt/mqtt_cmd.h +++ b/mqtt/mqtt_cmd.h @@ -17,4 +17,7 @@ void MQTTCMD_Publish(CmdPacket *cmd); void MQTTCMD_Subscribe(CmdPacket *cmd); void MQTTCMD_Lwt(CmdPacket *cmd); +void mqtt_block(); +void mqtt_unblock(); + #endif /* MODULES_MQTT_CMD_H_ */