Add RESTART command for master and slaves via ESP-NOW.

UART RESTART (client_id 0 = local reboot, >0 = unicast); dashboard and CLI hooks; delayed esp_restart after response.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-19 22:33:22 +02:00
co-authored by Cursor
parent 5c3cf65bca
commit a9e08107b4
23 changed files with 625 additions and 61 deletions
+54
View File
@@ -3,6 +3,7 @@
#include "esp_now_comm.h"
#include "led_ring.h"
#include "ota_espnow.h"
#include "pod_reboot.h"
#include "pod_settings.h"
#include "esp_now_proto.h"
#include "esp_err.h"
@@ -182,6 +183,16 @@ static esp_err_t send_find_me(const uint8_t *dest_mac, uint32_t client_id) {
return send_message(dest_mac, &msg);
}
static esp_err_t send_restart(const uint8_t *dest_mac, uint32_t client_id) {
alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
msg.type = alox_EspNowMessageType_ESPNOW_RESTART;
msg.which_payload = alox_EspNowMessage_restart_tag;
msg.payload.restart.client_id = client_id;
return send_message(dest_mac, &msg);
}
static esp_err_t send_ota_start(const uint8_t *dest_mac, uint32_t total_size) {
alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
@@ -272,6 +283,25 @@ bool esp_now_comm_get_master_mac(uint8_t mac_out[CLIENT_MAC_LEN]) {
return true;
}
esp_err_t esp_now_comm_send_restart(const uint8_t mac[CLIENT_MAC_LEN],
uint32_t client_id) {
if (mac == NULL || !s_config.master) {
return ESP_ERR_INVALID_STATE;
}
char mac_str[18];
mac_to_str(mac, mac_str, sizeof(mac_str));
esp_err_t err = send_restart(mac, client_id);
if (err == ESP_OK) {
ESP_LOGI(TAG, "unicast RESTART to %s client_id=%lu", mac_str,
(unsigned long)client_id);
} else {
ESP_LOGW(TAG, "unicast RESTART to %s failed: %s", mac_str,
esp_err_to_name(err));
}
return err;
}
esp_err_t esp_now_comm_send_find_me(const uint8_t mac[CLIENT_MAC_LEN],
uint32_t client_id) {
if (mac == NULL || !s_config.master) {
@@ -360,6 +390,24 @@ static void handle_slave_unicast_test(const uint8_t *master_mac,
mac_str, (unsigned long)test->seq, (int)s_slave_joined);
}
static void handle_slave_restart(const uint8_t *master_mac,
const alox_EspNowRestart *req) {
uint32_t my_id = s_own_mac[5];
if (req->client_id != 0 && req->client_id != my_id) {
return;
}
if (s_slave_joined && !mac_equal(master_mac, s_master_mac)) {
return;
}
char mac_str[18];
mac_to_str(master_mac, mac_str, sizeof(mac_str));
ESP_LOGI(TAG, "RESTART from master %s (id=%lu)", mac_str, (unsigned long)my_id);
pod_schedule_restart();
}
static void handle_slave_find_me(const uint8_t *master_mac,
const alox_EspNowFindMe *req) {
uint32_t my_id = s_own_mac[5];
@@ -550,6 +598,12 @@ static void espnow_recv_cb(const esp_now_recv_info_t *info, const uint8_t *data,
}
handle_slave_find_me(info->src_addr, &msg.payload.find_me);
break;
case alox_EspNowMessage_restart_tag:
if (!s_slave_joined || !mac_equal(info->src_addr, s_master_mac)) {
break;
}
handle_slave_restart(info->src_addr, &msg.payload.restart);
break;
case alox_EspNowMessage_ota_start_tag:
case alox_EspNowMessage_ota_payload_tag:
case alox_EspNowMessage_ota_end_tag: