Skip to content

Commit a284622

Browse files
authored
Merge pull request #191 from arduino-libraries/string-literals
Use flash strings to conserve RAM space
2 parents 2c8e67b + 77a6db7 commit a284622

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

.github/workflows/compile-examples.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- source-path: ./
2424
- source-url: https://github.com/arduino-libraries/Arduino_ConnectionHandler.git
2525
version: latest
26-
- name: Arduino_DebugUtils
26+
- source-url: https://github.com/arduino-libraries/Arduino_DebugUtils.git
2727
- name: ArduinoMqttClient
2828
# sketch paths to compile (recursive) for all boards
2929
UNIVERSAL_SKETCH_PATHS: '"examples/ArduinoIoTCloud-Advanced" "examples/ArduinoIoTCloud-Basic" "examples/utility/ArduinoIoTCloud_Travis_CI"'

src/AIoTC_Config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#endif
4444

4545
#ifndef DBG_VERBOSE
46-
#define DBG_VERBOSE(fmt, ...) Debug.print(DBG_VERBOSE, fmt, ## __VA_ARGS__)
46+
#define DBG_VERBOSE(fmt, ...) //Debug.print(DBG_VERBOSE, fmt, ## __VA_ARGS__)
4747
#endif
4848

4949
/******************************************************************************

src/ArduinoIoTCloudLPWAN.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ void ArduinoIoTCloudLPWAN::update()
8787

8888
void ArduinoIoTCloudLPWAN::printDebugInfo()
8989
{
90-
DBG_INFO("***** Arduino IoT Cloud LPWAN - configuration info *****");
91-
DBG_INFO("Thing ID: %s", getThingId().c_str());
90+
DBG_INFO(F("***** Arduino IoT Cloud LPWAN - configuration info *****"));
91+
DBG_INFO(F("Thing ID: %s"), getThingId().c_str());
9292
}
9393

9494
/******************************************************************************
@@ -106,16 +106,16 @@ ArduinoIoTCloudLPWAN::State ArduinoIoTCloudLPWAN::handle_ConnectPhy()
106106
ArduinoIoTCloudLPWAN::State ArduinoIoTCloudLPWAN::handle_SyncTime()
107107
{
108108
unsigned long const internal_posix_time = _time_service.getTime();
109-
DBG_VERBOSE("ArduinoIoTCloudLPWAN::%s internal clock configured to posix timestamp %d", __FUNCTION__, internal_posix_time);
110-
DBG_INFO("Connected to Arduino IoT Cloud");
109+
DBG_VERBOSE(F("ArduinoIoTCloudLPWAN::%s internal clock configured to posix timestamp %d"), __FUNCTION__, internal_posix_time);
110+
DBG_INFO(F("Connected to Arduino IoT Cloud"));
111111
return State::Connected;
112112
}
113113

114114
ArduinoIoTCloudLPWAN::State ArduinoIoTCloudLPWAN::handle_Connected()
115115
{
116116
if (!connected())
117117
{
118-
DBG_ERROR("ArduinoIoTCloudLPWAN::%s connection to gateway lost", __FUNCTION__);
118+
DBG_ERROR(F("ArduinoIoTCloudLPWAN::%s connection to gateway lost"), __FUNCTION__);
119119
return State::ConnectPhy;
120120
}
121121

src/ArduinoIoTCloudTCP.cpp

+19-19
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
112112
#endif /* OTA_ENABLED */
113113

