Skip to content

Commit 4991925

Browse files
committed
Moving protected functions to be private since there is no need for them to be protected
1 parent 98fb05f commit 4991925

File tree

2 files changed

+75
-84
lines changed

2 files changed

+75
-84
lines changed

src/ArduinoIoTCloudTCP.cpp

Lines changed: 69 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -122,29 +122,6 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort) {
122122
return 1;
123123
}
124124

125-
// private class method used to initialize mqttClient class member. (called in the begin class method)
126-
void ArduinoIoTCloudTCP::mqttClientBegin() {
127-
// MQTT topics definition
128-
_stdoutTopic = "/a/d/" + _device_id + "/s/o";
129-
_stdinTopic = "/a/d/" + _device_id + "/s/i";
130-
if (_thing_id == "") {
131-
_dataTopicIn = "/a/d/" + _device_id + "/e/i";
132-
_dataTopicOut = "/a/d/" + _device_id + "/e/o";
133-
} else {
134-
_dataTopicIn = "/a/t/" + _thing_id + "/e/i";
135-
_dataTopicOut = "/a/t/" + _thing_id + "/e/o";
136-
_shadowTopicIn = "/a/t/" + _thing_id + "/shadow/i";
137-
_shadowTopicOut = "/a/t/" + _thing_id + "/shadow/o";
138-
}
139-
140-
// use onMessage as callback for received mqtt messages
141-
_mqttClient->onMessage(ArduinoIoTCloudTCP::onMessage);
142-
_mqttClient->setKeepAliveInterval(30 * 1000);
143-
_mqttClient->setConnectionTimeout(1500);
144-
_mqttClient->setId(_device_id.c_str());
145-
}
146-
147-
148125
int ArduinoIoTCloudTCP::connect() {
149126

150127
if (!_mqttClient->connect(_brokerAddress.c_str(), _brokerPort)) {
@@ -230,54 +207,6 @@ int ArduinoIoTCloudTCP::connected() {
230207
return _mqttClient->connected();
231208
}
232209

233-
int ArduinoIoTCloudTCP::writeProperties(const byte data[], int length) {
234-
if (!_mqttClient->beginMessage(_dataTopicOut, length, false, 0)) {
235-
return 0;
236-
}
237-
238-
if (!_mqttClient->write(data, length)) {
239-
return 0;
240-
}
241-
242-
if (!_mqttClient->endMessage()) {
243-
return 0;
244-
}
245-
246-
return 1;
247-
}
248-
249-
int ArduinoIoTCloudTCP::writeStdout(const byte data[], int length) {
250-
if (!_mqttClient->beginMessage(_stdoutTopic, length, false, 0)) {
251-
return 0;
252-
}
253-
254-
if (!_mqttClient->write(data, length)) {
255-
return 0;
256-
}
257-
258-
if (!_mqttClient->endMessage()) {
259-
return 0;
260-
}
261-
262-
return 1;
263-
}
264-
265-
int ArduinoIoTCloudTCP::writeShadowOut(const byte data[], int length) {
266-
if (!_mqttClient->beginMessage(_shadowTopicOut, length, false, 0)) {
267-
return 0;
268-
}
269-
270-
if (!_mqttClient->write(data, length)) {
271-
return 0;
272-
}
273-
274-
if (!_mqttClient->endMessage()) {
275-
return 0;
276-
}
277-
278-
return 1;
279-
}
280-
281210
/******************************************************************************
282211
* PRIVATE MEMBER FUNCTIONS
283212
******************************************************************************/
@@ -404,6 +333,75 @@ ArduinoIoTConnectionStatus ArduinoIoTCloudTCP::checkCloudConnection()
404333
return _iotStatus;
405334
}
406335

336+
void ArduinoIoTCloudTCP::mqttClientBegin() {
337+
// MQTT topics definition
338+
_stdoutTopic = "/a/d/" + _device_id + "/s/o";
339+
_stdinTopic = "/a/d/" + _device_id + "/s/i";
340+
if (_thing_id == "") {
341+
_dataTopicIn = "/a/d/" + _device_id + "/e/i";
342+
_dataTopicOut = "/a/d/" + _device_id + "/e/o";
343+
} else {
344+
_dataTopicIn = "/a/t/" + _thing_id + "/e/i";
345+
_dataTopicOut = "/a/t/" + _thing_id + "/e/o";
346+
_shadowTopicIn = "/a/t/" + _thing_id + "/shadow/i";
347+
_shadowTopicOut = "/a/t/" + _thing_id + "/shadow/o";
348+
}
349+
350+
// use onMessage as callback for received mqtt messages
351+
_mqttClient->onMessage(ArduinoIoTCloudTCP::onMessage);
352+
_mqttClient->setKeepAliveInterval(30 * 1000);
353+
_mqttClient->setConnectionTimeout(1500);
354+
_mqttClient->setId(_device_id.c_str());
355+
}
356+
357+
int ArduinoIoTCloudTCP::writeProperties(const byte data[], int length) {
358+
if (!_mqttClient->beginMessage(_dataTopicOut, length, false, 0)) {
359+
return 0;
360+
}
361+
362+
if (!_mqttClient->write(data, length)) {
363+
return 0;
364+
}
365+
366+
if (!_mqttClient->endMessage()) {
367+
return 0;
368+
}
369+
370+
return 1;
371+
}
372+
373+
int ArduinoIoTCloudTCP::writeStdout(const byte data[], int length) {
374+
if (!_mqttClient->beginMessage(_stdoutTopic, length, false, 0)) {
375+
return 0;
376+
}
377+
378+
if (!_mqttClient->write(data, length)) {
379+
return 0;
380+
}
381+
382+
if (!_mqttClient->endMessage()) {
383+
return 0;
384+
}
385+
386+
return 1;
387+
}
388+
389+
int ArduinoIoTCloudTCP::writeShadowOut(const byte data[], int length) {
390+
if (!_mqttClient->beginMessage(_shadowTopicOut, length, false, 0)) {
391+
return 0;
392+
}
393+
394+
if (!_mqttClient->write(data, length)) {
395+
return 0;
396+
}
397+
398+
if (!_mqttClient->endMessage()) {
399+
return 0;
400+
}
401+
402+
return 1;
403+
}
404+
407405
/******************************************************************************
408406
* EXTERN DEFINITION
409407
******************************************************************************/

src/ArduinoIoTCloudTCP.h

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,7 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass {
9191
// Clean up existing Mqtt connection, create a new one and initialize it
9292
int reconnect();
9393

94-
protected:
9594
friend class CloudSerialClass;
96-
// Used to initialize MQTTClient
97-
void mqttClientBegin();
98-
// Function in charge of perform MQTT reconnection, basing on class parameters(retries,and timeout)
99-
bool mqttReconnect(int const maxRetries, int const timeout);
100-
// Used to retrieve last values from _shadowTopicIn
101-
int writeStdout(const byte data[], int length);
102-
int writeProperties(const byte data[], int length);
103-
int writeShadowOut(const byte data[], int length);
104-
105-
void requestLastValue();
10695

10796
private:
10897
ConnectionHandler * _connection;
@@ -132,12 +121,16 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass {
132121
String _otaTopic;
133122

134123
static void onMessage(int length);
135-
136124
void handleMessage(int length);
137-
138125
void sendPropertiesToCloud();
126+
void requestLastValue();
139127
NetworkConnectionState checkPhyConnection();
140128
ArduinoIoTConnectionStatus checkCloudConnection();
129+
void mqttClientBegin();
130+
bool mqttReconnect(int const maxRetries, int const timeout);
131+
int writeStdout(const byte data[], int length);
132+
int writeProperties(const byte data[], int length);
133+
int writeShadowOut(const byte data[], int length);
141134
};
142135

143136
/******************************************************************************

0 commit comments

Comments
 (0)