|
11 | 11 | typedef struct { void * arg; } PdpContext;
|
12 | 12 | #include "esp_modem_api.h"
|
13 | 13 |
|
| 14 | +// Because of how esp_modem functions are declared, we need to workaround some APIs that take strings as input (output works OK) |
| 15 | +// Following APIs work only when called through this interface |
| 16 | +extern "C" { |
| 17 | + esp_err_t _esp_modem_at(esp_modem_dce_t *dce_wrap, const char *at, char *p_out, int timeout); |
| 18 | + esp_err_t _esp_modem_at_raw(esp_modem_dce_t *dce_wrap, const char *cmd, char *p_out, const char *pass, const char *fail, int timeout); |
| 19 | + esp_err_t _esp_modem_send_sms(esp_modem_dce_t *dce_wrap, const char *number, const char *message); |
| 20 | + esp_err_t _esp_modem_set_pin(esp_modem_dce_t *dce_wrap, const char *pin); |
| 21 | + esp_err_t _esp_modem_set_operator(esp_modem_dce_t *dce_wrap, int mode, int format, const char *oper); |
| 22 | + esp_err_t _esp_modem_set_network_bands(esp_modem_dce_t *dce_wrap, const char *mode, const int *bands, int size); |
| 23 | +}; |
| 24 | + |
14 | 25 | static PPPClass * _esp_modem = NULL;
|
15 | 26 | static esp_event_handler_instance_t _ppp_ev_instance = NULL;
|
16 | 27 |
|
@@ -105,33 +116,14 @@ void PPPClass::_onPppArduinoEvent(arduino_event_id_t event, arduino_event_info_t
|
105 | 116 |
|
106 | 117 | // PPP Driver Events Callback
|
107 | 118 | void PPPClass::_onPppEvent(int32_t event_id, void* event_data){
|
108 |
| - arduino_event_t arduino_event; |
109 |
| - arduino_event.event_id = ARDUINO_EVENT_MAX; |
| 119 | + // arduino_event_t arduino_event; |
| 120 | + // arduino_event.event_id = ARDUINO_EVENT_MAX; |
110 | 121 |
|
111 | 122 | log_v("PPP Driver Event %ld: %s", event_id, _ppp_event_name(event_id));
|
112 | 123 |
|
113 |
| - // if (event_id == ETHERNET_EVENT_CONNECTED) { |
114 |
| - // log_v("%s Connected", desc()); |
115 |
| - // arduino_event.event_id = ARDUINO_EVENT_PPP_CONNECTED; |
116 |
| - // arduino_event.event_info.eth_connected = handle(); |
117 |
| - // setStatusBits(ESP_NETIF_CONNECTED_BIT); |
118 |
| - // } else if (event_id == ETHERNET_EVENT_DISCONNECTED) { |
119 |
| - // log_v("%s Disconnected", desc()); |
120 |
| - // arduino_event.event_id = ARDUINO_EVENT_PPP_DISCONNECTED; |
121 |
| - // clearStatusBits(ESP_NETIF_CONNECTED_BIT | ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_LOCAL_IP6_BIT | ESP_NETIF_HAS_GLOBAL_IP6_BIT); |
122 |
| - // } else if (event_id == ETHERNET_EVENT_START) { |
123 |
| - // log_v("%s Started", desc()); |
124 |
| - // arduino_event.event_id = ARDUINO_EVENT_PPP_START; |
125 |
| - // setStatusBits(ESP_NETIF_STARTED_BIT); |
126 |
| - // } else if (event_id == ETHERNET_EVENT_STOP) { |
127 |
| - // log_v("%s Stopped", desc()); |
128 |
| - // arduino_event.event_id = ARDUINO_EVENT_PPP_STOP; |
129 |
| - // clearStatusBits(ESP_NETIF_STARTED_BIT | ESP_NETIF_CONNECTED_BIT | ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_LOCAL_IP6_BIT | ESP_NETIF_HAS_GLOBAL_IP6_BIT | ESP_NETIF_HAS_STATIC_IP_BIT); |
| 124 | + // if(arduino_event.event_id < ARDUINO_EVENT_MAX){ |
| 125 | + // Network.postEvent(&arduino_event); |
130 | 126 | // }
|
131 |
| - |
132 |
| - if(arduino_event.event_id < ARDUINO_EVENT_MAX){ |
133 |
| - Network.postEvent(&arduino_event); |
134 |
| - } |
135 | 127 | }
|
136 | 128 |
|
137 | 129 | esp_modem_dce_t * PPPClass::handle() const {
|
@@ -330,7 +322,7 @@ bool PPPClass::begin(ppp_modem_model_t model, uint8_t uart_num, int baud_rate){
|
330 | 322 |
|
331 | 323 | /* check if PIN needed */
|
332 | 324 | if (esp_modem_read_pin(_dce, pin_ok) == ESP_OK && pin_ok == false) {
|
333 |
| - if (_pin == NULL || esp_modem_set_pin(_dce, _pin) != ESP_OK) { |
| 325 | + if (_pin == NULL || _esp_modem_set_pin(_dce, _pin) != ESP_OK) { |
334 | 326 | log_e("PIN verification failed!");
|
335 | 327 | goto err;
|
336 | 328 | }
|
@@ -735,7 +727,6 @@ bool PPPClass::setBaudrate(int baudrate) {
|
735 | 727 | return true;
|
736 | 728 | }
|
737 | 729 |
|
738 |
| - |
739 | 730 | bool PPPClass::sms(const char * num, const char * message) {
|
740 | 731 | if(_dce == NULL){
|
741 | 732 | return false;
|
@@ -765,14 +756,32 @@ bool PPPClass::sms(const char * num, const char * message) {
|
765 | 756 | return false;
|
766 | 757 | }
|
767 | 758 |
|
768 |
| - err = esp_modem_send_sms(_dce, num, message); |
| 759 | + err = _esp_modem_send_sms(_dce, num, message); |
769 | 760 | if (err != ESP_OK) {
|
770 | 761 | log_e("esp_modem_send_sms() failed with %d %s", err, esp_err_to_name(err));
|
771 | 762 | return false;
|
772 | 763 | }
|
773 | 764 | return true;
|
774 | 765 | }
|
775 | 766 |
|
| 767 | +String PPPClass::cmd(const char * at_command, int timeout){ |
| 768 | + if(_dce == NULL){ |
| 769 | + return String(); |
| 770 | + } |
| 771 | + |
| 772 | + if(_mode == ESP_MODEM_MODE_DATA){ |
| 773 | + log_e("Wrong modem mode. Should be ESP_MODEM_MODE_COMMAND"); |
| 774 | + return String(); |
| 775 | + } |
| 776 | + char out[128] = {0}; |
| 777 | + esp_err_t err = _esp_modem_at(_dce, at_command, out, timeout); |
| 778 | + if (err != ESP_OK) { |
| 779 | + log_e("esp_modem_at failed %d %s", err, esp_err_to_name(err)); |
| 780 | + return String(); |
| 781 | + } |
| 782 | + return String(out); |
| 783 | +} |
| 784 | + |
776 | 785 | size_t PPPClass::printDriverInfo(Print & out) const {
|
777 | 786 | size_t bytes = 0;
|
778 | 787 | if(_dce == NULL || _mode == ESP_MODEM_MODE_DATA){
|
|
0 commit comments