Skip to content

Commit 08459ce

Browse files
committed
Merge pull request #3 from ignaworn/master
Add esp.publish function
2 parents a0ef622 + 522c124 commit 08459ce

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

espduino.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ BOOL ESP::mqttConnect(const char* host, U16 port)
7878
INFO("TCP: Connected");
7979
connState = MQTT_CONNECT_SEND;
8080
}
81+
82+
BOOL ESP::publish(char* topic, char* data, int data_length, int qos, int retain)
83+
{
84+
if(connState != MQTT_DATA)
85+
return false;
86+
INFO("MQTT: sending publish...\r\n");
87+
mqtt_state.outbound_message = mqtt_msg_publish(&mqtt_state.mqtt_connection,
88+
topic, data, data_length,
89+
qos, retain,
90+
&mqtt_state.pending_msg_id);
91+
}
92+
8193
BOOL ESP::subscribe(char* topic)
8294
{
8395
INFO("MQTT: subscribe, topic");

espduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class ESP
6969
BOOL initMqttClient(const char *clientId, const char *user, const char *pass, U32 keepalive);
7070
BOOL wifiConnect(const char* ssid, const char* pass);
7171
BOOL mqttConnect(const char* host, U16 port);
72+
BOOL publish(char* topic, char* data, int data_length, int qos, int retain);
7273
BOOL subscribe(char* topic);
7374
void process();
7475
void enable();

0 commit comments

Comments
 (0)