First take on MQTT integration.
This commit is contained in:
Tobias Blum
2017-08-06 00:52:25 +02:00
parent 5f7733ebd3
commit b699cf75a2
3 changed files with 250 additions and 82 deletions
+24
View File
@@ -23,6 +23,14 @@
#include <ArduinoOTA.h>
#endif
// MQTT
#ifdef ENABLE_MQTT
#include <PubSubClient.h>
WiFiClient espClient;
PubSubClient mqtt_client(espClient);
#endif
// ***************************************************************************
// Instanciate HTTP(80) / WebSockets(81) Server
// ***************************************************************************
@@ -195,6 +203,15 @@ void setup() {
#endif
// ***************************************************************************
// Configure MQTT
// ***************************************************************************
#ifdef ENABLE_MQTT
mqtt_client.setServer(mqtt_server, 1883);
mqtt_client.setCallback(mqtt_callback);
#endif
// ***************************************************************************
// Setup: MDNS responder
// ***************************************************************************
@@ -412,6 +429,13 @@ void loop() {
ArduinoOTA.handle();
#endif
#ifdef ENABLE_MQTT
if (!mqtt_client.connected()) {
mqtt_reconnect();
}
mqtt_client.loop();
#endif
// Simple statemachine that handles the different modes
if (mode == SET_MODE) {
DBG_OUTPUT_PORT.printf("SET_MODE: %d %d\n", ws2812fx_mode, mode);