@@ -147,7 +147,7 @@ PPPClass::PPPClass()
147
147
,_pin_rst_act_low(true )
148
148
,_pin(NULL )
149
149
,_apn(NULL )
150
- ,_rx_buffer_size(1024 )
150
+ ,_rx_buffer_size(4096 )
151
151
,_tx_buffer_size(512 )
152
152
,_mode(ESP_MODEM_MODE_COMMAND)
153
153
{
@@ -232,18 +232,6 @@ bool PPPClass::begin(ppp_modem_model_t model){
232
232
return false ;
233
233
}
234
234
235
- if (_pin_rst >= 0 ){
236
- if (_pin_rst_act_low){
237
- pinMode (_pin_rst, OUTPUT_OPEN_DRAIN);
238
- } else {
239
- pinMode (_pin_rst, OUTPUT);
240
- }
241
- digitalWrite (_pin_rst, !_pin_rst_act_low);
242
- delay (200 );
243
- digitalWrite (_pin_rst, _pin_rst_act_low);
244
- delay (200 );
245
- }
246
-
247
235
Network.begin ();
248
236
_esp_modem = this ;
249
237
if (_ppp_ev_instance == NULL && esp_event_handler_instance_register (NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &_ppp_event_cb, NULL , &_ppp_ev_instance)){
@@ -264,21 +252,32 @@ bool PPPClass::begin(ppp_modem_model_t model){
264
252
265
253
/* Configure the DTE */
266
254
esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG ();
267
- /* setup UART specific configuration based on kconfig options */
268
255
dte_config.uart_config .tx_io_num = _pin_tx;
269
256
dte_config.uart_config .rx_io_num = _pin_rx;
270
257
dte_config.uart_config .rts_io_num = _pin_rts;
271
258
dte_config.uart_config .cts_io_num = _pin_cts;
272
259
dte_config.uart_config .flow_control = _flow_ctrl;
273
260
dte_config.uart_config .rx_buffer_size = _rx_buffer_size;
274
261
dte_config.uart_config .tx_buffer_size = _tx_buffer_size;
275
- dte_config.uart_config .event_queue_size = 20 ;
276
- dte_config.task_stack_size = 2048 ;
277
- dte_config.task_priority = 5 ;
278
- dte_config.dte_buffer_size = _rx_buffer_size / 2 ;
279
262
280
263
/* Configure the DCE */
281
264
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG (_apn);
265
+
266
+ /* Reset the Modem */
267
+ if (_pin_rst >= 0 ){
268
+ log_v (" Resetting the modem" );
269
+ if (_pin_rst_act_low){
270
+ pinMode (_pin_rst, OUTPUT_OPEN_DRAIN);
271
+ } else {
272
+ pinMode (_pin_rst, OUTPUT);
273
+ }
274
+ digitalWrite (_pin_rst, !_pin_rst_act_low);
275
+ delay (200 );
276
+ digitalWrite (_pin_rst, _pin_rst_act_low);
277
+ delay (100 );
278
+ }
279
+
280
+ /* Start the DCE */
282
281
_dce = esp_modem_new_dev ((esp_modem_dce_device_t )model, &dte_config, &dce_config, _esp_netif);
283
282
if (_dce == NULL ){
284
283
log_e (" esp_modem_new_dev failed" );
@@ -287,27 +286,33 @@ bool PPPClass::begin(ppp_modem_model_t model){
287
286
288
287
esp_modem_set_error_cb (_dce, _ppp_error_cb);
289
288
290
- // wait to be able to talk to the modem
291
- log_v (" Waiting for response from the modem" );
292
- while (esp_modem_read_pin (_dce, pin_ok) != ESP_OK && trys < 50 ){
293
- trys++;
294
- delay (500 );
295
- }
296
- if (trys >= 50 ){
297
- log_e (" Failed to wait for communication" );
298
- goto err;
289
+ /* Wait for Modem to respond */
290
+ if (_pin_rst >= 0 ){
291
+ // wait to be able to talk to the modem
292
+ log_v (" Waiting for response from the modem" );
293
+ while (esp_modem_sync (_dce) != ESP_OK && trys < 50 ){
294
+ trys++;
295
+ delay (500 );
296
+ }
297
+ if (trys >= 50 ){
298
+ log_e (" Failed to wait for communication" );
299
+ goto err;
300
+ }
301
+ } else {
302
+ // try to communicate with the modem
303
+
299
304
}
300
305
301
- // enable flow control
306
+ /* enable flow control */
302
307
if (dte_config.uart_config .flow_control == ESP_MODEM_FLOW_CONTROL_HW) {
303
308
ret = esp_modem_set_flow_control (_dce, 2 , 2 ); // 2/2 means HW Flow Control.
304
309
if (ret != ESP_OK) {
305
- log_e (" Failed to set the set_flow_control mode : [%d] %s" , ret, esp_err_to_name (ret));
310
+ log_e (" Failed to set the hardware flow control : [%d] %s" , ret, esp_err_to_name (ret));
306
311
goto err;
307
312
}
308
313
}
309
314
310
- // check if PIN needed
315
+ /* check if PIN needed */
311
316
if (esp_modem_read_pin (_dce, pin_ok) == ESP_OK && pin_ok == false ) {
312
317
if (_pin == NULL || esp_modem_set_pin (_dce, _pin) != ESP_OK) {
313
318
log_e (" PIN verification failed!" );
@@ -382,6 +387,19 @@ void PPPClass::end(void)
382
387
_mode = ESP_MODEM_MODE_COMMAND;
383
388
}
384
389
390
+ bool PPPClass::sync () const
391
+ {
392
+ if (_dce == NULL ){
393
+ return false ;
394
+ }
395
+
396
+ if (_mode == ESP_MODEM_MODE_DATA){
397
+ log_e (" Wrong modem mode. Should be ESP_MODEM_MODE_COMMAND" );
398
+ return false ;
399
+ }
400
+ return esp_modem_sync (_dce) == ESP_OK;
401
+ }
402
+
385
403
bool PPPClass::attached () const
386
404
{
387
405
if (_dce == NULL ){
0 commit comments