Skip to content

Commit 20cbb75

Browse files
committed
Applying suggestions by A. Catozzi upon internal review
- removed unnecessary call to _mqttReconnect(...) in ArduinoIoTCloud - removed unncessary begin() into case IOT_STATUS_IDLE in ArduinoIoTCloud - removed unnecessary calls to update() in CloudSerial - fixed if statement in ConnectionManager
1 parent e4e11e5 commit 20cbb75

File tree

3 files changed

+3
-28
lines changed

3 files changed

+3
-28
lines changed

src/ArduinoIoTCloud.cpp

+1-20
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ int ArduinoIoTCloudClass::begin(Client& net, String brokerAddress)
117117

118118

119119
// TODO: Find a better way to allow callback into object method
120-
121120
// Begin function for the MQTTClient
122121
mqttClientBegin();
123122

@@ -212,13 +211,6 @@ void ArduinoIoTCloudClass::update(int const reconnectionMaxRetries, int const re
212211
if(iotStatus != IOT_STATUS_CLOUD_CONNECTED){
213212
return;
214213
}
215-
// Method's argument controls
216-
int const maxRetries = (reconnectionMaxRetries > 0) ? reconnectionMaxRetries : MAX_RETRIES;
217-
int const timeout = (reconnectionTimeoutMs > 0) ? reconnectionTimeoutMs : RECONNECTION_TIMEOUT;
218-
219-
// If the reconnect() culd not establish the connection, return the control to the user sketch
220-
if (!mqttReconnect(maxRetries, timeout))
221-
return;
222214

223215
// MTTQClient connected!, poll() used to retrieve data from MQTT broker
224216
_mqttClient->poll();
@@ -323,20 +315,9 @@ void ArduinoIoTCloudClass::connectionCheck() {
323315
switch (iotStatus) {
324316
case IOT_STATUS_IDLE:
325317
{
326-
int connectionAttempt;
327-
if(connection == NULL){
328-
connectionAttempt = begin(*_net, _brokerAddress);
329-
}else{
330-
connectionAttempt = begin(connection, _brokerAddress);
331-
}
332-
if(!connectionAttempt){
333-
debugMessage("Error Starting Arduino Cloud\nTrying again in a few seconds", 0);
334-
setIoTConnectionState(IOT_STATUS_CLOUD_ERROR);
335-
return;
336-
}
337318
setIoTConnectionState(IOT_STATUS_CLOUD_CONNECTING);
338319
break;
339-
}
320+
}
340321

341322
case IOT_STATUS_CLOUD_ERROR:
342323
debugMessage("Cloud Error. Retrying...", 0);

src/CloudSerial.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,30 @@ void CloudSerialClass::end()
3838

3939
int CloudSerialClass::available()
4040
{
41-
ArduinoCloud.update();
4241

4342
return _rxBuffer.available();
4443
}
4544

4645
int CloudSerialClass::availableForWrite()
4746
{
48-
ArduinoCloud.update();
4947

5048
return _txBuffer.availableForStore();
5149
}
5250

5351
int CloudSerialClass::peek()
5452
{
55-
ArduinoCloud.update();
5653

5754
return _rxBuffer.peek();
5855
}
5956

6057
int CloudSerialClass::read()
6158
{
62-
ArduinoCloud.update();
6359

6460
return _rxBuffer.read_char();
6561
}
6662

6763
void CloudSerialClass::flush()
6864
{
69-
ArduinoCloud.update();
7065

7166
byte out[CLOUD_SERIAL_TX_BUFFER_SIZE];
7267
int length = 0;
@@ -91,7 +86,6 @@ size_t CloudSerialClass::write(const uint8_t data)
9186

9287
CloudSerialClass::operator bool()
9388
{
94-
ArduinoCloud.update();
9589

9690
return ArduinoCloud.connected();
9791
}

src/ConnectionManager.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ inline void debugMessage(char *_msg, uint8_t _debugLevel, bool _timestamp = true
8484
if (_debugLevel <= debugMessageLevel) {
8585
char prepend[20];
8686
sprintf(prepend, "\n[ %d ] ", millis());
87-
if(_timestamp)
87+
if(_timestamp){
8888
Serial.print(prepend);
89+
}
8990
if(_newline){
9091
Serial.println(_msg);
9192
}else{
9293
Serial.print(_msg);
9394
}
94-
9595
}
9696
}
9797

0 commit comments

Comments
 (0)