Skip to content

Commit

Permalink
Merge pull request #33 from 256dpi/more-advanced-publish
Browse files Browse the repository at this point in the history
More Advanced Publish
  • Loading branch information
256dpi committed May 17, 2016
2 parents 837a5e8 + 9fcc25d commit 2c70573
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ boolean publish(String topic, String payload);
boolean publish(const char * topic, String payload);
boolean publish(const char * topic, const char * payload);
boolean publish(const char * topic, char * payload, unsigned int length);
boolean publish(MQTTMessage * message)
```
- The last function can be used to publish messages with more low level attributes like `retained`.
Subscribe to a topic:
```c++
Expand Down
11 changes: 11 additions & 0 deletions src/MQTTClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ boolean MQTTClient::publish(const char * topic, char * payload, unsigned int len
return client->publish(topic, message) == MQTT::SUCCESS;
}

boolean MQTTClient::publish(MQTTMessage * message) {
MQTT::Message _message;
_message.qos = MQTT::QOS0;
_message.retained = message->retained;
_message.dup = false;
_message.payload = message->payload;
_message.payloadlen = message->length;

return client->publish(message->topic, _message) == MQTT::SUCCESS;
}

boolean MQTTClient::subscribe(String topic) {
return this->subscribe(topic.c_str());
}
Expand Down
8 changes: 8 additions & 0 deletions src/MQTTClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
#include "Network.h"
#include "Timer.h"

typedef struct {
char * topic;
char * payload;
unsigned int length;
boolean retained;
} MQTTMessage;

void messageReceived(String topic, String payload, char * bytes, unsigned int length);

class MQTTClient {
Expand All @@ -37,6 +44,7 @@ class MQTTClient {
boolean publish(const char * topic, String payload);
boolean publish(const char * topic, const char * payload);
boolean publish(const char * topic, char * payload, unsigned int length);
boolean publish(MQTTMessage * message);
boolean subscribe(String topic);
boolean subscribe(const char * topic);
boolean unsubscribe(String topic);
Expand Down

0 comments on commit 2c70573

Please sign in to comment.