diff --git a/src/Afterburner.cpp b/src/Afterburner.cpp index 0eda133..aaa136a 100644 --- a/src/Afterburner.cpp +++ b/src/Afterburner.cpp @@ -85,7 +85,7 @@ This example code is in the public domain. */ -//#include "src/WiFi/ABMqtt.h" +#include "WiFi/ABMqtt.h" #include "cfg/BTCConfig.h" #include "cfg/pins.h" #include "RTC/Timers.h" @@ -410,6 +410,9 @@ void setup() { #if USE_WEBSERVER == 1 initWebServer(); #endif // USE_WEBSERVER +#if USE_MQTT == 1 + MqttSetup(); +#endif // USE_MQTT } #endif // USE_WIFI @@ -1621,6 +1624,10 @@ void doStreaming() #if USE_WEBSERVER == 1 bHaveWebClient = doWebServer(); #endif //USE_WEBSERVER +#if USE_MQTT == 1 + doMQTT(); +#endif + #endif // USE_WIFI diff --git a/src/OLED/GPIOInfoScreen.cpp b/src/OLED/GPIOInfoScreen.cpp index 891c526..2bd45dc 100644 --- a/src/OLED/GPIOInfoScreen.cpp +++ b/src/OLED/GPIOInfoScreen.cpp @@ -81,6 +81,9 @@ CGPIOInfoScreen::animate() _drawBitmap(23, 14, StartIconInfo); _drawBitmap(30, 14, StopIconInfo); break; + case CGPIOin1::Stop: + _drawBitmap(23, 14, StopIconInfo); + break; } _drawBitmap(40, 16, GPIOin.getState(0) ? CloseIconInfo : OpenIconInfo); diff --git a/src/OLED/GPIOSetupScreen.cpp b/src/OLED/GPIOSetupScreen.cpp index fb95d97..a037e00 100644 --- a/src/OLED/GPIOSetupScreen.cpp +++ b/src/OLED/GPIOSetupScreen.cpp @@ -216,6 +216,7 @@ CGPIOSetupScreen::animate() case CGPIOin1::Start: pMsg = " Input 1: Starts heater upon closure. "; break; case CGPIOin1::Run: pMsg = " Input 1: Starts heater when held closed, stops when opened. "; break; case CGPIOin1::StartStop: pMsg = " Input 1: Starts or Stops heater upon closure. "; break; + case CGPIOin1::Stop: pMsg = " Input 1: Stops heater upon closure. "; break; } if(pMsg) _scrollMessage(56, pMsg, _scrollChar); diff --git a/src/WiFi/ABMqtt.cpp b/src/WiFi/ABMqtt.cpp index 68d312e..59ff3fa 100644 --- a/src/WiFi/ABMqtt.cpp +++ b/src/WiFi/ABMqtt.cpp @@ -2,32 +2,76 @@ // // -#ifdef USEMQTT +#include "../cfg/BTCConfig.h" + +#ifdef USE_MQTT #include #include "ABMqtt.h" #include "../../lib/PubSubClient/src/PubSubClient.h" #include "BTCWifi.h" #include "BTCWebServer.h" +#include "../Utility/DebugPort.h" +// Update these with values suitable for your network. +byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; +IPAddress ip(172, 16, 0, 100); +IPAddress MQTTserver(5, 196, 95, 208); void MqttCallback(char* topic, byte* payload, unsigned int length) { + DebugPort.printf("MQTT callback %s ", topic); + for(int i=0; i 0) + HoldOff = 0; + } + + if(HoldOff == 0 && !MQTTclient.connected()) { + DebugPort.println("Attempting MQTT connection"); + if (MQTTclient.connect("afterburnerClient")) { + DebugPort.println("MQTT connected"); + // Once connected, publish an announcement... + MQTTclient.publish("Afterburner/test", "hello world"); + // ... and resubscribe +// MQTTclient.subscribe("inTopic"); +// MQTTclient.subscribe("Test/Test/Test/Test"); + MQTTclient.subscribe("Afterburner"); + MQTTclient.publish("Afterburner/test", "the end is nigh"); + } + else { + DebugPort.printf("MQTT connect failed, rc = %d, try again in 5 seconds\r\n", MQTTclient.state()); + HoldOff = millis() + 5000; + } + } + return MQTTclient.connected(); +} + +void doMQTT() +{ + if(reconnect()) + MQTTclient.loop(); +} + #endif \ No newline at end of file diff --git a/src/WiFi/ABmqtt.h b/src/WiFi/ABmqtt.h index f6abf1d..8b6d6fc 100644 --- a/src/WiFi/ABmqtt.h +++ b/src/WiFi/ABmqtt.h @@ -4,13 +4,14 @@ #define _ABMQTT_h -// #include "../../lib/PubSubClient/src/PubSubClient.h" -// #include "BTCWifi.h"" -// #include "BTCWebServer.h" +//#include "../../lib/PubSubClient/src/PubSubClient.h" +#include "BTCWifi.h" +#include "BTCWebServer.h" void MqttCallback(char* topic, byte* payload, unsigned int length); void MqttSetup(); +void doMQTT(); #endif diff --git a/src/cfg/BTCConfig.h b/src/cfg/BTCConfig.h index 8469dde..ca1f248 100644 --- a/src/cfg/BTCConfig.h +++ b/src/cfg/BTCConfig.h @@ -42,6 +42,7 @@ #define USE_WIFI 1 #define USE_OTA 1 #define USE_WEBSERVER 1 +#define USE_MQTT 1 #define USE_PORTAL_TRIGGER_PIN 0