From 1bbd52a234462a49a3ad4db40428d8f6ec223663 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Fri, 8 Apr 2016 01:03:57 +0200 Subject: [PATCH] Add MQTT generic publisher function --- WifiControlSensor/MQTT.ino | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/WifiControlSensor/MQTT.ino b/WifiControlSensor/MQTT.ino index 5605054..a00998b 100644 --- a/WifiControlSensor/MQTT.ino +++ b/WifiControlSensor/MQTT.ino @@ -1,3 +1,4 @@ +#include // Create an ESP8266 WiFiClient class to connect to the MQTT server. WiFiClient client; Adafruit_MQTT_Client *mqtt; @@ -62,6 +63,16 @@ int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname) return 0; } +Adafruit_MQTT_Publish *MqttCreatePublisher(const char *fmt, ...){ + char buf[128]; + va_list args; + va_start (args, fmt); + vsnprintf(buf, sizeof(buf), (const char *)fmt, args); + va_end(args); + String *url = new String(buf); + return new Adafruit_MQTT_Publish(mqtt, url->c_str()); +} + bool MqttIsConfigured() { return isMqttConfigured; }