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
+3
View File
@@ -12,6 +12,9 @@ PB_BIND(alox_EspNowUnicastTest, alox_EspNowUnicastTest, AUTO)
PB_BIND(alox_EspNowFindMe, alox_EspNowFindMe, AUTO)
PB_BIND(alox_EspNowRestart, alox_EspNowRestart, AUTO)
PB_BIND(alox_EspNowDiscover, alox_EspNowDiscover, AUTO)
+26 -4
View File
@@ -21,7 +21,8 @@ typedef enum _alox_EspNowMessageType {
alox_EspNowMessageType_ESPNOW_OTA_PAYLOAD = 7,
alox_EspNowMessageType_ESPNOW_OTA_END = 8,
alox_EspNowMessageType_ESPNOW_OTA_STATUS = 9,
alox_EspNowMessageType_ESPNOW_FIND_ME = 10
alox_EspNowMessageType_ESPNOW_FIND_ME = 10,
alox_EspNowMessageType_ESPNOW_RESTART = 11
} alox_EspNowMessageType;
/* Struct definitions */
@@ -35,6 +36,11 @@ typedef struct _alox_EspNowFindMe {
uint32_t client_id;
} alox_EspNowFindMe;
/* * Master → slave: reboot after short delay. */
typedef struct _alox_EspNowRestart {
uint32_t client_id;
} alox_EspNowRestart;
typedef struct _alox_EspNowDiscover {
uint32_t network;
} alox_EspNowDiscover;
@@ -91,6 +97,7 @@ typedef struct _alox_EspNowMessage {
alox_EspNowOtaEnd ota_end;
alox_EspNowOtaStatus ota_status;
alox_EspNowFindMe find_me;
alox_EspNowRestart restart;
} payload;
} alox_EspNowMessage;
@@ -101,8 +108,9 @@ extern "C" {
/* Helper constants for enums */
#define _alox_EspNowMessageType_MIN alox_EspNowMessageType_ESPNOW_UNKNOWN
#define _alox_EspNowMessageType_MAX alox_EspNowMessageType_ESPNOW_FIND_ME
#define _alox_EspNowMessageType_ARRAYSIZE ((alox_EspNowMessageType)(alox_EspNowMessageType_ESPNOW_FIND_ME+1))
#define _alox_EspNowMessageType_MAX alox_EspNowMessageType_ESPNOW_RESTART
#define _alox_EspNowMessageType_ARRAYSIZE ((alox_EspNowMessageType)(alox_EspNowMessageType_ESPNOW_RESTART+1))
@@ -119,6 +127,7 @@ extern "C" {
/* Initializer values for message structs */
#define alox_EspNowUnicastTest_init_default {0}
#define alox_EspNowFindMe_init_default {0}
#define alox_EspNowRestart_init_default {0}
#define alox_EspNowDiscover_init_default {0}
#define alox_EspNowSlavePresence_init_default {0, {{NULL}, NULL}, 0, 0, 0, 0}
#define alox_EspNowAccelDeadzone_init_default {0, 0}
@@ -129,6 +138,7 @@ extern "C" {
#define alox_EspNowMessage_init_default {_alox_EspNowMessageType_MIN, 0, {alox_EspNowDiscover_init_default}}
#define alox_EspNowUnicastTest_init_zero {0}
#define alox_EspNowFindMe_init_zero {0}
#define alox_EspNowRestart_init_zero {0}
#define alox_EspNowDiscover_init_zero {0}
#define alox_EspNowSlavePresence_init_zero {0, {{NULL}, NULL}, 0, 0, 0, 0}
#define alox_EspNowAccelDeadzone_init_zero {0, 0}
@@ -141,6 +151,7 @@ extern "C" {
/* Field tags (for use in manual encoding/decoding) */
#define alox_EspNowUnicastTest_seq_tag 1
#define alox_EspNowFindMe_client_id_tag 1
#define alox_EspNowRestart_client_id_tag 1
#define alox_EspNowDiscover_network_tag 1
#define alox_EspNowSlavePresence_network_tag 1
#define alox_EspNowSlavePresence_mac_tag 2
@@ -167,6 +178,7 @@ extern "C" {
#define alox_EspNowMessage_ota_end_tag 9
#define alox_EspNowMessage_ota_status_tag 10
#define alox_EspNowMessage_find_me_tag 11
#define alox_EspNowMessage_restart_tag 12
/* Struct field encoding specification for nanopb */
#define alox_EspNowUnicastTest_FIELDLIST(X, a) \
@@ -179,6 +191,11 @@ X(a, STATIC, SINGULAR, UINT32, client_id, 1)
#define alox_EspNowFindMe_CALLBACK NULL
#define alox_EspNowFindMe_DEFAULT NULL
#define alox_EspNowRestart_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, client_id, 1)
#define alox_EspNowRestart_CALLBACK NULL
#define alox_EspNowRestart_DEFAULT NULL
#define alox_EspNowDiscover_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, network, 1)
#define alox_EspNowDiscover_CALLBACK NULL
@@ -234,7 +251,8 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,ota_start,payload.ota_start), 7) \
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_payload,payload.ota_payload), 8) \
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_end,payload.ota_end), 9) \
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_status,payload.ota_status), 10) \
X(a, STATIC, ONEOF, MESSAGE, (payload,find_me,payload.find_me), 11)
X(a, STATIC, ONEOF, MESSAGE, (payload,find_me,payload.find_me), 11) \
X(a, STATIC, ONEOF, MESSAGE, (payload,restart,payload.restart), 12)
#define alox_EspNowMessage_CALLBACK NULL
#define alox_EspNowMessage_DEFAULT NULL
#define alox_EspNowMessage_payload_discover_MSGTYPE alox_EspNowDiscover
@@ -247,9 +265,11 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,find_me,payload.find_me), 11)
#define alox_EspNowMessage_payload_ota_end_MSGTYPE alox_EspNowOtaEnd
#define alox_EspNowMessage_payload_ota_status_MSGTYPE alox_EspNowOtaStatus
#define alox_EspNowMessage_payload_find_me_MSGTYPE alox_EspNowFindMe
#define alox_EspNowMessage_payload_restart_MSGTYPE alox_EspNowRestart
extern const pb_msgdesc_t alox_EspNowUnicastTest_msg;
extern const pb_msgdesc_t alox_EspNowFindMe_msg;
extern const pb_msgdesc_t alox_EspNowRestart_msg;
extern const pb_msgdesc_t alox_EspNowDiscover_msg;
extern const pb_msgdesc_t alox_EspNowSlavePresence_msg;
extern const pb_msgdesc_t alox_EspNowAccelDeadzone_msg;
@@ -262,6 +282,7 @@ extern const pb_msgdesc_t alox_EspNowMessage_msg;
/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
#define alox_EspNowUnicastTest_fields &alox_EspNowUnicastTest_msg
#define alox_EspNowFindMe_fields &alox_EspNowFindMe_msg
#define alox_EspNowRestart_fields &alox_EspNowRestart_msg
#define alox_EspNowDiscover_fields &alox_EspNowDiscover_msg
#define alox_EspNowSlavePresence_fields &alox_EspNowSlavePresence_msg
#define alox_EspNowAccelDeadzone_fields &alox_EspNowAccelDeadzone_msg
@@ -282,6 +303,7 @@ extern const pb_msgdesc_t alox_EspNowMessage_msg;
#define alox_EspNowOtaPayload_size 209
#define alox_EspNowOtaStart_size 6
#define alox_EspNowOtaStatus_size 18
#define alox_EspNowRestart_size 6
#define alox_EspNowUnicastTest_size 6
#ifdef __cplusplus
+7
View File
@@ -16,6 +16,7 @@ enum EspNowMessageType {
ESPNOW_OTA_END = 8;
ESPNOW_OTA_STATUS = 9;
ESPNOW_FIND_ME = 10;
ESPNOW_RESTART = 11;
}
message EspNowUnicastTest {
@@ -28,6 +29,11 @@ message EspNowFindMe {
uint32 client_id = 1;
}
/** Master → slave: reboot after short delay. */
message EspNowRestart {
uint32 client_id = 1;
}
message EspNowDiscover {
uint32 network = 1;
}
@@ -80,5 +86,6 @@ message EspNowMessage {
EspNowOtaEnd ota_end = 9;
EspNowOtaStatus ota_status = 10;
EspNowFindMe find_me = 11;
EspNowRestart restart = 12;
}
}
+6
View File
@@ -54,6 +54,12 @@ PB_BIND(alox_EspNowFindMeRequest, alox_EspNowFindMeRequest, AUTO)
PB_BIND(alox_EspNowFindMeResponse, alox_EspNowFindMeResponse, AUTO)
PB_BIND(alox_RestartRequest, alox_RestartRequest, AUTO)
PB_BIND(alox_RestartResponse, alox_RestartResponse, AUTO)
PB_BIND(alox_OtaStartPayload, alox_OtaStartPayload, AUTO)
+49 -4
View File
@@ -26,7 +26,8 @@ typedef enum _alox_MessageType {
alox_MessageType_OTA_STATUS = 19,
alox_MessageType_OTA_START_ESPNOW = 20,
alox_MessageType_OTA_SLAVE_PROGRESS = 21,
alox_MessageType_FIND_ME = 22
alox_MessageType_FIND_ME = 22,
alox_MessageType_RESTART = 23
} alox_MessageType;
/* Struct definitions */
@@ -133,6 +134,16 @@ typedef struct _alox_EspNowFindMeResponse {
uint32_t client_id;
} alox_EspNowFindMeResponse;
/* * Host → master: restart local node (client_id=0) or ESP-NOW unicast to one slave. */
typedef struct _alox_RestartRequest {
uint32_t client_id;
} alox_RestartRequest;
typedef struct _alox_RestartResponse {
bool success;
uint32_t client_id;
} alox_RestartResponse;
/* Host → device: begin UART OTA (erase inactive OTA slot; device replies OTA_STATUS). */
typedef struct _alox_OtaStartPayload {
uint32_t total_size;
@@ -205,6 +216,8 @@ typedef struct _alox_UartMessage {
alox_LedRingProgressResponse led_ring_progress_response;
alox_EspNowFindMeRequest espnow_find_me_request;
alox_EspNowFindMeResponse espnow_find_me_response;
alox_RestartRequest restart_request;
alox_RestartResponse restart_response;
} payload;
} alox_UartMessage;
@@ -215,8 +228,8 @@ extern "C" {
/* Helper constants for enums */
#define _alox_MessageType_MIN alox_MessageType_UNKNOWN
#define _alox_MessageType_MAX alox_MessageType_FIND_ME
#define _alox_MessageType_ARRAYSIZE ((alox_MessageType)(alox_MessageType_FIND_ME+1))
#define _alox_MessageType_MAX alox_MessageType_RESTART
#define _alox_MessageType_ARRAYSIZE ((alox_MessageType)(alox_MessageType_RESTART+1))
#define alox_UartMessage_type_ENUMTYPE alox_MessageType
@@ -240,6 +253,8 @@ extern "C" {
@@ -260,6 +275,8 @@ extern "C" {
#define alox_LedRingProgressResponse_init_default {0, 0, 0, 0}
#define alox_EspNowFindMeRequest_init_default {0}
#define alox_EspNowFindMeResponse_init_default {0, 0}
#define alox_RestartRequest_init_default {0}
#define alox_RestartResponse_init_default {0, 0}
#define alox_OtaStartPayload_init_default {0}
#define alox_OtaPayload_init_default {0, {0, {0}}}
#define alox_OtaEndPayload_init_default {0}
@@ -283,6 +300,8 @@ extern "C" {
#define alox_LedRingProgressResponse_init_zero {0, 0, 0, 0}
#define alox_EspNowFindMeRequest_init_zero {0}
#define alox_EspNowFindMeResponse_init_zero {0, 0}
#define alox_RestartRequest_init_zero {0}
#define alox_RestartResponse_init_zero {0, 0}
#define alox_OtaStartPayload_init_zero {0}
#define alox_OtaPayload_init_zero {0, {0, {0}}}
#define alox_OtaEndPayload_init_zero {0}
@@ -337,6 +356,9 @@ extern "C" {
#define alox_EspNowFindMeRequest_client_id_tag 1
#define alox_EspNowFindMeResponse_success_tag 1
#define alox_EspNowFindMeResponse_client_id_tag 2
#define alox_RestartRequest_client_id_tag 1
#define alox_RestartResponse_success_tag 1
#define alox_RestartResponse_client_id_tag 2
#define alox_OtaStartPayload_total_size_tag 1
#define alox_OtaPayload_seq_tag 1
#define alox_OtaPayload_data_tag 2
@@ -375,6 +397,8 @@ extern "C" {
#define alox_UartMessage_led_ring_progress_response_tag 18
#define alox_UartMessage_espnow_find_me_request_tag 19
#define alox_UartMessage_espnow_find_me_response_tag 20
#define alox_UartMessage_restart_request_tag 21
#define alox_UartMessage_restart_response_tag 22
/* Struct field encoding specification for nanopb */
#define alox_UartMessage_FIELDLIST(X, a) \
@@ -397,7 +421,9 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,ota_slave_progress_response,payload.
X(a, STATIC, ONEOF, MESSAGE, (payload,led_ring_progress_request,payload.led_ring_progress_request), 17) \
X(a, STATIC, ONEOF, MESSAGE, (payload,led_ring_progress_response,payload.led_ring_progress_response), 18) \
X(a, STATIC, ONEOF, MESSAGE, (payload,espnow_find_me_request,payload.espnow_find_me_request), 19) \
X(a, STATIC, ONEOF, MESSAGE, (payload,espnow_find_me_response,payload.espnow_find_me_response), 20)
X(a, STATIC, ONEOF, MESSAGE, (payload,espnow_find_me_response,payload.espnow_find_me_response), 20) \
X(a, STATIC, ONEOF, MESSAGE, (payload,restart_request,payload.restart_request), 21) \
X(a, STATIC, ONEOF, MESSAGE, (payload,restart_response,payload.restart_response), 22)
#define alox_UartMessage_CALLBACK NULL
#define alox_UartMessage_DEFAULT NULL
#define alox_UartMessage_payload_ack_payload_MSGTYPE alox_Ack
@@ -419,6 +445,8 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,espnow_find_me_response,payload.espn
#define alox_UartMessage_payload_led_ring_progress_response_MSGTYPE alox_LedRingProgressResponse
#define alox_UartMessage_payload_espnow_find_me_request_MSGTYPE alox_EspNowFindMeRequest
#define alox_UartMessage_payload_espnow_find_me_response_MSGTYPE alox_EspNowFindMeResponse
#define alox_UartMessage_payload_restart_request_MSGTYPE alox_RestartRequest
#define alox_UartMessage_payload_restart_response_MSGTYPE alox_RestartResponse
#define alox_Ack_FIELDLIST(X, a) \
@@ -528,6 +556,17 @@ X(a, STATIC, SINGULAR, UINT32, client_id, 2)
#define alox_EspNowFindMeResponse_CALLBACK NULL
#define alox_EspNowFindMeResponse_DEFAULT NULL
#define alox_RestartRequest_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, client_id, 1)
#define alox_RestartRequest_CALLBACK NULL
#define alox_RestartRequest_DEFAULT NULL
#define alox_RestartResponse_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, BOOL, success, 1) \
X(a, STATIC, SINGULAR, UINT32, client_id, 2)
#define alox_RestartResponse_CALLBACK NULL
#define alox_RestartResponse_DEFAULT NULL
#define alox_OtaStartPayload_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, total_size, 1)
#define alox_OtaStartPayload_CALLBACK NULL
@@ -592,6 +631,8 @@ extern const pb_msgdesc_t alox_LedRingProgressRequest_msg;
extern const pb_msgdesc_t alox_LedRingProgressResponse_msg;
extern const pb_msgdesc_t alox_EspNowFindMeRequest_msg;
extern const pb_msgdesc_t alox_EspNowFindMeResponse_msg;
extern const pb_msgdesc_t alox_RestartRequest_msg;
extern const pb_msgdesc_t alox_RestartResponse_msg;
extern const pb_msgdesc_t alox_OtaStartPayload_msg;
extern const pb_msgdesc_t alox_OtaPayload_msg;
extern const pb_msgdesc_t alox_OtaEndPayload_msg;
@@ -617,6 +658,8 @@ extern const pb_msgdesc_t alox_OtaSlaveProgressResponse_msg;
#define alox_LedRingProgressResponse_fields &alox_LedRingProgressResponse_msg
#define alox_EspNowFindMeRequest_fields &alox_EspNowFindMeRequest_msg
#define alox_EspNowFindMeResponse_fields &alox_EspNowFindMeResponse_msg
#define alox_RestartRequest_fields &alox_RestartRequest_msg
#define alox_RestartResponse_fields &alox_RestartResponse_msg
#define alox_OtaStartPayload_fields &alox_OtaStartPayload_msg
#define alox_OtaPayload_fields &alox_OtaPayload_msg
#define alox_OtaEndPayload_fields &alox_OtaEndPayload_msg
@@ -650,6 +693,8 @@ extern const pb_msgdesc_t alox_OtaSlaveProgressResponse_msg;
#define alox_OtaSlaveProgressResponse_size 532
#define alox_OtaStartPayload_size 6
#define alox_OtaStatusPayload_size 24
#define alox_RestartRequest_size 6
#define alox_RestartResponse_size 8
#ifdef __cplusplus
} /* extern "C" */
+13
View File
@@ -21,6 +21,7 @@ enum MessageType {
OTA_START_ESPNOW = 20;
OTA_SLAVE_PROGRESS = 21;
FIND_ME = 22;
RESTART = 23;
}
message UartMessage {
@@ -45,6 +46,8 @@ message UartMessage {
LedRingProgressResponse led_ring_progress_response = 18;
EspNowFindMeRequest espnow_find_me_request = 19;
EspNowFindMeResponse espnow_find_me_response = 20;
RestartRequest restart_request = 21;
RestartResponse restart_response = 22;
}
}
@@ -149,6 +152,16 @@ message EspNowFindMeResponse {
uint32 client_id = 2;
}
/** Host → master: restart local node (client_id=0) or ESP-NOW unicast to one slave. */
message RestartRequest {
uint32 client_id = 1;
}
message RestartResponse {
bool success = 1;
uint32 client_id = 2;
}
// Host → device: begin UART OTA (erase inactive OTA slot; device replies OTA_STATUS).
message OtaStartPayload {
uint32 total_size = 1;