Add publish(topic,payload,retained) function
This commit is contained in:
parent
15a0e41c81
commit
2f97e4a558
@ -1,5 +1,9 @@
|
|||||||
|
2.3
|
||||||
|
* Add publish(topic,payload,retained) function
|
||||||
|
|
||||||
2.2
|
2.2
|
||||||
* Change code layout to match Arduino Library reqs
|
* Change code layout to match Arduino Library reqs
|
||||||
|
|
||||||
2.1
|
2.1
|
||||||
* Add MAX_TRANSFER_SIZE def to chunk messages if needed
|
* Add MAX_TRANSFER_SIZE def to chunk messages if needed
|
||||||
* Reject topic/payloads that exceed MQTT_MAX_PACKET_SIZE
|
* Reject topic/payloads that exceed MQTT_MAX_PACKET_SIZE
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=PubSubClient
|
name=PubSubClient
|
||||||
version=2.2
|
version=2.3
|
||||||
author=Nick O'Leary <nick.oleary@gmail.com>
|
author=Nick O'Leary <nick.oleary@gmail.com>
|
||||||
maintainer=Nick O'Leary <nick.oleary@gmail.com>
|
maintainer=Nick O'Leary <nick.oleary@gmail.com>
|
||||||
sentence=A client library for MQTT messaging.
|
sentence=A client library for MQTT messaging.
|
||||||
|
@ -329,6 +329,10 @@ boolean PubSubClient::publish(const char* topic, const char* payload) {
|
|||||||
return publish(topic,(const uint8_t*)payload,strlen(payload),false);
|
return publish(topic,(const uint8_t*)payload,strlen(payload),false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean PubSubClient::publish(const char* topic, const char* payload, boolean retained) {
|
||||||
|
return publish(topic,(const uint8_t*)payload,strlen(payload),retained);
|
||||||
|
}
|
||||||
|
|
||||||
boolean PubSubClient::publish(const char* topic, const uint8_t* payload, unsigned int plength) {
|
boolean PubSubClient::publish(const char* topic, const uint8_t* payload, unsigned int plength) {
|
||||||
return publish(topic, payload, plength, false);
|
return publish(topic, payload, plength, false);
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,7 @@ public:
|
|||||||
boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);
|
boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);
|
||||||
void disconnect();
|
void disconnect();
|
||||||
boolean publish(const char* topic, const char* payload);
|
boolean publish(const char* topic, const char* payload);
|
||||||
|
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 publish(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
|
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
|
||||||
boolean publish_P(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
|
boolean publish_P(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
|
||||||
|
@ -63,7 +63,7 @@ int test_publish_bytes() {
|
|||||||
|
|
||||||
|
|
||||||
int test_publish_retained() {
|
int test_publish_retained() {
|
||||||
IT("publishes retained");
|
IT("publishes retained - 1");
|
||||||
ShimClient shimClient;
|
ShimClient shimClient;
|
||||||
shimClient.setAllowConnect(true);
|
shimClient.setAllowConnect(true);
|
||||||
|
|
||||||
@ -88,6 +88,29 @@ int test_publish_retained() {
|
|||||||
END_IT
|
END_IT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int test_publish_retained_2() {
|
||||||
|
IT("publishes retained - 2");
|
||||||
|
ShimClient shimClient;
|
||||||
|
shimClient.setAllowConnect(true);
|
||||||
|
|
||||||
|
byte connack[] = { 0x20, 0x02, 0x00, 0x00 };
|
||||||
|
shimClient.respond(connack,4);
|
||||||
|
|
||||||
|
PubSubClient client(server, 1883, callback, shimClient);
|
||||||
|
int rc = client.connect((char*)"client_test1");
|
||||||
|
IS_TRUE(rc);
|
||||||
|
|
||||||
|
byte publish[] = {0x31,0xc,0x0,0x5,0x74,0x6f,0x70,0x69,0x63,'A','B','C','D','E'};
|
||||||
|
shimClient.expect(publish,14);
|
||||||
|
|
||||||
|
rc = client.publish((char*)"topic",(char*)"ABCDE",true);
|
||||||
|
IS_TRUE(rc);
|
||||||
|
|
||||||
|
IS_FALSE(shimClient.error());
|
||||||
|
|
||||||
|
END_IT
|
||||||
|
}
|
||||||
|
|
||||||
int test_publish_not_connected() {
|
int test_publish_not_connected() {
|
||||||
IT("publish fails when not connected");
|
IT("publish fails when not connected");
|
||||||
ShimClient shimClient;
|
ShimClient shimClient;
|
||||||
@ -158,6 +181,7 @@ int main()
|
|||||||
test_publish();
|
test_publish();
|
||||||
test_publish_bytes();
|
test_publish_bytes();
|
||||||
test_publish_retained();
|
test_publish_retained();
|
||||||
|
test_publish_retained_2();
|
||||||
test_publish_not_connected();
|
test_publish_not_connected();
|
||||||
test_publish_too_long();
|
test_publish_too_long();
|
||||||
test_publish_P();
|
test_publish_P();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user