Add LiPo battery monitoring with ESP-NOW cache and dashboard API.

Slaves report pack voltages every 30s; the master caches them for fast
BATTERY_STATUS reads. goTool exposes REST/WebSocket and shows values in
the dashboard, with a nanopb fix so optional lipo submessages encode.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-29 20:14:28 +02:00
co-authored by Cursor
parent eb67a46158
commit 3cb0b5bbe9
30 changed files with 1618 additions and 150 deletions
+107 -5
View File
@@ -29,7 +29,8 @@ typedef enum _alox_MessageType {
alox_MessageType_FIND_ME = 22,
alox_MessageType_RESTART = 23,
alox_MessageType_ACCEL_SNAPSHOT = 24,
alox_MessageType_ACCEL_STREAM = 25
alox_MessageType_ACCEL_STREAM = 25,
alox_MessageType_BATTERY_STATUS = 26
} alox_MessageType;
/* Struct definitions */
@@ -108,6 +109,36 @@ typedef struct _alox_AccelStreamResponse {
uint32_t slaves_updated;
} alox_AccelStreamResponse;
/* * Host → master: read LiPo ADC voltages (master local and/or slaves via ESP-NOW). */
typedef struct _alox_BatteryStatusRequest {
/* * 0 = master only; >0 = one slave; ignored when all_clients */
uint32_t client_id;
/* * Master (client_id 0) plus every registered slave */
bool all_clients;
} alox_BatteryStatusRequest;
typedef struct _alox_LipoReading {
bool valid;
/* * Estimated pack voltage in millivolts from ADC */
uint32_t voltage_mv;
} alox_LipoReading;
typedef struct _alox_BatterySample {
uint32_t client_id;
bool has_lipo1;
alox_LipoReading lipo1;
bool has_lipo2;
alox_LipoReading lipo2;
/* * Milliseconds since last ESP-NOW battery report from this pod. */
uint32_t age_ms;
} alox_BatterySample;
typedef struct _alox_BatteryStatusResponse {
bool success;
pb_size_t samples_count;
alox_BatterySample samples[17];
} alox_BatteryStatusResponse;
/* Host → master: read cached accel samples from slaves (only while stream enabled).
client_id 0 = all registered slaves; otherwise one slave. */
typedef struct _alox_AccelSnapshotRequest {
@@ -271,6 +302,8 @@ typedef struct _alox_UartMessage {
alox_AccelSnapshotResponse accel_snapshot_response;
alox_AccelStreamRequest accel_stream_request;
alox_AccelStreamResponse accel_stream_response;
alox_BatteryStatusRequest battery_status_request;
alox_BatteryStatusResponse battery_status_response;
} payload;
} alox_UartMessage;
@@ -281,8 +314,8 @@ extern "C" {
/* Helper constants for enums */
#define _alox_MessageType_MIN alox_MessageType_UNKNOWN
#define _alox_MessageType_MAX alox_MessageType_ACCEL_STREAM
#define _alox_MessageType_ARRAYSIZE ((alox_MessageType)(alox_MessageType_ACCEL_STREAM+1))
#define _alox_MessageType_MAX alox_MessageType_BATTERY_STATUS
#define _alox_MessageType_ARRAYSIZE ((alox_MessageType)(alox_MessageType_BATTERY_STATUS+1))
#define alox_UartMessage_type_ENUMTYPE alox_MessageType
@@ -311,6 +344,10 @@ extern "C" {
@@ -329,6 +366,10 @@ extern "C" {
#define alox_AccelDeadzoneResponse_init_default {0, 0, 0, 0}
#define alox_AccelStreamRequest_init_default {0, 0, 0, 0}
#define alox_AccelStreamResponse_init_default {0, 0, 0, 0}
#define alox_BatteryStatusRequest_init_default {0, 0}
#define alox_LipoReading_init_default {0, 0}
#define alox_BatterySample_init_default {0, false, alox_LipoReading_init_default, false, alox_LipoReading_init_default, 0}
#define alox_BatteryStatusResponse_init_default {0, 0, {alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default, alox_BatterySample_init_default}}
#define alox_AccelSnapshotRequest_init_default {0}
#define alox_AccelSample_init_default {0, 0, 0, 0, 0, 0}
#define alox_AccelSnapshotResponse_init_default {0, {alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default}}
@@ -359,6 +400,10 @@ extern "C" {
#define alox_AccelDeadzoneResponse_init_zero {0, 0, 0, 0}
#define alox_AccelStreamRequest_init_zero {0, 0, 0, 0}
#define alox_AccelStreamResponse_init_zero {0, 0, 0, 0}
#define alox_BatteryStatusRequest_init_zero {0, 0}
#define alox_LipoReading_init_zero {0, 0}
#define alox_BatterySample_init_zero {0, false, alox_LipoReading_init_zero, false, alox_LipoReading_init_zero, 0}
#define alox_BatteryStatusResponse_init_zero {0, 0, {alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero, alox_BatterySample_init_zero}}
#define alox_AccelSnapshotRequest_init_zero {0}
#define alox_AccelSample_init_zero {0, 0, 0, 0, 0, 0}
#define alox_AccelSnapshotResponse_init_zero {0, {alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero}}
@@ -413,6 +458,16 @@ extern "C" {
#define alox_AccelStreamResponse_client_id_tag 2
#define alox_AccelStreamResponse_success_tag 3
#define alox_AccelStreamResponse_slaves_updated_tag 4
#define alox_BatteryStatusRequest_client_id_tag 1
#define alox_BatteryStatusRequest_all_clients_tag 2
#define alox_LipoReading_valid_tag 1
#define alox_LipoReading_voltage_mv_tag 2
#define alox_BatterySample_client_id_tag 1
#define alox_BatterySample_lipo1_tag 2
#define alox_BatterySample_lipo2_tag 3
#define alox_BatterySample_age_ms_tag 4
#define alox_BatteryStatusResponse_success_tag 1
#define alox_BatteryStatusResponse_samples_tag 2
#define alox_AccelSnapshotRequest_client_id_tag 1
#define alox_AccelSample_client_id_tag 1
#define alox_AccelSample_valid_tag 2
@@ -493,6 +548,8 @@ extern "C" {
#define alox_UartMessage_accel_snapshot_response_tag 24
#define alox_UartMessage_accel_stream_request_tag 25
#define alox_UartMessage_accel_stream_response_tag 26
#define alox_UartMessage_battery_status_request_tag 27
#define alox_UartMessage_battery_status_response_tag 28
/* Struct field encoding specification for nanopb */
#define alox_UartMessage_FIELDLIST(X, a) \
@@ -521,7 +578,9 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,restart_response,payload.restart_res
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_snapshot_request,payload.accel_snapshot_request), 23) \
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_snapshot_response,payload.accel_snapshot_response), 24) \
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_stream_request,payload.accel_stream_request), 25) \
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_stream_response,payload.accel_stream_response), 26)
X(a, STATIC, ONEOF, MESSAGE, (payload,accel_stream_response,payload.accel_stream_response), 26) \
X(a, STATIC, ONEOF, MESSAGE, (payload,battery_status_request,payload.battery_status_request), 27) \
X(a, STATIC, ONEOF, MESSAGE, (payload,battery_status_response,payload.battery_status_response), 28)
#define alox_UartMessage_CALLBACK NULL
#define alox_UartMessage_DEFAULT NULL
#define alox_UartMessage_payload_ack_payload_MSGTYPE alox_Ack
@@ -549,6 +608,8 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,accel_stream_response,payload.accel_
#define alox_UartMessage_payload_accel_snapshot_response_MSGTYPE alox_AccelSnapshotResponse
#define alox_UartMessage_payload_accel_stream_request_MSGTYPE alox_AccelStreamRequest
#define alox_UartMessage_payload_accel_stream_response_MSGTYPE alox_AccelStreamResponse
#define alox_UartMessage_payload_battery_status_request_MSGTYPE alox_BatteryStatusRequest
#define alox_UartMessage_payload_battery_status_response_MSGTYPE alox_BatteryStatusResponse
#define alox_Ack_FIELDLIST(X, a) \
@@ -631,6 +692,35 @@ X(a, STATIC, SINGULAR, UINT32, slaves_updated, 4)
#define alox_AccelStreamResponse_CALLBACK NULL
#define alox_AccelStreamResponse_DEFAULT NULL
#define alox_BatteryStatusRequest_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, client_id, 1) \
X(a, STATIC, SINGULAR, BOOL, all_clients, 2)
#define alox_BatteryStatusRequest_CALLBACK NULL
#define alox_BatteryStatusRequest_DEFAULT NULL
#define alox_LipoReading_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, BOOL, valid, 1) \
X(a, STATIC, SINGULAR, UINT32, voltage_mv, 2)
#define alox_LipoReading_CALLBACK NULL
#define alox_LipoReading_DEFAULT NULL
#define alox_BatterySample_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, client_id, 1) \
X(a, STATIC, OPTIONAL, MESSAGE, lipo1, 2) \
X(a, STATIC, OPTIONAL, MESSAGE, lipo2, 3) \
X(a, STATIC, SINGULAR, UINT32, age_ms, 4)
#define alox_BatterySample_CALLBACK NULL
#define alox_BatterySample_DEFAULT NULL
#define alox_BatterySample_lipo1_MSGTYPE alox_LipoReading
#define alox_BatterySample_lipo2_MSGTYPE alox_LipoReading
#define alox_BatteryStatusResponse_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, BOOL, success, 1) \
X(a, STATIC, REPEATED, MESSAGE, samples, 2)
#define alox_BatteryStatusResponse_CALLBACK NULL
#define alox_BatteryStatusResponse_DEFAULT NULL
#define alox_BatteryStatusResponse_samples_MSGTYPE alox_BatterySample
#define alox_AccelSnapshotRequest_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, client_id, 1)
#define alox_AccelSnapshotRequest_CALLBACK NULL
@@ -772,6 +862,10 @@ extern const pb_msgdesc_t alox_AccelDeadzoneRequest_msg;
extern const pb_msgdesc_t alox_AccelDeadzoneResponse_msg;
extern const pb_msgdesc_t alox_AccelStreamRequest_msg;
extern const pb_msgdesc_t alox_AccelStreamResponse_msg;
extern const pb_msgdesc_t alox_BatteryStatusRequest_msg;
extern const pb_msgdesc_t alox_LipoReading_msg;
extern const pb_msgdesc_t alox_BatterySample_msg;
extern const pb_msgdesc_t alox_BatteryStatusResponse_msg;
extern const pb_msgdesc_t alox_AccelSnapshotRequest_msg;
extern const pb_msgdesc_t alox_AccelSample_msg;
extern const pb_msgdesc_t alox_AccelSnapshotResponse_msg;
@@ -804,6 +898,10 @@ extern const pb_msgdesc_t alox_OtaSlaveProgressResponse_msg;
#define alox_AccelDeadzoneResponse_fields &alox_AccelDeadzoneResponse_msg
#define alox_AccelStreamRequest_fields &alox_AccelStreamRequest_msg
#define alox_AccelStreamResponse_fields &alox_AccelStreamResponse_msg
#define alox_BatteryStatusRequest_fields &alox_BatteryStatusRequest_msg
#define alox_LipoReading_fields &alox_LipoReading_msg
#define alox_BatterySample_fields &alox_BatterySample_msg
#define alox_BatteryStatusResponse_fields &alox_BatteryStatusResponse_msg
#define alox_AccelSnapshotRequest_fields &alox_AccelSnapshotRequest_msg
#define alox_AccelSample_fields &alox_AccelSample_msg
#define alox_AccelSnapshotResponse_fields &alox_AccelSnapshotResponse_msg
@@ -830,7 +928,7 @@ extern const pb_msgdesc_t alox_OtaSlaveProgressResponse_msg;
/* alox_ClientInfo_size depends on runtime parameters */
/* alox_ClientInfoResponse_size depends on runtime parameters */
/* alox_ClientInputResponse_size depends on runtime parameters */
#define ALOX_UART_MESSAGES_PB_H_MAX_SIZE alox_AccelSnapshotResponse_size
#define ALOX_UART_MESSAGES_PB_H_MAX_SIZE alox_BatteryStatusResponse_size
#define alox_AccelDeadzoneRequest_size 16
#define alox_AccelDeadzoneResponse_size 20
#define alox_AccelSample_size 32
@@ -839,6 +937,9 @@ extern const pb_msgdesc_t alox_OtaSlaveProgressResponse_msg;
#define alox_AccelStreamRequest_size 12
#define alox_AccelStreamResponse_size 16
#define alox_Ack_size 0
#define alox_BatterySample_size 32
#define alox_BatteryStatusRequest_size 8
#define alox_BatteryStatusResponse_size 580
#define alox_ClientInput_size 22
#define alox_EspNowFindMeRequest_size 6
#define alox_EspNowFindMeResponse_size 8
@@ -846,6 +947,7 @@ extern const pb_msgdesc_t alox_OtaSlaveProgressResponse_msg;
#define alox_EspNowUnicastTestResponse_size 8
#define alox_LedRingProgressRequest_size 64
#define alox_LedRingProgressResponse_size 32
#define alox_LipoReading_size 8
#define alox_OtaEndPayload_size 0
#define alox_OtaPayload_size 209
#define alox_OtaSlaveProgressEntry_size 30