// // // #include "../cfg/BTCConfig.h" #if USE_MQTT == 1 #include #include "ABMqtt.h" #include "../../lib/aysync-mqtt-client/src/AsyncMqttClient.h" #include "BTCWifi.h" #include "BTCWebServer.h" #include "../Utility/DebugPort.h" #include "../Utility/NVStorage.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; return false; } if(MqttSetup()) { if(NVstore.getMQTTinfo().enabled && 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 const sMQTTparams params = NVstore.getMQTTinfo(); char topic[128]; sprintf(topic, "%s/JSONin", params.topic); MQTTclient.subscribe(topic); // 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