Skip to content

Commit d2b190a

Browse files
maidnlfacchinm
authored andcommitted
added selectable debug to modem
1 parent 5196c1c commit d2b190a

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

libraries/WiFiS3/examples/WiFiWebClient/WiFiWebClient.ino

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
*/
1919

2020

21-
#include "WiFi.h"
22-
#include "WiFiClient.h"
23-
#include "IPAddress.h"
21+
#include "WiFiS3.h"
22+
2423

2524
#include "arduino_secrets.h"
2625

@@ -44,7 +43,7 @@ WiFiClient client;
4443
void setup() {
4544
/* -------------------------------------------------------------------------- */
4645
//Initialize serial and wait for port to open:
47-
Serial.begin(115200);
46+
Serial.begin(9600);
4847
while (!Serial) {
4948
; // wait for serial port to connect. Needed for native USB port only
5049
}
@@ -57,7 +56,7 @@ void setup() {
5756
}
5857

5958
String fv = WiFi.firmwareVersion();
60-
if (fv < WiFi_FIRMWARE_LATEST_VERSION) {
59+
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
6160
Serial.println("Please upgrade the firmware");
6261
}
6362

libraries/WiFiS3/src/Modem.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,24 @@ bool ModemClass::buf_read(const string &prompt, string &data_res) {
193193
while( _serial->available() ){
194194
char c = _serial->read();
195195
data_res += c;
196+
#ifdef SELECTABLE_MODEM_DEBUG
197+
if(enable_dbg) {
198+
Serial.print(c);
199+
}
200+
#endif
196201

197202
if(read_by_size) {
198203
if(read_by_size_finished(data_res)) {
199204
found = true;
200205
read_by_size = false;
201206
res = true;
202-
data_res = data_res.substr(0, data_res.length() - sizeof(RESULT_OK));
207+
data_res = data_res.substr(0, data_res.length() - (sizeof(RESULT_OK) - 1));
203208
}
204209
}
205210
else {
206211
if(string::npos != data_res.rfind(RESULT_DATA)) {
207212
found = true;
208-
data_res = data_res.substr(0, data_res.length() - sizeof(RESULT_DATA));
213+
data_res = data_res.substr(0, data_res.length() - (sizeof(RESULT_DATA) - 1));
209214
if(prompt != DO_NOT_CHECK_CMD) {
210215
if(removeAtBegin(data_res, prompt)) {
211216
res = true;
@@ -218,7 +223,7 @@ bool ModemClass::buf_read(const string &prompt, string &data_res) {
218223
}
219224
else if(string::npos != data_res.rfind(RESULT_OK)){
220225
found = true;
221-
data_res = data_res.substr(0, data_res.length() - sizeof(RESULT_OK));
226+
data_res = data_res.substr(0, data_res.length() - (sizeof(RESULT_OK) - 1) );
222227
if(prompt != DO_NOT_CHECK_CMD) {
223228
if(removeAtBegin(data_res, prompt)) {
224229
res = true;
@@ -230,7 +235,7 @@ bool ModemClass::buf_read(const string &prompt, string &data_res) {
230235
break;
231236
}
232237
else if (string::npos != data_res.rfind(RESULT_ERROR)) {
233-
data_res.substr(0, data_res.length() - sizeof(RESULT_ERROR));
238+
data_res.substr(0, data_res.length() - (sizeof(RESULT_ERROR) - 1));
234239
res = false;
235240
break;
236241
}

libraries/WiFiS3/src/Modem.h

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//#define MODEM_DEBUG
1010
//#define MODEM_DEBUG_PASSTHROUGH
1111
#define MODEM_TIMEOUT 10000
12+
//#define SELECTABLE_MODEM_DEBUG
1213
#define MAX_BUFF_SIZE 64
1314

1415
#define DO_NOT_CHECK_CMD "NO_CMD_CHECK"
@@ -39,6 +40,11 @@ class ModemClass {
3940
}
4041
bool beginned;
4142

43+
#ifdef SELECTABLE_MODEM_DEBUG
44+
bool enable_dbg = false;
45+
void debug(bool e) {enable_dbg = e;}
46+
#endif
47+
4248
private:
4349
bool buf_read(const string &cmd, string &data_res);
4450
bool delete_serial;

0 commit comments

Comments
 (0)