Add MQTT generic publisher function

This commit is contained in:
Mathieu Maret 2016-04-08 01:03:57 +02:00
parent 85196a7563
commit 1bbd52a234

View File

@ -1,3 +1,4 @@
#include <stdarg.h>
// Create an ESP8266 WiFiClient class to connect to the MQTT server. // Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client; WiFiClient client;
Adafruit_MQTT_Client *mqtt; Adafruit_MQTT_Client *mqtt;
@ -62,6 +63,16 @@ int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname)
return 0; 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() { bool MqttIsConfigured() {
return isMqttConfigured; return isMqttConfigured;
} }