Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/PubSubClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,18 @@ boolean PubSubClient::publish(const char* topic, const uint8_t* payload, unsigne
return publish(topic, payload, plength, false);
}

boolean PubSubClient::deleteTopic(const char* topic) {
uint8_t buf[64];
if (!connected()) return false;
uint8_t len = strlen(topic);
buf[0]=0x31; //PUBLISH, QoS=0, Retained
buf[1]=len+2; //Packet len = topic + his Length
buf[2]=0;
buf[3]=len; //topic StrLen
strncpy((char*)buf+4,topic,sizeof(buf)-5);
return write( buf,len+4);
}

boolean PubSubClient::publish(const char* topic, const uint8_t* payload, unsigned int plength, boolean retained) {
if (connected()) {
if (this->bufferSize < MQTT_MAX_HEADER_SIZE + 2+strnlen(topic, this->bufferSize) + plength) {
Expand Down
2 changes: 2 additions & 0 deletions src/PubSubClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,13 @@ class PubSubClient : public Print {
boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage, boolean cleanSession);
void disconnect();
boolean publish(const char* topic, const char* payload);
boolean deleteTopic(const char* topic);
boolean publish(const char* topic, const char* payload, boolean retained);
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength);
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
boolean publish_P(const char* topic, const char* payload, boolean retained);
boolean publish_P(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
boolean isRetained() {return this->buffer[0]&0x1;}
// Start to publish a message.
// This API:
// beginPublish(...)
Expand Down