commit
ae44d21503
@ -290,7 +290,6 @@ boolean PubSubClient::write(uint8_t header, uint8_t* buf, uint16_t length) {
|
||||
return (rc == 1+llen+length);
|
||||
}
|
||||
|
||||
|
||||
boolean PubSubClient::subscribe(char* topic) {
|
||||
if (connected()) {
|
||||
// Leave room in the buffer for header and variable length field
|
||||
@ -308,6 +307,21 @@ boolean PubSubClient::subscribe(char* topic) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean PubSubClient::unsubscribe(char* topic) {
|
||||
if (connected()) {
|
||||
uint16_t length = 5;
|
||||
nextMsgId++;
|
||||
if (nextMsgId == 0) {
|
||||
nextMsgId = 1;
|
||||
}
|
||||
buffer[length++] = (nextMsgId >> 8);
|
||||
buffer[length++] = (nextMsgId & 0xFF);
|
||||
length = writeString(topic, buffer,length);
|
||||
return write(MQTTUNSUBSCRIBE|MQTTQOS1,buffer,length-5);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void PubSubClient::disconnect() {
|
||||
buffer[0] = MQTTDISCONNECT;
|
||||
buffer[1] = 0;
|
||||
|
@ -67,6 +67,7 @@ public:
|
||||
boolean publish(char *, uint8_t *, unsigned int, boolean);
|
||||
boolean publish_P(char *, uint8_t PROGMEM *, unsigned int, boolean);
|
||||
boolean subscribe(char *);
|
||||
boolean unsubscribe(char *);
|
||||
boolean loop();
|
||||
boolean connected();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user