Skip to content

MySensors: generic FOTA scripts and OTA duration fields - #46

Merged
jkandasa merged 3 commits into
mycontroller-org:mainfrom
jkandasa:generic_ota
Sep 6, 2026
Merged

MySensors: generic FOTA scripts and OTA duration fields#46
jkandasa merged 3 commits into
mycontroller-org:mainfrom
jkandasa:generic_ota

Conversation

@jkandasa

@jkandasa jkandasa commented Sep 6, 2026

Copy link
Copy Markdown
Member

Summary

Adds a generic firmware-selection hook for the MySensors v2 gateway. Policy lives in a data-repository JavaScript (onConfig, optional onBlock), not in Go. A sample STM32 A/B script is documented in docs/ota_stm32_ab.md.

Also records how long a completed OTA took.

FOTA scripts

When a node has fota_script set to a data-repository id:

  • onConfig chooses the image (firmwareId, noUpdate, or responseHex).
  • onBlock is optional; the firmwareId from onConfig is reused.
  • assigned_firmware is not used, even if the repository is missing or data.disabled is true.
  • Missing repository is an error. Disabled script echoes CONFIG (no update) and does not send blocks.

When fota_script is empty, the existing assigned_firmware path is unchanged.

getFirmware(id) is injected for scripts that need type, version, CRC, checksum, and the first 16 image bytes (head).

Node labels

Label Meaning
fota_script Data-repository id. Non-empty owns firmware selection.
fota_disabled true turns off all OTA for that node (script and stock).

The sample script also writes ab_* labels (running/request slot, last reported type/version/CRC, image being served). Those keys are policy, not core.

OTA progress

On a finished transfer, node others now includes:

  • ota_time_taken: duration in seconds
  • ota_time_taken_str: compact form, e.g. 4m37s

Start/end timestamps that were stored as RFC3339 strings are parsed so the duration is actually filled in.

Notes

  • Empty UI firmware-update payload does not invent a type/version/CRC.
  • Script debug logs skip function values (getFirmware) so they encode as JSON.
  • Empty label values no longer log a ParseBool error.

Firmware selection can live in a data_repository script (fota_script).
If that label is set, assigned_firmware is never used, even when the
script is missing or disabled. Record completed OTA time in seconds
and ota_time_taken_str (for example 1m40s).
# Conflicts:
#	plugin/gateway/provider/mysensors_v2/event_listener.go
Rewrite the event type check with De Morgan's law. Gateway and
handler Start block on success, so drop the always-true err != nil
guard that staticcheck SA4023 flags.
@jkandasa
jkandasa merged commit a6a8cea into mycontroller-org:main Sep 6, 2026
1 check passed
@jkandasa
jkandasa deleted the generic_ota branch September 6, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant