Skip to content

Commit e023315

Browse files
authoredAug 26, 2020
Use flash strings for storing debug messages in order to conserve RAM (#39)
1 parent 43b3ee2 commit e023315

4 files changed

+50
-50
lines changed
 

Diff for: ‎src/Arduino_GSMConnectionHandler.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,19 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit()
6060
{
6161
if (_gsm.begin(_pin) != GSM_READY)
6262
{
63-
Debug.print(DBG_ERROR, "SIM not present or wrong PIN");
63+
Debug.print(DBG_ERROR, F("SIM not present or wrong PIN"));
6464
return NetworkConnectionState::ERROR;
6565
}
6666

67-
Debug.print(DBG_INFO, "SIM card ok");
67+
Debug.print(DBG_INFO, F("SIM card ok"));
6868
_gsm.setTimeout(GSM_TIMEOUT);
6969

7070
GSM3_NetworkStatus_t const network_status = _gprs.attachGPRS(_apn, _login, _pass, true);
71-
Debug.print(DBG_DEBUG, "GPRS.attachGPRS(): %d", network_status);
71+
Debug.print(DBG_DEBUG, F("GPRS.attachGPRS(): %d"), network_status);
7272
if (network_status == GSM3_NetworkStatus_t::ERROR)
7373
{
74-
Debug.print(DBG_ERROR, "GPRS attach failed");
75-
Debug.print(DBG_ERROR, "Make sure the antenna is connected and reset your board.");
74+
Debug.print(DBG_ERROR, F("GPRS attach failed"));
75+
Debug.print(DBG_ERROR, F("Make sure the antenna is connected and reset your board."));
7676
return NetworkConnectionState::ERROR;
7777
}
7878

@@ -81,18 +81,18 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit()
8181

8282
NetworkConnectionState GSMConnectionHandler::update_handleConnecting()
8383
{
84-
Debug.print(DBG_INFO, "Sending PING to outer space...");
84+
Debug.print(DBG_INFO, F("Sending PING to outer space..."));
8585
int const ping_result = _gprs.ping("time.arduino.cc");
86-
Debug.print(DBG_INFO, "GPRS.ping(): %d", ping_result);
86+
Debug.print(DBG_INFO, F("GPRS.ping(): %d"), ping_result);
8787
if (ping_result < 0)
8888
{
89-
Debug.print(DBG_ERROR, "PING failed");
90-
Debug.print(DBG_INFO, "Retrying in \"%d\" milliseconds", CHECK_INTERVAL_TABLE[static_cast<unsigned int>(NetworkConnectionState::CONNECTING)]);
89+
Debug.print(DBG_ERROR, F("PING failed"));
90+
Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast<unsigned int>(NetworkConnectionState::CONNECTING)]);
9191
return NetworkConnectionState::CONNECTING;
9292
}
9393
else
9494
{
95-
Debug.print(DBG_INFO, "Connected to GPRS Network");
95+
Debug.print(DBG_INFO, F("Connected to GPRS Network"));
9696
return NetworkConnectionState::CONNECTED;
9797
}
9898
}

Diff for: ‎src/Arduino_LoRaConnectionHandler.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ int LoRaConnectionHandler::write(const uint8_t * buf, size_t size)
6868
{
6969
switch (err)
7070
{
71-
case LoRaCommunicationError::LORA_ERROR_ACK_NOT_RECEIVED: Debug.print(DBG_ERROR, "Message ack was not received, the message could not be delivered"); break;
72-
case LoRaCommunicationError::LORA_ERROR_GENERIC: Debug.print(DBG_ERROR, "LoRa generic error (LORA_ERROR)"); break;
73-
case LoRaCommunicationError::LORA_ERROR_WRONG_PARAM: Debug.print(DBG_ERROR, "LoRa malformed param error (LORA_ERROR_PARAM"); break;
74-
case LoRaCommunicationError::LORA_ERROR_COMMUNICATION_BUSY: Debug.print(DBG_ERROR, "LoRa chip is busy (LORA_ERROR_BUSY)"); break;
75-
case LoRaCommunicationError::LORA_ERROR_MESSAGE_OVERFLOW: Debug.print(DBG_ERROR, "LoRa chip overflow error (LORA_ERROR_OVERFLOW)"); break;
76-
case LoRaCommunicationError::LORA_ERROR_NO_NETWORK_AVAILABLE: Debug.print(DBG_ERROR, "LoRa no network error (LORA_ERROR_NO_NETWORK)"); break;
77-
case LoRaCommunicationError::LORA_ERROR_RX_PACKET: Debug.print(DBG_ERROR, "LoRa rx error (LORA_ERROR_RX)"); break;
78-
case LoRaCommunicationError::LORA_ERROR_REASON_UNKNOWN: Debug.print(DBG_ERROR, "LoRa unknown error (LORA_ERROR_UNKNOWN)"); break;
79-
case LoRaCommunicationError::LORA_ERROR_MAX_PACKET_SIZE: Debug.print(DBG_ERROR, "Message length is bigger than max LoRa packet!"); break;
71+
case LoRaCommunicationError::LORA_ERROR_ACK_NOT_RECEIVED: Debug.print(DBG_ERROR, F("Message ack was not received, the message could not be delivered")); break;
72+
case LoRaCommunicationError::LORA_ERROR_GENERIC: Debug.print(DBG_ERROR, F("LoRa generic error (LORA_ERROR)")); break;
73+
case LoRaCommunicationError::LORA_ERROR_WRONG_PARAM: Debug.print(DBG_ERROR, F("LoRa malformed param error (LORA_ERROR_PARAM")); break;
74+
case LoRaCommunicationError::LORA_ERROR_COMMUNICATION_BUSY: Debug.print(DBG_ERROR, F("LoRa chip is busy (LORA_ERROR_BUSY)")); break;
75+
case LoRaCommunicationError::LORA_ERROR_MESSAGE_OVERFLOW: Debug.print(DBG_ERROR, F("LoRa chip overflow error (LORA_ERROR_OVERFLOW)")); break;
76+
case LoRaCommunicationError::LORA_ERROR_NO_NETWORK_AVAILABLE: Debug.print(DBG_ERROR, F("LoRa no network error (LORA_ERROR_NO_NETWORK)")); break;
77+
case LoRaCommunicationError::LORA_ERROR_RX_PACKET: Debug.print(DBG_ERROR, F("LoRa rx error (LORA_ERROR_RX)")); break;
78+
case LoRaCommunicationError::LORA_ERROR_REASON_UNKNOWN: Debug.print(DBG_ERROR, F("LoRa unknown error (LORA_ERROR_UNKNOWN)")); break;
79+
case LoRaCommunicationError::LORA_ERROR_MAX_PACKET_SIZE: Debug.print(DBG_ERROR, F("Message length is bigger than max LoRa packet!")); break;
8080
}
8181
}
8282
else
8383
{
84-
Debug.print(DBG_INFO, "Message sent correctly!");
84+
Debug.print(DBG_INFO, F("Message sent correctly!"));
8585
}
8686
return err;
8787
}
@@ -104,14 +104,14 @@ NetworkConnectionState LoRaConnectionHandler::update_handleInit()
104104
{
105105
if (!_modem.begin(_band))
106106
{
107-
Debug.print(DBG_ERROR, "Something went wrong; are you indoor? Move near a window, then reset and retry.");
107+
Debug.print(DBG_ERROR, F("Something went wrong; are you indoor? Move near a window, then reset and retry."));
108108
return NetworkConnectionState::ERROR;
109109
}
110110
//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
111111
delay(100);
112112
_modem.configureClass(_device_class);
113113
delay(100);
114-
Debug.print(DBG_INFO, "Connecting to the network");
114+
Debug.print(DBG_INFO, F("Connecting to the network"));
115115
return NetworkConnectionState::CONNECTING;
116116
}
117117

@@ -120,12 +120,12 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnecting()
120120
bool const network_status = _modem.joinOTAA(_appeui, _appkey);
121121
if (network_status != true)
122122
{
123-
Debug.print(DBG_ERROR, "Something went wrong; are you indoor? Move near a window, then reset and retry.");
123+
Debug.print(DBG_ERROR, F("Something went wrong; are you indoor? Move near a window, then reset and retry."));
124124
return NetworkConnectionState::ERROR;
125125
}
126126
else
127127
{
128-
Debug.print(DBG_INFO, "Connected to the network");
128+
Debug.print(DBG_INFO, F("Connected to the network"));
129129
return NetworkConnectionState::CONNECTED;
130130
}
131131
}
@@ -135,10 +135,10 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnected()
135135
bool const network_status = _modem.connected();
136136
if (network_status != true)
137137
{
138-
Debug.print(DBG_ERROR, "Connection to the network lost.");
138+
Debug.print(DBG_ERROR, F("Connection to the network lost."));
139139
if (_keep_alive)
140140
{
141-
Debug.print(DBG_ERROR, "Attempting reconnection");
141+
Debug.print(DBG_ERROR, F("Attempting reconnection"));
142142
}
143143
return NetworkConnectionState::DISCONNECTED;
144144
}
@@ -147,10 +147,10 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnected()
147147

