Step 2.1: web server, embedded UI, /api/status, /api/reboot
- aes67_web: httpd (wildcard URI matching), serves web/index.html embedded via EMBED_TXTFILES, status registry (status_register) and route registry (web_register_uri), GET /api/status, POST /api/reboot (restarts 0.5 s after the response). - Status fields come from each core component: aes67_net (ip, aes67_ip, mac, link), aes67_health (fw, uptime_s, heap_free, psram_free), aes67_tx stub (tx_packets, underruns = 0). No ptp object yet, so the UI shows "no data". - Verified on board: / serves index.html byte-identical (27601 B), /api/status returns live values, reboot via API returns in ~12 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
idf_component_register(SRCS "aes67_net.c"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES esp_eth esp_netif esp_event)
|
||||
REQUIRES esp_eth esp_netif esp_event
|
||||
PRIV_REQUIRES aes67_web)
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "aes67_net.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "aes67_web.h"
|
||||
#include "esp_eth.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
@@ -7,6 +10,9 @@
|
||||
|
||||
static const char *TAG = "net";
|
||||
|
||||
static esp_netif_t *s_netif;
|
||||
static char s_link[24] = "down";
|
||||
|
||||
static void eth_event(void *arg, esp_event_base_t base, int32_t id, void *data)
|
||||
{
|
||||
esp_eth_handle_t eth = *(esp_eth_handle_t *)data;
|
||||
@@ -22,10 +28,13 @@ static void eth_event(void *arg, esp_event_base_t base, int32_t id, void *data)
|
||||
ESP_LOGI(TAG, "link up: %s Mbps %s duplex, MAC %02x:%02x:%02x:%02x:%02x:%02x",
|
||||
speed == ETH_SPEED_100M ? "100" : "10", duplex == ETH_DUPLEX_FULL ? "full" : "half",
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
snprintf(s_link, sizeof(s_link), "up, %s Mbps %s", speed == ETH_SPEED_100M ? "100" : "10",
|
||||
duplex == ETH_DUPLEX_FULL ? "full" : "half");
|
||||
break;
|
||||
}
|
||||
case ETHERNET_EVENT_DISCONNECTED:
|
||||
ESP_LOGW(TAG, "link down");
|
||||
snprintf(s_link, sizeof(s_link), "down");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -39,6 +48,25 @@ static void ip_event(void *arg, esp_event_base_t base, int32_t id, void *data)
|
||||
IP2STR(&ev->ip_info.ip), IP2STR(&ev->ip_info.netmask), IP2STR(&ev->ip_info.gw));
|
||||
}
|
||||
|
||||
static void net_status(cJSON *st)
|
||||
{
|
||||
char ip[16] = "", mac_s[18] = "";
|
||||
esp_netif_ip_info_t info;
|
||||
if (esp_netif_get_ip_info(s_netif, &info) == ESP_OK && info.ip.addr) {
|
||||
snprintf(ip, sizeof(ip), IPSTR, IP2STR(&info.ip));
|
||||
}
|
||||
uint8_t mac[6];
|
||||
if (esp_netif_get_mac(s_netif, mac) == ESP_OK) {
|
||||
snprintf(mac_s, sizeof(mac_s), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
}
|
||||
// Single untagged interface until the VLAN split: AES67 and web share it.
|
||||
cJSON_AddStringToObject(st, "ip", ip);
|
||||
cJSON_AddStringToObject(st, "aes67_ip", ip);
|
||||
cJSON_AddStringToObject(st, "mac", mac_s);
|
||||
cJSON_AddStringToObject(st, "link", s_link);
|
||||
}
|
||||
|
||||
esp_err_t aes67_net_init(esp_eth_handle_t eth)
|
||||
{
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
@@ -48,11 +76,12 @@ esp_err_t aes67_net_init(esp_eth_handle_t eth)
|
||||
}
|
||||
|
||||
esp_netif_config_t netif_cfg = ESP_NETIF_DEFAULT_ETH();
|
||||
esp_netif_t *netif = esp_netif_new(&netif_cfg);
|
||||
ESP_ERROR_CHECK(esp_netif_attach(netif, esp_eth_new_netif_glue(eth)));
|
||||
s_netif = esp_netif_new(&netif_cfg);
|
||||
ESP_ERROR_CHECK(esp_netif_attach(s_netif, esp_eth_new_netif_glue(eth)));
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, ip_event, NULL));
|
||||
|
||||
status_register(net_status);
|
||||
return esp_eth_start(eth);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user