Compare commits
No commits in common. "arduinopico" and "main" have entirely different histories.
arduinopic
...
main
3 changed files with 48 additions and 23 deletions
67
src/PPPOS.c
67
src/PPPOS.c
|
@ -1,8 +1,16 @@
|
|||
|
||||
#include <string.h>
|
||||
#include "FreeRTOS.h"
|
||||
//#include "freertos/task.h"
|
||||
//#include "freertos/event_groups.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "driver/uart.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "tcpip_adapter.h"
|
||||
#include "netif/ppp/pppos.h"
|
||||
#include "lwip/err.h"
|
||||
|
@ -45,85 +53,85 @@ static void ppp_status_cb(ppp_pcb *pcb, int err_code, void *ctx)
|
|||
|
||||
switch (err_code) {
|
||||
case PPPERR_NONE: {
|
||||
//ESP_LOGE(TAG, "status_cb: Connected\n");
|
||||
ESP_LOGE(TAG, "status_cb: Connected\n");
|
||||
#if PPP_IPV4_SUPPORT
|
||||
//ESP_LOGE(TAG, " ipaddr_v4 = %s\n", ipaddr_ntoa(&pppif->ip_addr));
|
||||
//ESP_LOGE(TAG, " gateway = %s\n", ipaddr_ntoa(&pppif->gw));
|
||||
//ESP_LOGE(TAG, " netmask = %s\n", ipaddr_ntoa(&pppif->netmask));
|
||||
ESP_LOGE(TAG, " ipaddr_v4 = %s\n", ipaddr_ntoa(&pppif->ip_addr));
|
||||
ESP_LOGE(TAG, " gateway = %s\n", ipaddr_ntoa(&pppif->gw));
|
||||
ESP_LOGE(TAG, " netmask = %s\n", ipaddr_ntoa(&pppif->netmask));
|
||||
#endif /* PPP_IPV4_SUPPORT */
|
||||
#if PPP_IPV6_SUPPORT
|
||||
//ESP_LOGE(TAG, " ipaddr_v6 = %s\n", ip6addr_ntoa(netif_ip6_addr(pppif, 0)));
|
||||
ESP_LOGE(TAG, " ipaddr_v6 = %s\n", ip6addr_ntoa(netif_ip6_addr(pppif, 0)));
|
||||
#endif /* PPP_IPV6_SUPPORT */
|
||||
PPPOS_connected = true;
|
||||
|
||||
break;
|
||||
}
|
||||
case PPPERR_PARAM: {
|
||||
//ESP_LOGE(TAG, "status_cb: Invalid parameter\n");
|
||||
ESP_LOGE(TAG, "status_cb: Invalid parameter\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_OPEN: {
|
||||
//ESP_LOGE(TAG, "status_cb: Unable to open PPP session\n");
|
||||
ESP_LOGE(TAG, "status_cb: Unable to open PPP session\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_DEVICE: {
|
||||
//ESP_LOGE(TAG, "status_cb: Invalid I/O device for PPP\n");
|
||||
ESP_LOGE(TAG, "status_cb: Invalid I/O device for PPP\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_ALLOC: {
|
||||
//ESP_LOGE(TAG, "status_cb: Unable to allocate resources\n");
|
||||
ESP_LOGE(TAG, "status_cb: Unable to allocate resources\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_USER: {
|
||||
//ESP_LOGE(TAG, "status_cb: User interrupt\n");
|
||||
ESP_LOGE(TAG, "status_cb: User interrupt\n");
|
||||
PPPOS_started = false;
|
||||
PPPOS_connected = false;
|
||||
break;
|
||||
}
|
||||
case PPPERR_CONNECT: {
|
||||
//ESP_LOGE(TAG, "status_cb: Connection lost\n");
|
||||
ESP_LOGE(TAG, "status_cb: Connection lost\n");
|
||||
PPPOS_started = false;
|
||||
PPPOS_connected = false;
|
||||
break;
|
||||
}
|
||||
case PPPERR_AUTHFAIL: {
|
||||
//ESP_LOGE(TAG, "status_cb: Failed authentication challenge\n");
|
||||
ESP_LOGE(TAG, "status_cb: Failed authentication challenge\n");
|
||||
PPPOS_started = false;
|
||||
PPPOS_connected = false;
|
||||
break;
|
||||
}
|
||||
case PPPERR_PROTOCOL: {
|
||||
//ESP_LOGE(TAG, "status_cb: Failed to meet protocol\n");
|
||||
ESP_LOGE(TAG, "status_cb: Failed to meet protocol\n");
|
||||
PPPOS_started = false;
|
||||
PPPOS_connected = false;
|
||||
break;
|
||||
}
|
||||
case PPPERR_PEERDEAD: {
|
||||
//ESP_LOGE(TAG, "status_cb: Connection timeout\n");
|
||||
ESP_LOGE(TAG, "status_cb: Connection timeout\n");
|
||||
PPPOS_started = false;
|
||||
PPPOS_connected = false;
|
||||
break;
|
||||
}
|
||||
case PPPERR_IDLETIMEOUT: {
|
||||
//ESP_LOGE(TAG, "status_cb: Idle Timeout\n");
|
||||
ESP_LOGE(TAG, "status_cb: Idle Timeout\n");
|
||||
PPPOS_started = false;
|
||||
PPPOS_connected = false;
|
||||
break;
|
||||
}
|
||||
case PPPERR_CONNECTTIME: {
|
||||
//ESP_LOGE(TAG, "status_cb: Max connect time reached\n");
|
||||
ESP_LOGE(TAG, "status_cb: Max connect time reached\n");
|
||||
PPPOS_started = false;
|
||||
PPPOS_connected = false;
|
||||
break;
|
||||
}
|
||||
case PPPERR_LOOPBACK: {
|
||||
//ESP_LOGE(TAG, "status_cb: Loopback detected\n");
|
||||
ESP_LOGE(TAG, "status_cb: Loopback detected\n");
|
||||
PPPOS_started = false;
|
||||
PPPOS_connected = false;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
//ESP_LOGE(TAG, "status_cb: Unknown error code %d\n", err_code);
|
||||
ESP_LOGE(TAG, "status_cb: Unknown error code %d\n", err_code);
|
||||
PPPOS_started = false;
|
||||
PPPOS_connected = false;
|
||||
break;
|
||||
|
@ -163,8 +171,23 @@ char* data = (char*)malloc(BUF_SIZE);
|
|||
|
||||
|
||||
}
|
||||
void PPPOS_init(int uart_number, char* user, char* pass){
|
||||
void PPPOS_init(int txPin, int rxPin, int baudrate, int uart_number, char* user, char* pass){
|
||||
PPPOS_uart_num = uart_number;
|
||||
gpio_set_direction(txPin, GPIO_MODE_OUTPUT);
|
||||
gpio_set_direction(rxPin, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(rxPin, GPIO_PULLUP_ONLY);
|
||||
|
||||
uart_config_t uart_config = {
|
||||
.baud_rate = baudrate,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
|
||||
};
|
||||
|
||||
uart_param_config(PPPOS_uart_num, &uart_config) ;
|
||||
uart_set_pin(PPPOS_uart_num, txPin, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
uart_driver_install(PPPOS_uart_num, BUF_SIZE * 2, BUF_SIZE * 2, 0, NULL, 0);
|
||||
tcpip_adapter_init();
|
||||
PPP_User = user;
|
||||
PPP_Pass = pass;
|
||||
|
|
|
@ -8,7 +8,7 @@ extern "C" {
|
|||
#define BUF_SIZE (1024)
|
||||
|
||||
|
||||
void PPPOS_init(int uart_number, char* user, char* pass);
|
||||
void PPPOS_init(int txPin, int rxPin, int baudrate, int uart_number, char* user, char* pass);
|
||||
|
||||
bool PPPOS_isConnected();
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#include "Client.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/inet.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
|
|
Loading…
Reference in a new issue