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
|
1.5
|
||||||
* Added default constructor
|
* Added default constructor
|
||||||
* Fixed compile error when used with arduino-0021 or later
|
* 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));
|
return publish(topic,(uint8_t*)payload,strlen(payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int PubSubClient::publish(char* topic, uint8_t* payload, uint8_t plength) {
|
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()) {
|
if (connected()) {
|
||||||
uint8_t length = writeString(topic,buffer,0);
|
uint8_t length = writeString(topic,buffer,0);
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<plength;i++) {
|
for (i=0;i<plength;i++) {
|
||||||
buffer[length++] = payload[i];
|
buffer[length++] = payload[i];
|
||||||
}
|
}
|
||||||
//header |= 1; retain
|
uint8_t header = MQTTPUBLISH;
|
||||||
write(MQTTPUBLISH,buffer,length);
|
if (retained != 0) {
|
||||||
|
header |= 1;
|
||||||
|
}
|
||||||
|
write(header,buffer,length);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -32,6 +32,7 @@ public:
|
|||||||
void disconnect();
|
void disconnect();
|
||||||
int publish(char *, char *);
|
int publish(char *, char *);
|
||||||
int publish(char *, uint8_t *, uint8_t);
|
int publish(char *, uint8_t *, uint8_t);
|
||||||
|
int publish(char *, uint8_t *, uint8_t, uint8_t);
|
||||||
void subscribe(char *);
|
void subscribe(char *);
|
||||||
int loop();
|
int loop();
|
||||||
int connected();
|
int connected();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user