Skip to content

Commit

Permalink
MQTT events
Browse files Browse the repository at this point in the history
  • Loading branch information
omersiar committed Mar 30, 2018
1 parent 53f4dc6 commit dd129db
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
Binary file modified bin/firmware.bin
Binary file not shown.
32 changes: 28 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,16 +856,40 @@ void ICACHE_FLASH_ATTR onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient *
}

void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
char * rch;
sprintf(rch, "Reason : %d", reason);
writeEvent("WARN", "mqtt", "Disconnected from MQTT server", rch);
String reasonstr = "";
switch (reason) {
case (AsyncMqttClientDisconnectReason::TCP_DISCONNECTED):
reasonstr = "TCP_DISCONNECTED";
break;
case (AsyncMqttClientDisconnectReason::MQTT_UNACCEPTABLE_PROTOCOL_VERSION):
reasonstr = "MQTT_UNACCEPTABLE_PROTOCOL_VERSION";
break;
case (AsyncMqttClientDisconnectReason::MQTT_IDENTIFIER_REJECTED):
reasonstr = "MQTT_IDENTIFIER_REJECTED";
break;
case (AsyncMqttClientDisconnectReason::MQTT_SERVER_UNAVAILABLE):
reasonstr = "MQTT_SERVER_UNAVAILABLE";
break;
case (AsyncMqttClientDisconnectReason::MQTT_MALFORMED_CREDENTIALS):
reasonstr = "MQTT_MALFORMED_CREDENTIALS";
break;
case (AsyncMqttClientDisconnectReason::MQTT_NOT_AUTHORIZED):
reasonstr = "MQTT_NOT_AUTHORIZED";
break;
case (AsyncMqttClientDisconnectReason::ESP8266_NOT_ENOUGH_SPACE):
reasonstr = "ESP8266_NOT_ENOUGH_SPACE";
break;
default:
reasonstr = "Unknown";
break;
}
writeEvent("WARN", "mqtt", "Disconnected from MQTT server", reasonstr);
if (WiFi.isConnected()) {
mqttReconnectTimer.once(2, connectToMqtt);
}
}

void onMqttPublish(uint16_t packetId) {

writeEvent("INFO", "mqtt", "MQTT publish acknowledged", String(packetId));
}

Expand Down
Loading

0 comments on commit dd129db

Please sign in to comment.