diff --git a/espduino.cpp b/espduino.cpp index 0b08721..4e471d2 100644 --- a/espduino.cpp +++ b/espduino.cpp @@ -78,6 +78,18 @@ BOOL ESP::mqttConnect(const char* host, U16 port) INFO("TCP: Connected"); connState = MQTT_CONNECT_SEND; } + +BOOL ESP::publish(char* topic, char* data, int data_length, int qos, int retain) +{ + if(connState != MQTT_DATA) + return false; + INFO("MQTT: sending publish...\r\n"); + mqtt_state.outbound_message = mqtt_msg_publish(&mqtt_state.mqtt_connection, + topic, data, data_length, + qos, retain, + &mqtt_state.pending_msg_id); +} + BOOL ESP::subscribe(char* topic) { INFO("MQTT: subscribe, topic"); diff --git a/espduino.h b/espduino.h index 0e1b423..f8560f4 100644 --- a/espduino.h +++ b/espduino.h @@ -69,6 +69,7 @@ class ESP BOOL initMqttClient(const char *clientId, const char *user, const char *pass, U32 keepalive); BOOL wifiConnect(const char* ssid, const char* pass); BOOL mqttConnect(const char* host, U16 port); + BOOL publish(char* topic, char* data, int data_length, int qos, int retain); BOOL subscribe(char* topic); void process(); void enable();