feat: Add mDNS, watchdog, human-readable uptime, esp-fleet tool
Firmware: - mDNS announcement as <hostname>.local (configurable via Kconfig) - Task watchdog with 30s timeout and auto-reboot on hang - STATUS now returns human-readable uptime (e.g., 3d2h15m) and hostname Pi-side tools: - esp-cmd: mDNS hostname resolution (esp-cmd amber-maple.local STATUS) - esp-fleet: parallel command to all sensors (esp-fleet status) Tested on amber-maple — mDNS resolves, watchdog active, fleet tool works.
This commit is contained in:
@@ -29,7 +29,9 @@
|
||||
#include "esp_netif.h"
|
||||
#include "esp_now.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_task_wdt.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "mdns.h"
|
||||
|
||||
#include "lwip/inet.h"
|
||||
#include "lwip/netdb.h"
|
||||
@@ -400,7 +402,10 @@ static int cmd_handle(const char *cmd, char *reply, size_t reply_size)
|
||||
|
||||
/* STATUS */
|
||||
if (strncmp(cmd, "STATUS", 6) == 0) {
|
||||
int64_t uptime_s = esp_timer_get_time() / 1000000LL;
|
||||
int64_t up = esp_timer_get_time() / 1000000LL;
|
||||
int days = (int)(up / 86400);
|
||||
int hours = (int)((up % 86400) / 3600);
|
||||
int mins = (int)((up % 3600) / 60);
|
||||
uint32_t heap = esp_get_free_heap_size();
|
||||
|
||||
wifi_ap_record_t ap;
|
||||
@@ -409,9 +414,19 @@ static int cmd_handle(const char *cmd, char *reply, size_t reply_size)
|
||||
rssi = ap.rssi;
|
||||
}
|
||||
|
||||
char uptime_str[32];
|
||||
if (days > 0) {
|
||||
snprintf(uptime_str, sizeof(uptime_str), "%dd%dh%dm", days, hours, mins);
|
||||
} else if (hours > 0) {
|
||||
snprintf(uptime_str, sizeof(uptime_str), "%dh%dm", hours, mins);
|
||||
} else {
|
||||
snprintf(uptime_str, sizeof(uptime_str), "%dm", mins);
|
||||
}
|
||||
|
||||
snprintf(reply, reply_size,
|
||||
"OK STATUS uptime=%lld heap=%lu rssi=%d tx_power=%d rate=%d",
|
||||
uptime_s, (unsigned long)heap, rssi, (int)s_tx_power_dbm, s_send_frequency);
|
||||
"OK STATUS uptime=%s heap=%lu rssi=%d tx_power=%d rate=%d hostname=%s",
|
||||
uptime_str, (unsigned long)heap, rssi, (int)s_tx_power_dbm,
|
||||
s_send_frequency, CONFIG_CSI_HOSTNAME);
|
||||
return strlen(reply);
|
||||
}
|
||||
|
||||
@@ -526,6 +541,21 @@ void app_main()
|
||||
esp_wifi_set_max_tx_power(s_tx_power_dbm * 4);
|
||||
ESP_LOGI(TAG, "TX power set to %d dBm", (int)s_tx_power_dbm);
|
||||
|
||||
/* mDNS: announce as <hostname>.local */
|
||||
ESP_ERROR_CHECK(mdns_init());
|
||||
mdns_hostname_set(CONFIG_CSI_HOSTNAME);
|
||||
mdns_instance_name_set("ESP32 CSI Sensor");
|
||||
ESP_LOGI(TAG, "mDNS hostname: %s.local", CONFIG_CSI_HOSTNAME);
|
||||
|
||||
/* Watchdog: 30s timeout, auto-reboot on hang */
|
||||
esp_task_wdt_config_t wdt_cfg = {
|
||||
.timeout_ms = 30000,
|
||||
.idle_core_mask = (1 << 0) | (1 << 1),
|
||||
.trigger_panic = true,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_task_wdt_reconfigure(&wdt_cfg));
|
||||
ESP_LOGI(TAG, "Watchdog configured: 30s timeout");
|
||||
|
||||
s_led_mode = LED_SLOW_BLINK;
|
||||
|
||||
udp_socket_init();
|
||||
|
||||
Reference in New Issue
Block a user