Skip to content

Commit 1a4632f

Browse files
committed
Turning _deice_id into a private member variable with setters/getters
1 parent 8701e53 commit 1a4632f

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/ArduinoIoTCloud.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ class ArduinoIoTCloudClass
8484
virtual int connected () = 0;
8585
virtual void printDebugInfo() = 0;
8686

87-
inline void setThingId (String const thing_id) { _thing_id = thing_id; };
88-
inline String getThingId () const { return _thing_id; };
89-
inline String getDeviceId() const { return _device_id; };
87+
inline void setThingId (String const thing_id) { _thing_id = thing_id; };
88+
inline String & getThingId () { return _thing_id; };
89+
inline void setDeviveId(String const device_id) { _device_id = device_id; };
90+
inline String & getDeviceId() { return _device_id; };
9091

9192
void addCallback(ArduinoIoTCloudEvent const event, OnCloudEventCallback callback);
9293

@@ -130,8 +131,6 @@ class ArduinoIoTCloudClass
130131

131132
inline ArduinoIoTConnectionStatus getIoTStatus() { return _iotStatus; }
132133

133-
String _device_id = "";
134-
135134
ArduinoIoTConnectionStatus _iotStatus = ArduinoIoTConnectionStatus::IDLE;
136135
ArduinoIoTSynchronizationStatus _syncStatus = ArduinoIoTSynchronizationStatus::SYNC_STATUS_SYNCHRONIZED;
137136

@@ -149,6 +148,7 @@ class ArduinoIoTCloudClass
149148
private:
150149

151150
String _thing_id = "";
151+
String _device_id = "";
152152
};
153153

154154
#ifdef HAS_TCP

src/ArduinoIoTCloudTCP.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort) {
9797
_brokerPort = brokerPort;
9898

9999
#ifdef BOARD_HAS_ECCX08
100-
if (!ECCX08.begin()) { Debug.print(DBG_ERROR, "Cryptography processor failure. Make sure you have a compatible board."); return 0; }
101-
if (!CryptoUtil::readDeviceId(ECCX08, _device_id, ECCX08Slot::DeviceId)) { Debug.print(DBG_ERROR, "Cryptography processor read failure."); return 0; }
102-
if (!CryptoUtil::reconstructCertificate(_eccx08_cert, _device_id, ECCX08Slot::Key, ECCX08Slot::CompressedCertificate, ECCX08Slot::SerialNumberAndAuthorityKeyIdentifier)) { Debug.print(DBG_ERROR, "Cryptography certificate reconstruction failure."); return 0; }
100+
if (!ECCX08.begin()) { Debug.print(DBG_ERROR, "Cryptography processor failure. Make sure you have a compatible board."); return 0; }
101+
if (!CryptoUtil::readDeviceId(ECCX08, getDeviceId(), ECCX08Slot::DeviceId)) { Debug.print(DBG_ERROR, "Cryptography processor read failure."); return 0; }
102+
if (!CryptoUtil::reconstructCertificate(_eccx08_cert, getDeviceId(), ECCX08Slot::Key, ECCX08Slot::CompressedCertificate, ECCX08Slot::SerialNumberAndAuthorityKeyIdentifier)) { Debug.print(DBG_ERROR, "Cryptography certificate reconstruction failure."); return 0; }
103103
ArduinoBearSSL.onGetTime(getTime);
104104
_sslClient = new BearSSLClient(_connection->getClient(), ArduinoIoTCloudTrustAnchor, ArduinoIoTCloudTrustAnchor_NUM);
105105
_sslClient->setEccSlot(static_cast<int>(ECCX08Slot::Key), _eccx08_cert.bytes(), _eccx08_cert.length());
@@ -110,12 +110,12 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort) {
110110

111111
_mqttClient = new MqttClient(*_sslClient);
112112
#ifdef BOARD_ESP
113-
_mqttClient->setUsernamePassword(_device_id, _password);
113+
_mqttClient->setUsernamePassword(getDeviceId(), _password);
114114
#endif
115115
_mqttClient->onMessage(ArduinoIoTCloudTCP::onMessage);
116116
_mqttClient->setKeepAliveInterval(30 * 1000);
117117
_mqttClient->setConnectionTimeout(1500);
118-
_mqttClient->setId(_device_id.c_str());
118+
_mqttClient->setId(getDeviceId().c_str());
119119

120120
_stdinTopic = getTopic_stdin();
121121
_stdoutTopic = getTopic_stdout();

src/ArduinoIoTCloudTCP.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass {
7070

7171
#ifdef BOARD_ESP
7272
inline void setBoardId(String const device_id) {
73-
_device_id = device_id;
73+
setDeviveId(device_id);
7474
}
7575
inline void setSecretDeviceKey(String const password) {
7676
_password = password;
@@ -119,12 +119,12 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass {
119119
String _dataTopicOut;
120120
String _dataTopicIn;
121121

122-
inline String getTopic_stdin () const { return String("/a/d/" + _device_id + "/s/i"); }
123-
inline String getTopic_stdout () const { return String("/a/d/" + _device_id + "/s/o"); }
124-
inline String getTopic_shadowout() const { return ( getThingId().length() == 0) ? String("") : String("/a/t/" + getThingId() + "/shadow/o"); }
125-
inline String getTopic_shadowin () const { return ( getThingId().length() == 0) ? String("") : String("/a/t/" + getThingId() + "/shadow/i"); }
126-
inline String getTopic_dataout () const { return ( getThingId().length() == 0) ? String("/a/d/" + _device_id + "/e/o") : String("/a/t/" + getThingId() + "/e/o"); }
127-
inline String getTopic_datain () const { return ( getThingId().length() == 0) ? String("/a/d/" + _device_id + "/e/i") : String("/a/t/" + getThingId() + "/e/i"); }
122+
inline String getTopic_stdin () { return String("/a/d/" + getDeviceId() + "/s/i"); }
123+
inline String getTopic_stdout () { return String("/a/d/" + getDeviceId() + "/s/o"); }
124+
inline String getTopic_shadowout() { return ( getThingId().length() == 0) ? String("") : String("/a/t/" + getThingId() + "/shadow/o"); }
125+
inline String getTopic_shadowin () { return ( getThingId().length() == 0) ? String("") : String("/a/t/" + getThingId() + "/shadow/i"); }
126+
inline String getTopic_dataout () { return ( getThingId().length() == 0) ? String("/a/d/" + getDeviceId() + "/e/o") : String("/a/t/" + getThingId() + "/e/o"); }
127+
inline String getTopic_datain () { return ( getThingId().length() == 0) ? String("/a/d/" + getDeviceId() + "/e/i") : String("/a/t/" + getThingId() + "/e/i"); }
128128

129129
static void onMessage(int length);
130130
void handleMessage(int length);

0 commit comments

Comments
 (0)