148148
NetworkConnectionState LoRaConnectionHandler::update_handleDisconnecting()
149149
{
150-
Debug.print(DBG_ERROR, "Connection to the network lost.");
150+
Debug.print(DBG_ERROR, F("Connection to the network lost."));
151151
if (_keep_alive)
152152
{
153-
Debug.print(DBG_ERROR, "Attempting reconnection");
153+
Debug.print(DBG_ERROR, F("Attempting reconnection"));
154154
}
155155
return NetworkConnectionState::DISCONNECTED;
156156
}

Diff for: ‎src/Arduino_NBConnectionHandler.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -71,52 +71,52 @@ NetworkConnectionState NBConnectionHandler::update_handleInit()
7171
{
7272
if (_nb.begin(_pin, _apn, _login, _pass) == NB_READY)
7373
{
74-
Debug.print(DBG_INFO, "SIM card ok");
74+
Debug.print(DBG_INFO, F("SIM card ok"));
7575
_nb.setTimeout(NB_TIMEOUT);
7676
return NetworkConnectionState::CONNECTING;
7777
}
7878
else
7979
{
80-
Debug.print(DBG_ERROR, "SIM not present or wrong PIN");
80+
Debug.print(DBG_ERROR, F("SIM not present or wrong PIN"));
8181
return NetworkConnectionState::ERROR;
8282
}
8383
}
8484

8585
NetworkConnectionState NBConnectionHandler::update_handleConnecting()
8686
{
8787
NB_NetworkStatus_t const network_status = _nb_gprs.attachGPRS(true);
88-
Debug.print(DBG_DEBUG, "GPRS.attachGPRS(): %d", network_status);
88+
Debug.print(DBG_DEBUG, F("GPRS.attachGPRS(): %d"), network_status);
8989
if (network_status == NB_NetworkStatus_t::ERROR)
9090
{
91-
Debug.print(DBG_ERROR, "GPRS.attachGPRS() failed");
91+
Debug.print(DBG_ERROR, F("GPRS.attachGPRS() failed"));
9292
return NetworkConnectionState::ERROR;
9393
}
9494
else
9595
{
96-
Debug.print(DBG_INFO, "Connected to GPRS Network");
96+
Debug.print(DBG_INFO, F("Connected to GPRS Network"));
9797
return NetworkConnectionState::CONNECTED;
9898
}
9999
}
100100

101101
NetworkConnectionState NBConnectionHandler::update_handleConnected()
102102
{
103103
int const nb_is_access_alive = _nb.isAccessAlive();
104-
Debug.print(DBG_VERBOSE, "GPRS.isAccessAlive(): %d", nb_is_access_alive);
104+
Debug.print(DBG_VERBOSE, F("GPRS.isAccessAlive(): %d"), nb_is_access_alive);
105105
if (nb_is_access_alive != 1)
106106
{
107-
Debug.print(DBG_INFO, "Disconnected from cellular network");
107+
Debug.print(DBG_INFO, F("Disconnected from cellular network"));
108108
return NetworkConnectionState::DISCONNECTED;
109109
}
110110
else
111111
{
112-
Debug.print(DBG_VERBOSE, "Connected to Cellular Network");
112+
Debug.print(DBG_VERBOSE, F("Connected to Cellular Network"));
113113
return NetworkConnectionState::CONNECTED;
114114
}
115115
}
116116

117117
NetworkConnectionState NBConnectionHandler::update_handleDisconnecting()
118118
{
119-
Debug.print(DBG_VERBOSE, "Disconnecting from Cellular Network");
119+
Debug.print(DBG_VERBOSE, F("Disconnecting from Cellular Network"));
120120
_nb.shutdown();
121121
return NetworkConnectionState::DISCONNECTED;
122122
}