114114
#ifdef BOARD_HAS_ECCX08
115-
if (!ECCX08.begin()) { DBG_ERROR("Cryptography processor failure. Make sure you have a compatible board."); return 0; }
116-
if (!CryptoUtil::readDeviceId(ECCX08, getDeviceId(), ECCX08Slot::DeviceId)) { DBG_ERROR("Cryptography processor read failure."); return 0; }
117-
if (!CryptoUtil::reconstructCertificate(_eccx08_cert, getDeviceId(), ECCX08Slot::Key, ECCX08Slot::CompressedCertificate, ECCX08Slot::SerialNumberAndAuthorityKeyIdentifier)) { DBG_ERROR("Cryptography certificate reconstruction failure."); return 0; }
115+
if (!ECCX08.begin()) { DBG_ERROR(F("Cryptography processor failure. Make sure you have a compatible board.")); return 0; }
116+
if (!CryptoUtil::readDeviceId(ECCX08, getDeviceId(), ECCX08Slot::DeviceId)) { DBG_ERROR(F("Cryptography processor read failure.")); return 0; }
117+
if (!CryptoUtil::reconstructCertificate(_eccx08_cert, getDeviceId(), ECCX08Slot::Key, ECCX08Slot::CompressedCertificate, ECCX08Slot::SerialNumberAndAuthorityKeyIdentifier)) { DBG_ERROR(F("Cryptography certificate reconstruction failure.")); return 0; }
118118
_sslClient.setClient(_connection->getClient());
119119
_sslClient.setEccSlot(static_cast<int>(ECCX08Slot::Key), _eccx08_cert.bytes(), _eccx08_cert.length());
120120
#elif defined(BOARD_ESP)
@@ -145,7 +145,7 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
145145
#if OTA_STORAGE_SNU
146146
String const nina_fw_version = WiFi.firmwareVersion();
147147
if (nina_fw_version < "1.4.1") {
148-
DBG_ERROR("ArduinoIoTCloudTCP::%s error nina firmware needs to be >= 1.4.1, current %s", __FUNCTION__, nina_fw_version.c_str());
148+
DBG_ERROR(F("ArduinoIoTCloudTCP::%s error nina firmware needs to be >= 1.4.1, current %s"), __FUNCTION__, nina_fw_version.c_str());
149149
return 0;
150150
}
151151
#endif /* OTA_STORAGE_SNU */
@@ -180,10 +180,10 @@ int ArduinoIoTCloudTCP::connected()
180180

181181
void ArduinoIoTCloudTCP::printDebugInfo()
182182
{
183-
DBG_INFO("***** Arduino IoT Cloud - configuration info *****");
184-
DBG_INFO("Device ID: %s", getDeviceId().c_str());
185-
DBG_INFO("Thing ID: %s", getThingId().c_str());
186-
DBG_INFO("MQTT Broker: %s:%d", _brokerAddress.c_str(), _brokerPort);
183+
DBG_INFO(F("***** Arduino IoT Cloud - configuration info *****"));
184+
DBG_INFO(F("Device ID: %s"), getDeviceId().c_str());
185+
DBG_INFO(F("Thing ID: %s"), getThingId().c_str());
186+
DBG_INFO(F("MQTT Broker: %s:%d"), _brokerAddress.c_str(), _brokerPort);
187187
}
188188

