block MQTT during avrflash, fixes #179

pull/236/head
Thorsten von Eicken 8 years ago
parent 23e0e35ca4
commit 8fbb639b72
No known key found for this signature in database
GPG Key ID: C7F972A59D834B46
  1. 3
      esp-link/cgioptiboot.c
  2. 11
      mqtt/mqtt_cmd.c
  3. 3
      mqtt/mqtt_cmd.h

@ -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();

@ -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);

@ -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_ */

Loading…
Cancel
Save