Skip to content

Commit fc49176

Browse files
aentingermattiabertorello
authored andcommitted
Changing topic format from /ORG_ID/d/DEVICE_ID/* to /ORG_ID/t/THING_ID/*
In order for the new topic format to be used, the function setThingId must be called setting the ID of the THING - otherwise the old format is still used
1 parent f2544dd commit fc49176

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/ArduinoIoTCloud.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const static int serialNumberAndAuthorityKeyIdentifierSlot = 11;
99
const static int thingIdSlot = 12;
1010

1111
ArduinoIoTCloudClass::ArduinoIoTCloudClass() :
12+
_thing_id (""),
1213
_bearSslClient(NULL),
13-
// Size of the receive buffer
14-
_mqttClient(MQTT_BUFFER_SIZE)
14+
_mqttClient (MQTT_BUFFER_SIZE)
1515
{
1616
}
1717

@@ -71,10 +71,18 @@ int ArduinoIoTCloudClass::begin(Client& net, String brokerAddress)
7171
void ArduinoIoTCloudClass::mqttClientBegin(Client& net)
7272
{
7373
// MQTT topics definition
74-
_stdoutTopic = "/a/d/" + _id + "/s/o";
75-
_stdinTopic = "/a/d/" + _id + "/s/i";
76-
_dataTopicIn = "/a/d/" + _id + "/e/i";
77-
_dataTopicOut = "/a/d/" + _id + "/e/o";
74+
if(_thing_id == "") {
75+
_stdoutTopic = "/a/d/" + _id + "/s/o";
76+
_stdinTopic = "/a/d/" + _id + "/s/i";
77+
_dataTopicIn = "/a/d/" + _id + "/e/i";
78+
_dataTopicOut = "/a/d/" + _id + "/e/o";
79+
}
80+
else {
81+
_stdoutTopic = "/a/t/" + _thing_id + "/s/o";
82+
_stdinTopic = "/a/t/" + _thing_id + "/s/i";
83+
_dataTopicIn = "/a/t/" + _thing_id + "/e/i";
84+
_dataTopicOut = "/a/t/" + _thing_id + "/e/o";
85+
}
7886

7987
// use onMessage as callback for received mqtt messages
8088
_mqttClient.onMessageAdvanced(ArduinoIoTCloudClass::onMessage);

src/ArduinoIoTCloud.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class ArduinoIoTCloudClass {
5050
// Clean up existing Mqtt connection, create a new one and initialize it
5151
int reconnect(Client& net);
5252

53+
inline void setThingId(String const thing_id) { _thing_id = thing_id; };
54+
5355
#define addProperty( v, ...) addPropertyReal(v, #v, __VA_ARGS__)
5456

5557
static unsigned long const DEFAULT_MIN_TIME_BETWEEN_UPDATES_MILLIS = 100; /* Data rate throttled to 10 Hz */
@@ -87,8 +89,9 @@ class ArduinoIoTCloudClass {
8789
static void onMessage(MQTTClient *client, char topic[], char bytes[], int const length);
8890
void handleMessage(char topic[], char bytes[], int const length);
8991

90-
String _id;
91-
String _brokerAddress;
92+
String _id,
93+
_thing_id,
94+
_brokerAddress;
9295
ArduinoCloudThing Thing;
9396
BearSSLClient* _bearSslClient;
9497
MQTTClient _mqttClient;

0 commit comments

Comments
 (0)