From 8e297d005f6d23482585ba3e969d63fe7b9a3de0 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Mon, 2 Dec 2024 14:18:01 +0100 Subject: [PATCH 1/2] Added the possibility to get the modem answer from a passthrough call --- libraries/WiFiS3/src/Modem.cpp | 6 +++++- libraries/WiFiS3/src/Modem.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/WiFiS3/src/Modem.cpp b/libraries/WiFiS3/src/Modem.cpp index 7aa34391..b3e4038b 100644 --- a/libraries/WiFiS3/src/Modem.cpp +++ b/libraries/WiFiS3/src/Modem.cpp @@ -48,13 +48,17 @@ void ModemClass::end(){ } /* -------------------------------------------------------------------------- */ -bool ModemClass::passthrough(const uint8_t *data, size_t size) { +bool ModemClass::passthrough(const uint8_t *data, size_t size, std::string *response) { /* -------------------------------------------------------------------------- */ _serial->write(data,size); std::string prompt = DO_NOT_CHECK_CMD, data_res; auto res = buf_read(prompt, data_res); + if(response != nullptr) { + *response = data_res; + } + if(_serial_debug && _debug_level >= 2) { _serial_debug->print(" ANSWER (passthrough): "); _serial_debug->println(data_res.c_str()); diff --git a/libraries/WiFiS3/src/Modem.h b/libraries/WiFiS3/src/Modem.h index 3f785bc9..f417cfb5 100644 --- a/libraries/WiFiS3/src/Modem.h +++ b/libraries/WiFiS3/src/Modem.h @@ -27,7 +27,7 @@ class ModemClass { bool write(const std::string &cmd, std::string &str, const char * fmt, ...); void write_nowait(const std::string &cmd, std::string &str, const char * fmt, ...); - bool passthrough(const uint8_t *data, size_t size); + bool passthrough(const uint8_t *data, size_t size, std::string *response=nullptr); void avoid_trim_results() { /* one shot - it works only 1 time the it is necessary to call again this funtion */ From 76ff27d37d07dd050e3fda75b5a82d75956843a4 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Mon, 2 Dec 2024 14:20:02 +0100 Subject: [PATCH 2/2] [preferences] returning the response of the modem when putting bytes --- libraries/Preferences/src/Preferences.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Preferences/src/Preferences.cpp b/libraries/Preferences/src/Preferences.cpp index 3e689c95..7ad494fe 100644 --- a/libraries/Preferences/src/Preferences.cpp +++ b/libraries/Preferences/src/Preferences.cpp @@ -178,8 +178,8 @@ size_t Preferences::putBytes(const char* key, const void* value, size_t len) { string res = ""; if ( key != nullptr && strlen(key) > 0 && value != nullptr && len > 0) { modem.write_nowait(string(PROMPT(_PREF_PUT)), res, "%s%s,%d,%d\r\n", CMD_WRITE(_PREF_PUT), key, PT_BLOB, len); - if(modem.passthrough((uint8_t *)value, len)) { - return len; + if(modem.passthrough((uint8_t *)value, len, &res)) { + return atoi(res.c_str()); } } return 0;