189189
/******************************************************************************
@@ -201,7 +201,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectPhy()
201201
ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SyncTime()
202202
{
203203
unsigned long const internal_posix_time = _time_service.getTime();
204-
DBG_VERBOSE("ArduinoIoTCloudTCP::%s internal clock configured to posix timestamp %d", __FUNCTION__, internal_posix_time);
204+
DBG_VERBOSE(F("ArduinoIoTCloudTCP::%s internal clock configured to posix timestamp %d"), __FUNCTION__, internal_posix_time);
205205
return State::ConnectMqttBroker;
206206
}
207207

@@ -210,28 +210,28 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectMqttBroker()
210210
if (_mqttClient.connect(_brokerAddress.c_str(), _brokerPort))
211211
return State::SubscribeMqttTopics;
212212

213-
DBG_ERROR("ArduinoIoTCloudTCP::%s could not connect to %s:%d", __FUNCTION__, _brokerAddress.c_str(), _brokerPort);
213+
DBG_ERROR(F("ArduinoIoTCloudTCP::%s could not connect to %s:%d"), __FUNCTION__, _brokerAddress.c_str(), _brokerPort);
214214
return State::ConnectPhy;
215215
}
216216

217217
ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeMqttTopics()
218218
{
219219
if (!_mqttClient.subscribe(_dataTopicIn))
220220
{
221-
DBG_ERROR("ArduinoIoTCloudTCP::%s could not subscribe to %s", __FUNCTION__, _dataTopicIn.c_str());
221+
DBG_ERROR(F("ArduinoIoTCloudTCP::%s could not subscribe to %s"), __FUNCTION__, _dataTopicIn.c_str());
222222
return State::SubscribeMqttTopics;
223223
}
224224

225225
if (_shadowTopicIn != "")
226226
{
227227
if (!_mqttClient.subscribe(_shadowTopicIn))
228228
{
229-
DBG_ERROR("ArduinoIoTCloudTCP::%s could not subscribe to %s", __FUNCTION__, _shadowTopicIn.c_str());
229+
DBG_ERROR(F("ArduinoIoTCloudTCP::%s could not subscribe to %s"), __FUNCTION__, _shadowTopicIn.c_str());
230230
return State::SubscribeMqttTopics;
231231
}
232232
}
233233

234-
DBG_INFO("Connected to Arduino IoT Cloud");
234+
DBG_INFO(F("Connected to Arduino IoT Cloud"));
235235
execCloudEventCallback(ArduinoIoTCloudEvent::CONNECT);
236236

237237
if (_shadowTopicIn != "")
@@ -246,7 +246,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_RequestLastValues()
246246
unsigned long const now = millis();
247247
if ((now - _lastSyncRequestTickTime) > TIMEOUT_FOR_LASTVALUES_SYNC)
248248
{
249-
DBG_VERBOSE("ArduinoIoTCloudTCP::%s [%d] last values requested", __FUNCTION__, now);
249+
DBG_VERBOSE(F("ArduinoIoTCloudTCP::%s [%d] last values requested"), __FUNCTION__, now);
250250
requestLastValue();
251251
_lastSyncRequestTickTime = now;
252252
}
@@ -258,7 +258,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
258258
{
259259
if (!_mqttClient.connected())
260260
{
261-
DBG_ERROR("ArduinoIoTCloudTCP::%s MQTT client connection lost", __FUNCTION__);
261+
DBG_ERROR(F("ArduinoIoTCloudTCP::%s MQTT client connection lost"), __FUNCTION__);
262262

263263
/* Forcefully disconnect MQTT client and trigger a reconnection. */
264264
_mqttClient.stop();
@@ -321,7 +321,7 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
321321

322322
if ((_shadowTopicIn == topic) && (_state == State::RequestLastValues))
323323
{
324-
DBG_VERBOSE("ArduinoIoTCloudTCP::%s [%d] last values received", __FUNCTION__, millis());
324+
DBG_VERBOSE(F("ArduinoIoTCloudTCP::%s [%d] last values received"), __FUNCTION__, millis());
325325
CBORDecoder::decode(_property_container, (uint8_t*)bytes, length, true);
326326
sendPropertiesToCloud();
327327
execCloudEventCallback(ArduinoIoTCloudEvent::SYNC);
@@ -376,8 +376,8 @@ void ArduinoIoTCloudTCP::on_OTA_REQ_Update()
376376

377377
void ArduinoIoTCloudTCP::onOTARequest()
378378
{
379-
DBG_VERBOSE("ArduinoIoTCloudTCP::%s _ota_req = %s", __FUNCTION__, _ota_req ? "true" : "false");
380-
DBG_VERBOSE("ArduinoIoTCloudTCP::%s _ota_url = %s", __FUNCTION__, _ota_url.c_str());
379+
DBG_VERBOSE(F("ArduinoIoTCloudTCP::%s _ota_req = %s"), __FUNCTION__, _ota_req ? "true" : "false");
380+
DBG_VERBOSE(F("ArduinoIoTCloudTCP::%s _ota_url = %s"), __FUNCTION__, _ota_url.c_str());
381381

382382
if (_ota_req)
383383
{
@@ -398,7 +398,7 @@ void ArduinoIoTCloudTCP::onOTARequest()
398398
uint8_t nina_ota_err_code = 0;
399399
if (!WiFiStorage.downloadOTA(_ota_url.c_str(), &nina_ota_err_code))
400400
{
401-
DBG_ERROR("ArduinoIoTCloudTCP::%s error download to nina: %d", __FUNCTION__, nina_ota_err_code);
401+
DBG_ERROR(F("ArduinoIoTCloudTCP::%s error download to nina: %d"), __FUNCTION__, nina_ota_err_code);
402402
_ota_error = static_cast<int>(OTAError::DownloadFailed);
403403
return;
404404
}

0 commit comments

Comments
 (0)