Skip to content

Commit 3120cc2

Browse files
committed
Fix PPP.end()
1 parent ee0366e commit 3120cc2

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

libraries/PPP/src/PPP.cpp

+35-21
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ static void _ppp_error_cb(esp_modem_terminal_error_t err){
9696
// PPP Arduino Events Callback
9797
void PPPClass::_onPppArduinoEvent(arduino_event_id_t event, arduino_event_info_t info){
9898
log_v("PPP Arduino Event %ld: %s", event, Network.eventName(event));
99-
if(event == ARDUINO_EVENT_PPP_GOT_IP){
100-
if((getStatusBits() & ESP_NETIF_CONNECTED_BIT) == 0){
101-
setStatusBits(ESP_NETIF_CONNECTED_BIT);
102-
arduino_event_t arduino_event;
103-
arduino_event.event_id = ARDUINO_EVENT_PPP_CONNECTED;
104-
Network.postEvent(&arduino_event);
105-
}
106-
} else
99+
// if(event == ARDUINO_EVENT_PPP_GOT_IP){
100+
// if((getStatusBits() & ESP_NETIF_CONNECTED_BIT) == 0){
101+
// setStatusBits(ESP_NETIF_CONNECTED_BIT);
102+
// arduino_event_t arduino_event;
103+
// arduino_event.event_id = ARDUINO_EVENT_PPP_CONNECTED;
104+
// Network.postEvent(&arduino_event);
105+
// }
106+
// } else
107107
if(event == ARDUINO_EVENT_PPP_LOST_IP){
108108
if((getStatusBits() & ESP_NETIF_CONNECTED_BIT) != 0){
109109
clearStatusBits(ESP_NETIF_CONNECTED_BIT);
@@ -115,15 +115,24 @@ void PPPClass::_onPppArduinoEvent(arduino_event_id_t event, arduino_event_info_t
115115
}
116116

117117
// PPP Driver Events Callback
118-
void PPPClass::_onPppEvent(int32_t event_id, void* event_data){
119-
// arduino_event_t arduino_event;
120-
// arduino_event.event_id = ARDUINO_EVENT_MAX;
118+
void PPPClass::_onPppEvent(int32_t event, void* event_data){
119+
arduino_event_t arduino_event;
120+
arduino_event.event_id = ARDUINO_EVENT_MAX;
121121

122-
log_v("PPP Driver Event %ld: %s", event_id, _ppp_event_name(event_id));
122+
log_v("PPP Driver Event %ld: %s", event, _ppp_event_name(event));
123+
124+
if(event == NETIF_PPP_ERRORNONE){
125+
if((getStatusBits() & ESP_NETIF_CONNECTED_BIT) == 0){
126+
setStatusBits(ESP_NETIF_CONNECTED_BIT);
127+
arduino_event_t arduino_event;
128+
arduino_event.event_id = ARDUINO_EVENT_PPP_CONNECTED;
129+
Network.postEvent(&arduino_event);
130+
}
131+
}
123132

124-
// if(arduino_event.event_id < ARDUINO_EVENT_MAX){
125-
// Network.postEvent(&arduino_event);
126-
// }
133+
if(arduino_event.event_id < ARDUINO_EVENT_MAX){
134+
Network.postEvent(&arduino_event);
135+
}
127136
}
128137

129138
esp_modem_dce_t * PPPClass::handle() const {
@@ -291,11 +300,11 @@ bool PPPClass::begin(ppp_modem_model_t model, uint8_t uart_num, int baud_rate){
291300
if(_pin_rst >= 0){
292301
// wait to be able to talk to the modem
293302
log_v("Waiting for response from the modem");
294-
while(esp_modem_sync(_dce) != ESP_OK && trys < 50){
303+
while(esp_modem_sync(_dce) != ESP_OK && trys < 100){
295304
trys++;
296305
delay(500);
297306
}
298-
if(trys >= 50){
307+
if(trys >= 100){
299308
log_e("Failed to wait for communication");
300309
goto err;
301310
}
@@ -375,21 +384,26 @@ void PPPClass::end(void)
375384
_dce = NULL;
376385
}
377386

387+
int8_t pin = -1;
378388
if(_pin_tx != -1){
379-
perimanClearPinBus(_pin_tx);
389+
pin = _pin_tx;
380390
_pin_tx = -1;
391+
perimanClearPinBus(pin);
381392
}
382393
if(_pin_rx != -1){
383-
perimanClearPinBus(_pin_rx);
394+
pin = _pin_rx;
384395
_pin_rx = -1;
396+
perimanClearPinBus(pin);
385397
}
386398
if(_pin_rts != -1){
387-
perimanClearPinBus(_pin_rts);
399+
pin = _pin_rts;
388400
_pin_rts = -1;
401+
perimanClearPinBus(pin);
389402
}
390403
if(_pin_cts != -1){
391-
perimanClearPinBus(_pin_cts);
404+
pin = _pin_cts;
392405
_pin_cts = -1;
406+
perimanClearPinBus(pin);
393407
}
394408

395409
_mode = ESP_MODEM_MODE_COMMAND;

0 commit comments

Comments
 (0)