-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(eppp_link): Added test-app with server and client on one ESP
- Loading branch information
1 parent
046e7e4
commit ad2507e
Showing
8 changed files
with
246 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# The following four lines of boilerplate have to be in your project's CMakeLists | ||
# in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/iperf) | ||
|
||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(test_app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
# Test application running both server and client on the same device | ||
|
||
Need to connect client's Tx to server's Rx and vice versa: | ||
GPIO25 - GPIO4 | ||
GPIO26 - GPIO5 | ||
|
||
We wait for the connection and then we start pinging the client's address on server's netif. | ||
|
||
## Example of output: | ||
|
||
``` | ||
I (393) eppp_test_app: [APP] Startup.. | ||
I (393) eppp_test_app: [APP] Free memory: 296332 bytes | ||
I (393) eppp_test_app: [APP] IDF version: v5.3-dev-1154-gf14d9e7431-dirty | ||
I (423) uart: ESP_INTR_FLAG_IRAM flag not set while CONFIG_UART_ISR_IN_IRAM is enabled, flag updated | ||
I (423) uart: queue free spaces: 16 | ||
I (433) eppp_link: Waiting for IP address | ||
I (433) uart: ESP_INTR_FLAG_IRAM flag not set while CONFIG_UART_ISR_IN_IRAM is enabled, flag updated | ||
I (443) uart: queue free spaces: 16 | ||
I (443) eppp_link: Waiting for IP address | ||
I (6473) esp-netif_lwip-ppp: Connected | ||
I (6513) eppp_link: Got IPv4 event: Interface "pppos_client" address: 192.168.11.2 | ||
I (6523) esp-netif_lwip-ppp: Connected | ||
I (6513) eppp_link: Connected! | ||
I (6523) eppp_link: Got IPv4 event: Interface "pppos_server" address: 192.168.11.1 | ||
I (6553) main_task: Returned from app_main() | ||
64bytes from 192.168.11.2 icmp_seq=1 ttl=255 time=18 ms | ||
64bytes from 192.168.11.2 icmp_seq=2 ttl=255 time=19 ms | ||
64bytes from 192.168.11.2 icmp_seq=3 ttl=255 time=19 ms | ||
64bytes from 192.168.11.2 icmp_seq=4 ttl=255 time=20 ms | ||
64bytes from 192.168.11.2 icmp_seq=5 ttl=255 time=19 ms | ||
64bytes from 192.168.11.2 icmp_seq=6 ttl=255 time=19 ms | ||
64bytes from 192.168.11.2 icmp_seq=7 ttl=255 time=19 ms | ||
From 192.168.11.2 icmp_seq=8 timeout // <-- Disconnected Tx-Rx wires | ||
From 192.168.11.2 icmp_seq=9 timeout | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
idf_component_register(SRCS app_main.c | ||
INCLUDE_DIRS ".") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <string.h> | ||
#include "esp_system.h" | ||
#include "nvs_flash.h" | ||
#include "esp_event.h" | ||
#include "esp_netif.h" | ||
#include "eppp_link.h" | ||
#include "lwip/sockets.h" | ||
#include "esp_log.h" | ||
#include "ping/ping_sock.h" | ||
#include "driver/uart.h" | ||
|
||
static const char *TAG = "eppp_test_app"; | ||
|
||
static void test_on_ping_success(esp_ping_handle_t hdl, void *args) | ||
{ | ||
uint8_t ttl; | ||
uint16_t seqno; | ||
uint32_t elapsed_time, recv_len; | ||
ip_addr_t target_addr; | ||
esp_ping_get_profile(hdl, ESP_PING_PROF_SEQNO, &seqno, sizeof(seqno)); | ||
esp_ping_get_profile(hdl, ESP_PING_PROF_TTL, &ttl, sizeof(ttl)); | ||
esp_ping_get_profile(hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof(target_addr)); | ||
esp_ping_get_profile(hdl, ESP_PING_PROF_SIZE, &recv_len, sizeof(recv_len)); | ||
esp_ping_get_profile(hdl, ESP_PING_PROF_TIMEGAP, &elapsed_time, sizeof(elapsed_time)); | ||
printf("%" PRId32 "bytes from %s icmp_seq=%d ttl=%d time=%" PRId32 " ms\n", | ||
recv_len, inet_ntoa(target_addr.u_addr.ip4), seqno, ttl, elapsed_time); | ||
} | ||
|
||
static void test_on_ping_timeout(esp_ping_handle_t hdl, void *args) | ||
{ | ||
uint16_t seqno; | ||
ip_addr_t target_addr; | ||
esp_ping_get_profile(hdl, ESP_PING_PROF_SEQNO, &seqno, sizeof(seqno)); | ||
esp_ping_get_profile(hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof(target_addr)); | ||
printf("From %s icmp_seq=%d timeout\n", inet_ntoa(target_addr.u_addr.ip4), seqno); | ||
} | ||
|
||
static void test_on_ping_end(esp_ping_handle_t hdl, void *args) | ||
{ | ||
uint32_t transmitted; | ||
uint32_t received; | ||
uint32_t total_time_ms; | ||
esp_ping_get_profile(hdl, ESP_PING_PROF_REQUEST, &transmitted, sizeof(transmitted)); | ||
esp_ping_get_profile(hdl, ESP_PING_PROF_REPLY, &received, sizeof(received)); | ||
esp_ping_get_profile(hdl, ESP_PING_PROF_DURATION, &total_time_ms, sizeof(total_time_ms)); | ||
printf("%" PRId32 " packets transmitted, %" PRId32 " received, time %" PRId32 "ms\n", transmitted, received, total_time_ms); | ||
|
||
} | ||
|
||
static void client_task(void *ctx) | ||
{ | ||
eppp_config_t *client_config = ctx; | ||
esp_netif_t *eppp_client = eppp_connect(client_config); | ||
|
||
if (eppp_client == NULL) { | ||
ESP_LOGE(TAG, "Failed to connect"); | ||
} | ||
|
||
vTaskDelete(NULL); | ||
} | ||
|
||
void app_main(void) | ||
{ | ||
ESP_LOGI(TAG, "[APP] Startup.."); | ||
ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size()); | ||
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version()); | ||
|
||
|
||
ESP_ERROR_CHECK(nvs_flash_init()); | ||
ESP_ERROR_CHECK(esp_netif_init()); | ||
ESP_ERROR_CHECK(esp_event_loop_create_default()); | ||
|
||
/* Sets up the default EPPP-connection | ||
*/ | ||
uint32_t server_ip = ESP_IP4TOADDR(192, 168, 11, 1); | ||
uint32_t client_ip = ESP_IP4TOADDR(192, 168, 11, 2); | ||
eppp_config_t server_config = { | ||
.uart = { | ||
.port = UART_NUM_1, | ||
.baud = 921600, | ||
.tx_io = 25, | ||
.rx_io = 26, | ||
.queue_size = 16, | ||
.rx_buffer_size = 1024, | ||
}, | ||
. task = { | ||
.run_task = true, | ||
.stack_size = 4096, | ||
.priority = 18, | ||
}, | ||
. ppp = { | ||
.our_ip4_addr = server_ip, | ||
.their_ip4_addr = client_ip, | ||
} | ||
}; | ||
eppp_config_t client_config = {}; | ||
memcpy(&client_config, &server_config, sizeof(server_config)); | ||
client_config.uart.port = UART_NUM_2; | ||
client_config.uart.tx_io = 4; | ||
client_config.uart.rx_io = 5; | ||
client_config.ppp.our_ip4_addr = client_ip; | ||
client_config.ppp.their_ip4_addr = server_ip; | ||
xTaskCreate(client_task, "client_task", 4096, &client_config, 5, NULL); | ||
|
||
esp_netif_t *eppp_server = eppp_listen(&server_config); | ||
if (eppp_server == NULL) { | ||
ESP_LOGE(TAG, "Failed to setup connection"); | ||
return ; | ||
} | ||
|
||
// Try to ping client's IP on server interface, so the packets go over the wires | ||
// (if we didn't set the interface, ping would run locally on the client's netif) | ||
ip_addr_t target_addr = { .type = IPADDR_TYPE_V4, .u_addr.ip4.addr = client_ip }; | ||
|
||
esp_ping_config_t ping_config = ESP_PING_DEFAULT_CONFIG(); | ||
ping_config.timeout_ms = 2000; | ||
ping_config.interval_ms = 1000, | ||
ping_config.target_addr = target_addr; | ||
ping_config.count = 100; | ||
ping_config.interface = esp_netif_get_netif_impl_index(eppp_server); | ||
/* set callback functions */ | ||
esp_ping_callbacks_t cbs; | ||
cbs.on_ping_success = test_on_ping_success; | ||
cbs.on_ping_timeout = test_on_ping_timeout; | ||
cbs.on_ping_end = test_on_ping_end; | ||
esp_ping_handle_t ping; | ||
esp_ping_new_session(&ping_config, &cbs, &ping); | ||
/* start ping */ | ||
esp_ping_start(ping); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dependencies: | ||
espressif/eppp_link: | ||
version: "*" | ||
override_path: "../../.." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_LWIP_PPP_SUPPORT=y |