Skip to content

Use flash strings for storing debug messages in order to conserve RAM #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/Arduino_GSMConnectionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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<unsigned int>(NetworkConnectionState::CONNECTING)]);
Debug.print(DBG_ERROR, F("PING failed"));
Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast<unsigned int>(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;
}
}
Expand Down
36 changes: 18 additions & 18 deletions src/Arduino_LoRaConnectionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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;
}
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
18 changes: 9 additions & 9 deletions src/Arduino_NBConnectionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,52 +71,52 @@ 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;
}
}

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;
}
}

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;
}
Expand Down
26 changes: 13 additions & 13 deletions src/Arduino_WiFiConnectionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<unsigned int>(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<unsigned int>(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
Expand All @@ -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;
Expand Down