Add Lua runtime: chip temp -> LED color -> HA, verified live
Sandboxed Lua state (espressif/lua v5.5.0, base/table/string/math only, no io/os/package/debug) exposes a kvida API table (chip_temperature, set_led, publish) to a compiled-in default script that reads chip temperature, maps it to an LED color, and publishes the reading to Home Assistant. Generalizes transport's publish_chip_temperature() into publish_value(name, value), the first real use of AGENTS.md's semantic publish API. Requires -DLUA_32BITS globally since this toolchain's long long support isn't visible to Lua's default build. Verified on real ESP32-C6 hardware: no crashes/errors across multiple serial monitor windows, LED changes color, chip_temperature sensor appears in Home Assistant via MQTT Discovery. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,18 +7,21 @@ namespace kvida {
|
||||
// Starts mDNS-based MQTT broker discovery (_mqtt._tcp) and, once found,
|
||||
// connects the MQTT client and publishes Home Assistant MQTT Discovery
|
||||
// for a diagnostic "connectivity" entity. Safe to call multiple times
|
||||
// (no-op if already connecting/connected). No public-facing semantic
|
||||
// publish(topic, value) API yet -- deferred until `profiles` has real
|
||||
// sensor data to publish (see components/transport/README.md).
|
||||
// (no-op if already connecting/connected).
|
||||
void start_mqtt();
|
||||
|
||||
bool mqtt_connected();
|
||||
|
||||
// Publishes (retained) Home Assistant MQTT Discovery for a diagnostic
|
||||
// "Chip temperature" sensor on first call, then the reading itself.
|
||||
// Quick end-to-end proof that a real Sensor implementation's data can
|
||||
// reach MQTT/HA -- not the eventual generic publish(topic, value) API.
|
||||
void publish_chip_temperature(float celsius);
|
||||
// Publishes a named numeric value as a Home Assistant MQTT Discovery
|
||||
// sensor: `kvida/<id>/<name>` state topic, `homeassistant/sensor/<id>/<name>/config`
|
||||
// discovery topic. This is the semantic publish(name, value) API AGENTS.md
|
||||
// describes -- driven by `lua_runtime`'s `kvida.publish()`, not called
|
||||
// directly by other components. Discovery is republished (retained, so
|
||||
// idempotent) on every call rather than cached behind a per-name
|
||||
// "already announced" flag -- simpler, at the cost of a bit of extra
|
||||
// retained-message traffic each call. TODO: cache announced names if
|
||||
// that traffic becomes a real concern.
|
||||
void publish_value(const char *name, double value);
|
||||
|
||||
// Registered by main to receive "set LED color" commands from Home
|
||||
// Assistant (an RGB light entity) without transport depending on
|
||||
|
||||
Reference in New Issue
Block a user