From 8ea22f1273a3638c76d8ae07fe4065e940a60ed2 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Fri, 21 Aug 2020 07:06:53 +0200 Subject: [PATCH] Use flash strings for storing debug messages in order to conserve RAM --- src/Arduino_GSMConnectionHandler.cpp | 20 +++++++-------- src/Arduino_LoRaConnectionHandler.cpp | 36 +++++++++++++-------------- src/Arduino_NBConnectionHandler.cpp | 18 +++++++------- src/Arduino_WiFiConnectionHandler.cpp | 26 +++++++++---------- 4 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/Arduino_GSMConnectionHandler.cpp b/src/Arduino_GSMConnectionHandler.cpp index 629699b6..67afa14f 100644 --- a/src/Arduino_GSMConnectionHandler.cpp +++ b/src/Arduino_GSMConnectionHandler.cpp @@ -60,19 +60,19 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit() { if (_gsm.begin(_pin) != GSM_READY) { - Debug.print(DBG_ERROR, "SIM not present or wrong PIN"); + Debug.print(DBG_ERROR, F("SIM not present or wrong PIN")); return NetworkConnectionState::ERROR; } - Debug.print(DBG_INFO, "SIM card ok"); + Debug.print(DBG_INFO, F("SIM card ok")); _gsm.setTimeout(GSM_TIMEOUT); GSM3_NetworkStatus_t const network_status = _gprs.attachGPRS(_apn, _login, _pass, true); - Debug.print(DBG_DEBUG, "GPRS.attachGPRS(): %d", network_status); + Debug.print(DBG_DEBUG, F("GPRS.attachGPRS(): %d"), network_status); if (network_status == GSM3_NetworkStatus_t::ERROR) { - Debug.print(DBG_ERROR, "GPRS attach failed"); - Debug.print(DBG_ERROR, "Make sure the antenna is connected and reset your board."); + Debug.print(DBG_ERROR, F("GPRS attach failed")); + Debug.print(DBG_ERROR, F("Make sure the antenna is connected and reset your board.")); return NetworkConnectionState::ERROR; } @@ -81,18 +81,18 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit() NetworkConnectionState GSMConnectionHandler::update_handleConnecting() { - Debug.print(DBG_INFO, "Sending PING to outer space..."); + Debug.print(DBG_INFO, F("Sending PING to outer space...")); int const ping_result = _gprs.ping("time.arduino.cc"); - Debug.print(DBG_INFO, "GPRS.ping(): %d", ping_result); + Debug.print(DBG_INFO, F("GPRS.ping(): %d"), ping_result); if (ping_result < 0) { - Debug.print(DBG_ERROR, "PING failed"); - Debug.print(DBG_INFO, "Retrying in \"%d\" milliseconds", CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); + Debug.print(DBG_ERROR, F("PING failed")); + Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); return NetworkConnectionState::CONNECTING; } else { - Debug.print(DBG_INFO, "Connected to GPRS Network"); + Debug.print(DBG_INFO, F("Connected to GPRS Network")); return NetworkConnectionState::CONNECTED; } } diff --git a/src/Arduino_LoRaConnectionHandler.cpp b/src/Arduino_LoRaConnectionHandler.cpp index d3b86c97..c0183e3e 100644 --- a/src/Arduino_LoRaConnectionHandler.cpp +++ b/src/Arduino_LoRaConnectionHandler.cpp @@ -68,20 +68,20 @@ int LoRaConnectionHandler::write(const uint8_t * buf, size_t size) { switch (err) { - case LoRaCommunicationError::LORA_ERROR_ACK_NOT_RECEIVED: Debug.print(DBG_ERROR, "Message ack was not received, the message could not be delivered"); break; - case LoRaCommunicationError::LORA_ERROR_GENERIC: Debug.print(DBG_ERROR, "LoRa generic error (LORA_ERROR)"); break; - case LoRaCommunicationError::LORA_ERROR_WRONG_PARAM: Debug.print(DBG_ERROR, "LoRa malformed param error (LORA_ERROR_PARAM"); break; - case LoRaCommunicationError::LORA_ERROR_COMMUNICATION_BUSY: Debug.print(DBG_ERROR, "LoRa chip is busy (LORA_ERROR_BUSY)"); break; - case LoRaCommunicationError::LORA_ERROR_MESSAGE_OVERFLOW: Debug.print(DBG_ERROR, "LoRa chip overflow error (LORA_ERROR_OVERFLOW)"); break; - case LoRaCommunicationError::LORA_ERROR_NO_NETWORK_AVAILABLE: Debug.print(DBG_ERROR, "LoRa no network error (LORA_ERROR_NO_NETWORK)"); break; - case LoRaCommunicationError::LORA_ERROR_RX_PACKET: Debug.print(DBG_ERROR, "LoRa rx error (LORA_ERROR_RX)"); break; - case LoRaCommunicationError::LORA_ERROR_REASON_UNKNOWN: Debug.print(DBG_ERROR, "LoRa unknown error (LORA_ERROR_UNKNOWN)"); break; - case LoRaCommunicationError::LORA_ERROR_MAX_PACKET_SIZE: Debug.print(DBG_ERROR, "Message length is bigger than max LoRa packet!"); break; + case LoRaCommunicationError::LORA_ERROR_ACK_NOT_RECEIVED: Debug.print(DBG_ERROR, F("Message ack was not received, the message could not be delivered")); break; + case LoRaCommunicationError::LORA_ERROR_GENERIC: Debug.print(DBG_ERROR, F("LoRa generic error (LORA_ERROR)")); break; + case LoRaCommunicationError::LORA_ERROR_WRONG_PARAM: Debug.print(DBG_ERROR, F("LoRa malformed param error (LORA_ERROR_PARAM")); break; + case LoRaCommunicationError::LORA_ERROR_COMMUNICATION_BUSY: Debug.print(DBG_ERROR, F("LoRa chip is busy (LORA_ERROR_BUSY)")); break; + case LoRaCommunicationError::LORA_ERROR_MESSAGE_OVERFLOW: Debug.print(DBG_ERROR, F("LoRa chip overflow error (LORA_ERROR_OVERFLOW)")); break; + case LoRaCommunicationError::LORA_ERROR_NO_NETWORK_AVAILABLE: Debug.print(DBG_ERROR, F("LoRa no network error (LORA_ERROR_NO_NETWORK)")); break; + case LoRaCommunicationError::LORA_ERROR_RX_PACKET: Debug.print(DBG_ERROR, F("LoRa rx error (LORA_ERROR_RX)")); break; + case LoRaCommunicationError::LORA_ERROR_REASON_UNKNOWN: Debug.print(DBG_ERROR, F("LoRa unknown error (LORA_ERROR_UNKNOWN)")); break; + case LoRaCommunicationError::LORA_ERROR_MAX_PACKET_SIZE: Debug.print(DBG_ERROR, F("Message length is bigger than max LoRa packet!")); break; } } else { - Debug.print(DBG_INFO, "Message sent correctly!"); + Debug.print(DBG_INFO, F("Message sent correctly!")); } return err; } @@ -104,14 +104,14 @@ NetworkConnectionState LoRaConnectionHandler::update_handleInit() { if (!_modem.begin(_band)) { - Debug.print(DBG_ERROR, "Something went wrong; are you indoor? Move near a window, then reset and retry."); + Debug.print(DBG_ERROR, F("Something went wrong; are you indoor? Move near a window, then reset and retry.")); return NetworkConnectionState::ERROR; } //A delay is required between _modem.begin(band) and _modem.joinOTAA(appeui, appkey) in order to let the chip to be correctly initialized before the connection attempt delay(100); _modem.configureClass(_device_class); delay(100); - Debug.print(DBG_INFO, "Connecting to the network"); + Debug.print(DBG_INFO, F("Connecting to the network")); return NetworkConnectionState::CONNECTING; } @@ -120,12 +120,12 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnecting() bool const network_status = _modem.joinOTAA(_appeui, _appkey); if (network_status != true) { - Debug.print(DBG_ERROR, "Something went wrong; are you indoor? Move near a window, then reset and retry."); + Debug.print(DBG_ERROR, F("Something went wrong; are you indoor? Move near a window, then reset and retry.")); return NetworkConnectionState::ERROR; } else { - Debug.print(DBG_INFO, "Connected to the network"); + Debug.print(DBG_INFO, F("Connected to the network")); return NetworkConnectionState::CONNECTED; } } @@ -135,10 +135,10 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnected() bool const network_status = _modem.connected(); if (network_status != true) { - Debug.print(DBG_ERROR, "Connection to the network lost."); + Debug.print(DBG_ERROR, F("Connection to the network lost.")); if (_keep_alive) { - Debug.print(DBG_ERROR, "Attempting reconnection"); + Debug.print(DBG_ERROR, F("Attempting reconnection")); } return NetworkConnectionState::DISCONNECTED; } @@ -147,10 +147,10 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnected() NetworkConnectionState LoRaConnectionHandler::update_handleDisconnecting() { - Debug.print(DBG_ERROR, "Connection to the network lost."); + Debug.print(DBG_ERROR, F("Connection to the network lost.")); if (_keep_alive) { - Debug.print(DBG_ERROR, "Attempting reconnection"); + Debug.print(DBG_ERROR, F("Attempting reconnection")); } return NetworkConnectionState::DISCONNECTED; } diff --git a/src/Arduino_NBConnectionHandler.cpp b/src/Arduino_NBConnectionHandler.cpp index b3c719dd..a4d8765b 100644 --- a/src/Arduino_NBConnectionHandler.cpp +++ b/src/Arduino_NBConnectionHandler.cpp @@ -71,13 +71,13 @@ NetworkConnectionState NBConnectionHandler::update_handleInit() { if (_nb.begin(_pin, _apn, _login, _pass) == NB_READY) { - Debug.print(DBG_INFO, "SIM card ok"); + Debug.print(DBG_INFO, F("SIM card ok")); _nb.setTimeout(NB_TIMEOUT); return NetworkConnectionState::CONNECTING; } else { - Debug.print(DBG_ERROR, "SIM not present or wrong PIN"); + Debug.print(DBG_ERROR, F("SIM not present or wrong PIN")); return NetworkConnectionState::ERROR; } } @@ -85,15 +85,15 @@ NetworkConnectionState NBConnectionHandler::update_handleInit() NetworkConnectionState NBConnectionHandler::update_handleConnecting() { NB_NetworkStatus_t const network_status = _nb_gprs.attachGPRS(true); - Debug.print(DBG_DEBUG, "GPRS.attachGPRS(): %d", network_status); + Debug.print(DBG_DEBUG, F("GPRS.attachGPRS(): %d"), network_status); if (network_status == NB_NetworkStatus_t::ERROR) { - Debug.print(DBG_ERROR, "GPRS.attachGPRS() failed"); + Debug.print(DBG_ERROR, F("GPRS.attachGPRS() failed")); return NetworkConnectionState::ERROR; } else { - Debug.print(DBG_INFO, "Connected to GPRS Network"); + Debug.print(DBG_INFO, F("Connected to GPRS Network")); return NetworkConnectionState::CONNECTED; } } @@ -101,22 +101,22 @@ NetworkConnectionState NBConnectionHandler::update_handleConnecting() NetworkConnectionState NBConnectionHandler::update_handleConnected() { int const nb_is_access_alive = _nb.isAccessAlive(); - Debug.print(DBG_VERBOSE, "GPRS.isAccessAlive(): %d", nb_is_access_alive); + Debug.print(DBG_VERBOSE, F("GPRS.isAccessAlive(): %d"), nb_is_access_alive); if (nb_is_access_alive != 1) { - Debug.print(DBG_INFO, "Disconnected from cellular network"); + Debug.print(DBG_INFO, F("Disconnected from cellular network")); return NetworkConnectionState::DISCONNECTED; } else { - Debug.print(DBG_VERBOSE, "Connected to Cellular Network"); + Debug.print(DBG_VERBOSE, F("Connected to Cellular Network")); return NetworkConnectionState::CONNECTED; } } NetworkConnectionState NBConnectionHandler::update_handleDisconnecting() { - Debug.print(DBG_VERBOSE, "Disconnecting from Cellular Network"); + Debug.print(DBG_VERBOSE, F("Disconnecting from Cellular Network")); _nb.shutdown(); return NetworkConnectionState::DISCONNECTED; } diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 728bc062..8cfb2f06 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -55,27 +55,27 @@ unsigned long WiFiConnectionHandler::getTime() NetworkConnectionState WiFiConnectionHandler::update_handleInit() { #ifndef BOARD_ESP8266 - Debug.print(DBG_INFO, "WiFi.status(): %d", WiFi.status()); + Debug.print(DBG_INFO, F("WiFi.status(): %d"), WiFi.status()); if (WiFi.status() == NETWORK_HARDWARE_ERROR) { - Debug.print(DBG_ERROR, "WiFi Hardware failure.\nMake sure you are using a WiFi enabled board/shield."); - Debug.print(DBG_ERROR, "Then reset and retry."); + Debug.print(DBG_ERROR, F("WiFi Hardware failure.\nMake sure you are using a WiFi enabled board/shield.")); + Debug.print(DBG_ERROR, F("Then reset and retry.")); return NetworkConnectionState::ERROR; } - Debug.print(DBG_ERROR, "Current WiFi Firmware: %s", WiFi.firmwareVersion()); + Debug.print(DBG_ERROR, F("Current WiFi Firmware: %s"), WiFi.firmwareVersion()); #if defined(WIFI_FIRMWARE_VERSION_REQUIRED) if (WiFi.firmwareVersion() < WIFI_FIRMWARE_VERSION_REQUIRED) { - Debug.print(DBG_ERROR, "Latest WiFi Firmware: %s", WIFI_FIRMWARE_VERSION_REQUIRED); - Debug.print(DBG_ERROR, "Please update to the latest version for best performance."); + Debug.print(DBG_ERROR, F("Latest WiFi Firmware: %s"), WIFI_FIRMWARE_VERSION_REQUIRED); + Debug.print(DBG_ERROR, F("Please update to the latest version for best performance.")); delay(5000); } #endif #else - Debug.print(DBG_ERROR, "WiFi status ESP: %d", WiFi.status()); + Debug.print(DBG_ERROR, F("WiFi status ESP: %d"), WiFi.status()); WiFi.disconnect(); delay(300); WiFi.begin(_ssid, _pass); @@ -96,13 +96,13 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() if (WiFi.status() != NETWORK_CONNECTED) { - Debug.print(DBG_ERROR, "Connection to \"%s\" failed", _ssid); - Debug.print(DBG_INFO, "Retrying in \"%d\" milliseconds", CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); + Debug.print(DBG_ERROR, F("Connection to \"%s\" failed"), _ssid); + Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); return NetworkConnectionState::CONNECTING; } else { - Debug.print(DBG_INFO, "Connected to \"%s\"", _ssid); + Debug.print(DBG_INFO, F("Connected to \"%s\""), _ssid); #ifdef BOARD_ESP8266 configTime(0, 0, "time.arduino.cc", "pool.ntp.org", "time.nist.gov"); #endif @@ -114,12 +114,12 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnected() { if (WiFi.status() != WL_CONNECTED) { - Debug.print(DBG_VERBOSE, "WiFi.status(): %d", WiFi.status()); - Debug.print(DBG_ERROR, "Connection to \"%s\" lost.", _ssid); + Debug.print(DBG_VERBOSE, F("WiFi.status(): %d"), WiFi.status()); + Debug.print(DBG_ERROR, F("Connection to \"%s\" lost."), _ssid); if (_keep_alive) { - Debug.print(DBG_ERROR, "Attempting reconnection"); + Debug.print(DBG_ERROR, F("Attempting reconnection")); } return NetworkConnectionState::DISCONNECTED;