Skip to content
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@ If you are using an `ESP32` platform, you can enable the native `ESP_LOGX()` log
#include "SIM7600Modem.h"
```

If you need verbose error codes (`+CME ERROR:` and `+CMS ERROR:`), you can define the
`SIM7600_LOG_VERBOSE_ERROR_CODES` macro. You need to set the log level to `1` (ERROR) or higher:

```cpp
// Enable verbose error codes
#define SIM7600_LOG_VERBOSE_ERROR_CODES
#define SIM7600_LOG_LEVEL 3
#include "SIM7600Modem.h"
```

If you need a custom log function, you can define the `SIM7600_LOG_CUSTOM` to a custom function with the
following signature:

Expand Down Expand Up @@ -317,6 +327,7 @@ build_flags =
-DSIM7600_LOG_BUFFER_SIZE_B=512
-DSIM7600_USE_ESP32_LOGS
-DSIM7600_LOG_CUSTOM=logFunction
-DSIM7600_LOG_VERBOSE_ERROR_CODES
```

## Modem features
Expand Down
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ build_flags =
-DARDUINO_USB_CDC_ON_BOOT=1

; Enable library debug (for ESP32)
-DSIM7600_LOG_LEVEL=5
-DSIM7600_LOG_LEVEL=5
-DSIM7600_LOG_VERBOSE_ERROR_CODES
5 changes: 5 additions & 0 deletions src/SIM7600Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
#define SIM7600_LOG_STREAM Serial
#endif

// Enable verbose error codes, only printed when log level is ERROR or higher
#ifndef SIM7600_LOG_VERBOSE_ERROR_CODES
#define SIM7600_LOG_VERBOSE_ERROR_CODES 0
#endif

// Log buffer size
#ifndef SIM7600_LOG_BUFFER_SIZE_B
#define SIM7600_LOG_BUFFER_SIZE_B 256
Expand Down
39 changes: 29 additions & 10 deletions src/SIM7600Modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,17 @@ Status Modem::init(const char* pin, const uint32_t timeout_ms) {
status = sendATCmdAndWaitResp("ATE0", AT_OK);
if (status != Status::Success) return status;

#if SIM7600_LOG_VERBOSE_ERROR_CODES
// Enable verbose errors
SIM7600_LOGD(tag, "Enabling verbose errors");
status = sendATCmdAndWaitResp("AT+CMEE=2", AT_OK);
if (status != Status::Success) return status;
#else
// Disable verbose errors
SIM7600_LOGD(tag, "Disabling verbose errors");
status = sendATCmdAndWaitResp("AT+CMEE=0", AT_OK);
if (status != Status::Success) return status;
#endif

// Enable CGREG URCs
SIM7600_LOGD(tag, "Enabling CGREG URCs");
Expand Down Expand Up @@ -201,11 +208,8 @@ Status Modem::waitForResponse(const char* expected_response, const uint32_t time
return Status::Success;
}

// Error response
if (strcmp(_rx_buf, AT_ERROR) == 0) {
SIM7600_LOGW(tag, "Received AT error response");
return Status::Error;
}
// Check for error response
if (_receivedErrorResponse()) return Status::Error;
}

SIM7600_LOGE(tag, "Timed out expecting response");
Expand Down Expand Up @@ -235,11 +239,8 @@ Status Modem::waitForResponses(const char** expected_responses, const uint8_t re
}
}

// Error response
if (strcmp(_rx_buf, AT_ERROR) == 0) {
SIM7600_LOGW(tag, "Received AT error response");
return Status::Error;
}
// Check for error response
if (_receivedErrorResponse()) return Status::Error;
}

SIM7600_LOGE(tag, "Timed out expecting %u responses", response_count);
Expand Down Expand Up @@ -1197,6 +1198,24 @@ Status Modem::_waitAsyncMQTTResponse(const char* mqtt_response_prefix, uint8_t&
return Status::Success;
}

bool Modem::_receivedErrorResponse() {
#if SIM7600_LOG_VERBOSE_ERROR_CODES
// Verbose error response
if ((strncmp(_rx_buf, "+CME ERROR:", 11) == 0) || (strncmp(_rx_buf, "+CMS ERROR:", 11) == 0)) {
SIM7600_LOGE(tag, "<< [Verbose Error]: %s", _rx_buf);
return true;
}
#endif

// Error response
if (strcmp(_rx_buf, AT_ERROR) == 0) {
SIM7600_LOGW(tag, "Received AT error response");
return true;
}

return false;
}

bool Modem::_handleURCs() {
// First, check registered handlers (TCPClient, MQTTClient)
for (uint8_t i = 0; i < _urc_handler_count; i++) {
Expand Down
1 change: 1 addition & 0 deletions src/SIM7600Modem.h
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ class Modem {
Status _waitPromptAndSendData(const uint8_t* data, const size_t data_length, size_t& bytes_sent,
const uint32_t timeout_ms = SIM7600_MODEM_DEFAULT_TIMEOUT_MS);
Status _waitAsyncMQTTResponse(const char* mqtt_response_prefix, uint8_t& err_code);
bool _receivedErrorResponse();

bool _handleURCs();

Expand Down