Added ability to publish retained messages
This commit is contained in:
parent
ef565d8d98
commit
31f3742040
@ -1,3 +1,6 @@
|
||||
1.6
|
||||
* Added the ability to publish a retained message
|
||||
|
||||
1.5
|
||||
* Added default constructor
|
||||
* Fixed compile error when used with arduino-0021 or later
|
||||
|
@ -129,16 +129,22 @@ int PubSubClient::publish(char* topic, char* payload) {
|
||||
return publish(topic,(uint8_t*)payload,strlen(payload));
|
||||
}
|
||||
|
||||
|
||||
int PubSubClient::publish(char* topic, uint8_t* payload, uint8_t plength) {
|
||||
return publish(topic, payload, plength, 0);
|
||||
}
|
||||
|
||||
int PubSubClient::publish(char* topic, uint8_t* payload, uint8_t plength, uint8_t retained) {
|
||||
if (connected()) {
|
||||
uint8_t length = writeString(topic,buffer,0);
|
||||
int i;
|
||||
for (i=0;i<plength;i++) {
|
||||
buffer[length++] = payload[i];
|
||||
}
|
||||
//header |= 1; retain
|
||||
write(MQTTPUBLISH,buffer,length);
|
||||
uint8_t header = MQTTPUBLISH;
|
||||
if (retained != 0) {
|
||||
header |= 1;
|
||||
}
|
||||
write(header,buffer,length);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
void disconnect();
|
||||
int publish(char *, char *);
|
||||
int publish(char *, uint8_t *, uint8_t);
|
||||
int publish(char *, uint8_t *, uint8_t, uint8_t);
|
||||
void subscribe(char *);
|
||||
int loop();
|
||||
int connected();
|
||||
|
Loading…
x
Reference in New Issue
Block a user