Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Support binary data (#104)
Browse files Browse the repository at this point in the history
* Initial branch commit for supporting binary payloads
* Adds wrappers for transmitting binary data
  • Loading branch information
gguuss authored Apr 23, 2019
1 parent 6441784 commit 4254c71
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 7 deletions.
8 changes: 8 additions & 0 deletions examples/Esp32-lwmqtt/esp32-mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,18 @@ void publishTelemetry(String data) {
mqtt->publishTelemetry(data);
}

void publishTelemetry(const char* data, int length) {
mqtt->publishTelemetry(data, length);
}

void publishTelemetry(String subfolder, String data) {
mqtt->publishTelemetry(subfolder, data);
}

void publishTelemetry(String subfolder, const char* data, int length) {
mqtt->publishTelemetry(subfolder, data, length);
}

void connect() {
connectWifi();
mqtt->mqttConnect();
Expand Down
8 changes: 8 additions & 0 deletions examples/Esp8266-lwmqtt/esp8266_mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,18 @@ void publishTelemetry(String data) {
mqtt->publishTelemetry(data);
}

void publishTelemetry(const char* data, int length) {
mqtt->publishTelemetry(data, length);
}

void publishTelemetry(String subfolder, String data) {
mqtt->publishTelemetry(subfolder, data);
}

void publishTelemetry(String subfolder, const char* data, int length) {
mqtt->publishTelemetry(subfolder, data, length);
}

void connect() {
mqtt->mqttConnect();
}
Expand Down
18 changes: 13 additions & 5 deletions examples/MKR1000-lwmqtt/mkr1000-mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,27 @@ void connectWifi() {
///////////////////////////////
// Orchestrates various methods from preceeding code.
///////////////////////////////
void connect() {
connectWifi();
mqtt->mqttConnect();
}

void publishTelemetry(String data) {
mqtt->publishTelemetry(data);
}

void publishTelemetry(const char* data, int length) {
mqtt->publishTelemetry(data, length);
}

void publishTelemetry(String subfolder, String data) {
mqtt->publishTelemetry(subfolder, data);
}

void publishTelemetry(String subfolder, const char* data, int length) {
mqtt->publishTelemetry(subfolder, data, length);
}

void connect() {
connectWifi();
mqtt->mqttConnect();
}

void setupCloudIoT() {
device = new CloudIoTCoreDevice(
project_id, location, registry_id, device_id,
Expand Down
8 changes: 8 additions & 0 deletions examples/universal-lwmqtt/universal-mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,18 @@ void publishTelemetry(String data) {
mqtt->publishTelemetry(data);
}

void publishTelemetry(const char* data, int length) {
mqtt->publishTelemetry(data, length);
}

void publishTelemetry(String subfolder, String data) {
mqtt->publishTelemetry(subfolder, data);
}

void publishTelemetry(String subfolder, const char* data, int length) {
mqtt->publishTelemetry(subfolder, data, length);
}

void connect() {
mqtt->mqttConnect();
}
Expand Down
16 changes: 14 additions & 2 deletions src/CloudIoTCoreMqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "CloudIoTCoreMqtt.h"

// Forward global callback declarations
String getJwt();
String getJwt();
void messageReceived(String &topic, String &payload);


Expand All @@ -42,15 +42,27 @@ void CloudIoTCoreMqtt::publishTelemetry(String data) {
this->mqttClient->publish(device->getEventsTopic(), data);
}

void CloudIoTCoreMqtt::publishTelemetry(const char* data, int length) {
this->mqttClient->publish(device->getEventsTopic().c_str(), data, length);
}

void CloudIoTCoreMqtt::publishTelemetry(String subtopic, String data) {
this->mqttClient->publish(device->getEventsTopic() + subtopic, data);
}

void CloudIoTCoreMqtt::publishTelemetry(String subtopic, const char* data, int length) {
this->mqttClient->publish(String(device->getEventsTopic() + subtopic).c_str(), data, length);
}

// Helper that just sends default sensor
void CloudIoTCoreMqtt::publishState(String data) {
this->mqttClient->publish(device->getStateTopic(), data);
}

void CloudIoTCoreMqtt::publishState(const char* data, int length) {
this->mqttClient->publish(device->getStateTopic().c_str(), data, length);
}

void CloudIoTCoreMqtt::onConnect() {
if (logConnect) {
publishState("connected");
Expand Down Expand Up @@ -170,7 +182,7 @@ void CloudIoTCoreMqtt::mqttConnect() {
}

// Set QoS to 1 (ack) for configuration messages
this->mqttClient->subscribe(device->getConfigTopic(), 1);
this->mqttClient->subscribe(device->getConfigTopic(), 1);
// QoS 0 (no ack) for commands
this->mqttClient->subscribe(device->getCommandsTopic(), 0);

Expand Down
3 changes: 3 additions & 0 deletions src/CloudIoTCoreMqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ class CloudIoTCoreMqtt {

void startMQTT();
void publishTelemetry(String data);
void publishTelemetry(const char* data, int length);
void publishTelemetry(String subtopic, String data);
void publishTelemetry(String subtopic, const char* data, int length);
void publishState(String data);
void publishState(const char* data, int length);
void onConnect();
void setLogConnect(boolean enabled);
void logError();
Expand Down

0 comments on commit 4254c71

Please sign in to comment.