Skip to content

Commit

Permalink
fix(ppp): Make modem reset delay configurable
Browse files Browse the repository at this point in the history
The delay required to reset Simcom modem modules varies significantly across
different models, even where they have otherwise identical AT command
sets.

Simcom A7672 was failing to reset with the default 200ms delay. Make the reset
delay configurable to allow customising this for a specific modem.
Default delay, if not specified is kept at 200ms.
  • Loading branch information
tl-sl committed Jun 20, 2024
1 parent 1079f4c commit f407853
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
19 changes: 10 additions & 9 deletions libraries/PPP/examples/PPP_Basic/PPP_Basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#define PPP_MODEM_PIN "0000" // or NULL

// WaveShare SIM7600 HW Flow Control
#define PPP_MODEM_RST 25
#define PPP_MODEM_RST_LOW false //active HIGH
#define PPP_MODEM_TX 21
#define PPP_MODEM_RX 22
#define PPP_MODEM_RTS 26
#define PPP_MODEM_CTS 27
#define PPP_MODEM_FC ESP_MODEM_FLOW_CONTROL_HW
#define PPP_MODEM_MODEL PPP_MODEM_SIM7600
#define PPP_MODEM_RST 25
#define PPP_MODEM_RST_LOW false //active HIGH
#define PPP_MODEM_RST_DELAY 200
#define PPP_MODEM_TX 21
#define PPP_MODEM_RX 22
#define PPP_MODEM_RTS 26
#define PPP_MODEM_CTS 27
#define PPP_MODEM_FC ESP_MODEM_FLOW_CONTROL_HW
#define PPP_MODEM_MODEL PPP_MODEM_SIM7600

// SIM800 basic module with just TX,RX and RST
// #define PPP_MODEM_RST 0
Expand Down Expand Up @@ -60,7 +61,7 @@ void setup() {
// Configure the modem
PPP.setApn(PPP_MODEM_APN);
PPP.setPin(PPP_MODEM_PIN);
PPP.setResetPin(PPP_MODEM_RST, PPP_MODEM_RST_LOW);
PPP.setResetPin(PPP_MODEM_RST, PPP_MODEM_RST_LOW, PPP_MODEM_RST_DELAY);
PPP.setPins(PPP_MODEM_TX, PPP_MODEM_RX, PPP_MODEM_RTS, PPP_MODEM_CTS, PPP_MODEM_FC);

Serial.println("Starting the modem. It might take a while!");
Expand Down
9 changes: 5 additions & 4 deletions libraries/PPP/src/PPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ esp_modem_dce_t *PPPClass::handle() const {
}

PPPClass::PPPClass()
: _dce(NULL), _pin_tx(-1), _pin_rx(-1), _pin_rts(-1), _pin_cts(-1), _flow_ctrl(ESP_MODEM_FLOW_CONTROL_NONE), _pin_rst(-1), _pin_rst_act_low(true), _pin(NULL),
_apn(NULL), _rx_buffer_size(4096), _tx_buffer_size(512), _mode(ESP_MODEM_MODE_COMMAND), _uart_num(UART_NUM_1) {}
: _dce(NULL), _pin_tx(-1), _pin_rx(-1), _pin_rts(-1), _pin_cts(-1), _flow_ctrl(ESP_MODEM_FLOW_CONTROL_NONE), _pin_rst(-1), _pin_rst_act_low(true),
_pin_rst_delay(200), _pin(NULL), _apn(NULL), _rx_buffer_size(4096), _tx_buffer_size(512), _mode(ESP_MODEM_MODE_COMMAND), _uart_num(UART_NUM_1) {}

PPPClass::~PPPClass() {}

Expand All @@ -152,9 +152,10 @@ bool PPPClass::pppDetachBus(void *bus_pointer) {
return true;
}

void PPPClass::setResetPin(int8_t rst, bool active_low) {
void PPPClass::setResetPin(int8_t rst, bool active_low, int16_t reset_delay) {
_pin_rst = digitalPinToGPIONumber(rst);
_pin_rst_act_low = active_low;
_pin_rst_delay = reset_delay;
}

bool PPPClass::setPins(int8_t tx, int8_t rx, int8_t rts, int8_t cts, esp_modem_flow_ctrl_t flow_ctrl) {
Expand Down Expand Up @@ -285,7 +286,7 @@ bool PPPClass::begin(ppp_modem_model_t model, uint8_t uart_num, int baud_rate) {
}
perimanSetPinBusExtraType(_pin_rst, "PPP_MODEM_RST");
digitalWrite(_pin_rst, !_pin_rst_act_low);
delay(200);
delay(_pin_rst_delay);
digitalWrite(_pin_rst, _pin_rst_act_low);
delay(100);
}
Expand Down
3 changes: 2 additions & 1 deletion libraries/PPP/src/PPP.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PPPClass : public NetworkInterface {
bool setPins(int8_t tx, int8_t rx, int8_t rts = -1, int8_t cts = -1, esp_modem_flow_ctrl_t flow_ctrl = ESP_MODEM_FLOW_CONTROL_NONE);

// Using the reset pin of the module ensures that proper communication can be achieved
void setResetPin(int8_t rst, bool active_low = true);
void setResetPin(int8_t rst, bool active_low = true, int16_t reset_delay = 200);

// Modem DCE APIs
int RSSI() const;
Expand Down Expand Up @@ -94,6 +94,7 @@ class PPPClass : public NetworkInterface {
esp_modem_flow_ctrl_t _flow_ctrl;
int8_t _pin_rst;
bool _pin_rst_act_low;
int16_t _pin_rst_delay;
const char *_pin;
const char *_apn;
int _rx_buffer_size;
Expand Down

0 comments on commit f407853

Please sign in to comment.