Skip to content

Commit

Permalink
Merge pull request #191 from arduino-libraries/string-literals
Browse files Browse the repository at this point in the history
Use flash strings to conserve RAM space
  • Loading branch information
aentinger authored Aug 21, 2020
2 parents 2c8e67b + 77a6db7 commit a284622
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- source-path: ./
- source-url: https://github.com/arduino-libraries/Arduino_ConnectionHandler.git
version: latest
- name: Arduino_DebugUtils
- source-url: https://github.com/arduino-libraries/Arduino_DebugUtils.git
- name: ArduinoMqttClient
# sketch paths to compile (recursive) for all boards
UNIVERSAL_SKETCH_PATHS: '"examples/ArduinoIoTCloud-Advanced" "examples/ArduinoIoTCloud-Basic" "examples/utility/ArduinoIoTCloud_Travis_CI"'
Expand Down
2 changes: 1 addition & 1 deletion src/AIoTC_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#endif

#ifndef DBG_VERBOSE
#define DBG_VERBOSE(fmt, ...) Debug.print(DBG_VERBOSE, fmt, ## __VA_ARGS__)
#define DBG_VERBOSE(fmt, ...) //Debug.print(DBG_VERBOSE, fmt, ## __VA_ARGS__)
#endif

/******************************************************************************
Expand Down
10 changes: 5 additions & 5 deletions src/ArduinoIoTCloudLPWAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void ArduinoIoTCloudLPWAN::update()

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

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

ArduinoIoTCloudLPWAN::State ArduinoIoTCloudLPWAN::handle_Connected()
{
if (!connected())
{
DBG_ERROR("ArduinoIoTCloudLPWAN::%s connection to gateway lost", __FUNCTION__);
DBG_ERROR(F("ArduinoIoTCloudLPWAN::%s connection to gateway lost"), __FUNCTION__);
return State::ConnectPhy;
}

Expand Down
38 changes: 19 additions & 19 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
#endif /* OTA_ENABLED */

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

void ArduinoIoTCloudTCP::printDebugInfo()
{
DBG_INFO("***** Arduino IoT Cloud - configuration info *****");
DBG_INFO("Device ID: %s", getDeviceId().c_str());
DBG_INFO("Thing ID: %s", getThingId().c_str());
DBG_INFO("MQTT Broker: %s:%d", _brokerAddress.c_str(), _brokerPort);
DBG_INFO(F("***** Arduino IoT Cloud - configuration info *****"));
DBG_INFO(F("Device ID: %s"), getDeviceId().c_str());
DBG_INFO(F("Thing ID: %s"), getThingId().c_str());
DBG_INFO(F("MQTT Broker: %s:%d"), _brokerAddress.c_str(), _brokerPort);
}

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

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

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

ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeMqttTopics()
{
if (!_mqttClient.subscribe(_dataTopicIn))
{
DBG_ERROR("ArduinoIoTCloudTCP::%s could not subscribe to %s", __FUNCTION__, _dataTopicIn.c_str());
DBG_ERROR(F("ArduinoIoTCloudTCP::%s could not subscribe to %s"), __FUNCTION__, _dataTopicIn.c_str());
return State::SubscribeMqttTopics;
}

if (_shadowTopicIn != "")
{
if (!_mqttClient.subscribe(_shadowTopicIn))
{
DBG_ERROR("ArduinoIoTCloudTCP::%s could not subscribe to %s", __FUNCTION__, _shadowTopicIn.c_str());
DBG_ERROR(F("ArduinoIoTCloudTCP::%s could not subscribe to %s"), __FUNCTION__, _shadowTopicIn.c_str());
return State::SubscribeMqttTopics;
}
}

DBG_INFO("Connected to Arduino IoT Cloud");
DBG_INFO(F("Connected to Arduino IoT Cloud"));
execCloudEventCallback(ArduinoIoTCloudEvent::CONNECT);

if (_shadowTopicIn != "")
Expand All @@ -246,7 +246,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_RequestLastValues()
unsigned long const now = millis();
if ((now - _lastSyncRequestTickTime) > TIMEOUT_FOR_LASTVALUES_SYNC)
{
DBG_VERBOSE("ArduinoIoTCloudTCP::%s [%d] last values requested", __FUNCTION__, now);
DBG_VERBOSE(F("ArduinoIoTCloudTCP::%s [%d] last values requested"), __FUNCTION__, now);
requestLastValue();
_lastSyncRequestTickTime = now;
}
Expand All @@ -258,7 +258,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
{
if (!_mqttClient.connected())
{
DBG_ERROR("ArduinoIoTCloudTCP::%s MQTT client connection lost", __FUNCTION__);
DBG_ERROR(F("ArduinoIoTCloudTCP::%s MQTT client connection lost"), __FUNCTION__);

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

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

void ArduinoIoTCloudTCP::onOTARequest()
{
DBG_VERBOSE("ArduinoIoTCloudTCP::%s _ota_req = %s", __FUNCTION__, _ota_req ? "true" : "false");
DBG_VERBOSE("ArduinoIoTCloudTCP::%s _ota_url = %s", __FUNCTION__, _ota_url.c_str());
DBG_VERBOSE(F("ArduinoIoTCloudTCP::%s _ota_req = %s"), __FUNCTION__, _ota_req ? "true" : "false");
DBG_VERBOSE(F("ArduinoIoTCloudTCP::%s _ota_url = %s"), __FUNCTION__, _ota_url.c_str());

if (_ota_req)
{
Expand All @@ -398,7 +398,7 @@ void ArduinoIoTCloudTCP::onOTARequest()
uint8_t nina_ota_err_code = 0;
if (!WiFiStorage.downloadOTA(_ota_url.c_str(), &nina_ota_err_code))
{
DBG_ERROR("ArduinoIoTCloudTCP::%s error download to nina: %d", __FUNCTION__, nina_ota_err_code);
DBG_ERROR(F("ArduinoIoTCloudTCP::%s error download to nina: %d"), __FUNCTION__, nina_ota_err_code);
_ota_error = static_cast<int>(OTAError::DownloadFailed);
return;
}
Expand Down

0 comments on commit a284622

Please sign in to comment.