feat: multi-device support + HA discovery and energy fixes#1
Open
SobolevTim wants to merge 1 commit into
Open
Conversation
Adds support for up to 4 simultaneous meteo sensors and 4 power meters
in the hub without requiring firmware changes on the sensor devices
(deviceId from PacketHeader is used for slot routing).
Bug fixes:
- Fix humidity showing "Unavailable" in HA: send JSON null when AHT20
reports FLAG_AHT_ERROR, instead of -999.0 which HA 2024+ rejects
- Fix HA device grouping: device["identifiers"] was a JSON string,
now correctly a JSON array via createNestedArray("identifiers")
- Fix buffer overflow in discovery messages: char message[512] → [1024]
with sizeof(message) guard on serializeJson
- Fix RSSI sensor not published: serializeJson+publish was missing before
the flags section in publishMeteoDiscovery and publishPowerDiscovery
- Fix energy counter stuck after PZEM reset: introduced backstepObserved
flag so allowEnergyBackstep is only cleared when an actual decrease
is observed, not on every packet
- Fix phase disconnect: all four fields (voltage/current/power/pf) set
to 0 when phase is unavailable; energy omitted so HA retains last value
Multi-device architecture:
- MeteoDeviceSlot[4] and PowerDeviceSlot[4] arrays replace singletons
- findOrAllocMeteoSlot / findOrAllocPowerSlot with deviceId lookup
- Per-slot: discoveryPublished, pendingPublication, lastPublishAttempt,
lastEnergy[], phaseEnergyInit[], allowEnergyBackstep
- Thread ownership annotations: [mutex], [core0], [core1]
- NVS persistence with indexed keys (mt0_*, mt1_*, pw0_*, pw1_*)
all ≤12 chars, within ESP-IDF 15-char NVS key limit
- Web UI iterates all valid slots, shows 0x%04X deviceId per device
- handleCommand reads deviceId hex arg for per-device command routing
- handleApi returns JSON arrays for all meteo and power slots
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
deviceIdиз заголовка пакета)Изменения
Мультиустройство
MeteoDeviceSlot[4]иPowerDeviceSlot[4]вместо глобальных переменных-синглтоновfindOrAllocMeteoSlot/findOrAllocPowerSlot— поиск слота поdeviceIdили выделение новогоdiscoveryPublished,pendingPublication,lastEnergy[],allowEnergyBackstep[mutex],[core0],[core1]mt0_*,mt1_*,pw0_*) — все ≤12 символов/apiитерируют все активные слотыBug fixes
nullptrвместо-999.0приFLAG_AHT_ERRORdevice["identifiers"]→ JSON array черезcreateNestedArraychar message[512]→[1024]+sizeof(message)guardserializeJson+publishперед секцией флаговbackstepObservedфлаг —allowEnergyBackstepочищается только при реальном уменьшенииTest plan
deviceId— оба должны появиться отдельными устройствами в HA/api— должен вернуть массивыmeteo[]иpower[]🤖 Generated with Claude Code