Diff for: ‎src/Arduino_WiFiConnectionHandler.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,27 @@ unsigned long WiFiConnectionHandler::getTime()
5555
NetworkConnectionState WiFiConnectionHandler::update_handleInit()
5656
{
5757
#ifndef BOARD_ESP8266
58-
Debug.print(DBG_INFO, "WiFi.status(): %d", WiFi.status());
58+
Debug.print(DBG_INFO, F("WiFi.status(): %d"), WiFi.status());
5959
if (WiFi.status() == NETWORK_HARDWARE_ERROR)
6060
{
61-
Debug.print(DBG_ERROR, "WiFi Hardware failure.\nMake sure you are using a WiFi enabled board/shield.");
62-
Debug.print(DBG_ERROR, "Then reset and retry.");
61+
Debug.print(DBG_ERROR, F("WiFi Hardware failure.\nMake sure you are using a WiFi enabled board/shield."));
62+
Debug.print(DBG_ERROR, F("Then reset and retry."));
6363
return NetworkConnectionState::ERROR;
6464
}
6565

66-
Debug.print(DBG_ERROR, "Current WiFi Firmware: %s", WiFi.firmwareVersion());
66+
Debug.print(DBG_ERROR, F("Current WiFi Firmware: %s"), WiFi.firmwareVersion());
6767

6868
#if defined(WIFI_FIRMWARE_VERSION_REQUIRED)
6969
if (WiFi.firmwareVersion() < WIFI_FIRMWARE_VERSION_REQUIRED)
7070
{
71-
Debug.print(DBG_ERROR, "Latest WiFi Firmware: %s", WIFI_FIRMWARE_VERSION_REQUIRED);
72-
Debug.print(DBG_ERROR, "Please update to the latest version for best performance.");
71+
Debug.print(DBG_ERROR, F("Latest WiFi Firmware: %s"), WIFI_FIRMWARE_VERSION_REQUIRED);
72+
Debug.print(DBG_ERROR, F("Please update to the latest version for best performance."));
7373
delay(5000);
7474
}
7575
#endif
7676

7777
#else
78-
Debug.print(DBG_ERROR, "WiFi status ESP: %d", WiFi.status());
78+
Debug.print(DBG_ERROR, F("WiFi status ESP: %d"), WiFi.status());
7979
WiFi.disconnect();
8080
delay(300);
8181
WiFi.begin(_ssid, _pass);
@@ -96,13 +96,13 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting()
9696

9797
if (WiFi.status() != NETWORK_CONNECTED)
9898
{
99-
Debug.print(DBG_ERROR, "Connection to \"%s\" failed", _ssid);
100-
Debug.print(DBG_INFO, "Retrying in \"%d\" milliseconds", CHECK_INTERVAL_TABLE[static_cast<unsigned int>(NetworkConnectionState::CONNECTING)]);
99+
Debug.print(DBG_ERROR, F("Connection to \"%s\" failed"), _ssid);
100+
Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast<unsigned int>(NetworkConnectionState::CONNECTING)]);
101101
return NetworkConnectionState::CONNECTING;
102102
}
103103
else
104104
{
105-
Debug.print(DBG_INFO, "Connected to \"%s\"", _ssid);
105+
Debug.print(DBG_INFO, F("Connected to \"%s\""), _ssid);
106106
#ifdef BOARD_ESP8266
107107
configTime(0, 0, "time.arduino.cc", "pool.ntp.org", "time.nist.gov");
108108
#endif
@@ -114,12 +114,12 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnected()
114114
{
115115
if (WiFi.status() != WL_CONNECTED)
116116
{
117-
Debug.print(DBG_VERBOSE, "WiFi.status(): %d", WiFi.status());
118-
Debug.print(DBG_ERROR, "Connection to \"%s\" lost.", _ssid);
117+
Debug.print(DBG_VERBOSE, F("WiFi.status(): %d"), WiFi.status());
118+
Debug.print(DBG_ERROR, F("Connection to \"%s\" lost."), _ssid);
119119

120120
if (_keep_alive)
121121
{
122-
Debug.print(DBG_ERROR, "Attempting reconnection");
122+
Debug.print(DBG_ERROR, F("Attempting reconnection"));
123123
}
124124

125125
return NetworkConnectionState::DISCONNECTED;

0 commit comments

Comments
 (0)
Please sign in to comment.