Skip to content

feat(identify): identify a device from the cloud and from its button - #12

Merged
reubenmiller merged 1 commit into
mainfrom
feat/device-identify
Oct 6, 2026
Merged

reubenmiller merged 1 commit into
mainfrom
feat/device-identify

Conversation

@reubenmiller

Copy link
Copy Markdown
Contributor

With several identical boards on a bench, the device list in Cumulocity doesn't say which board is which. This makes every tedge-* image identifiable both ways.

Changes

  • Cloud → device: tedge identify [seconds], a new shell subcommand under the client's tedge root (lib/common/identify.c), blinks the status LED in the existing identify pattern (fast 5 Hz, white on an RGB LED). Default 30 s, capped at 300 s; it returns at once, so the operation succeeds immediately. The cloud runs it through c8y_Command (Shell tab). It is added to the allow-list in extras/shell-diagnostics.conf, so it works wherever the cloud shell ships.
  • Device → cloud: two quick presses of sw0 (BOOT) send a zephyr_Identify event (Identify button pressed on <hostname>, at most one per 5 s) and flash the LED. The device keeps serving; the provisioning triple-press and erase hold are unchanged, and the build fails if the two press counts are equal.
  • cumulocity/smart-functions/tedge-zephyr-events/: maps te/device/*///e/* to Cumulocity events. Nothing mapped device events on the MQTT Service before, so no tedge-zephyr event reached the tenant. Deployed to eu-latest.
  • sw0 refactor: GPIO/debounce move from prov_handoff.c to button.c (CONFIG_APP_BUTTON), so the button works with either feature. The gesture classifier gets an identify count, and any gesture can be switched off; host tests cover the new cases.
  • Fix (tedge-zephyr): a shell command that failed through shell_error() left its operation EXECUTING forever, because the shell's ANSI colour codes ended up in the 505 status and Cumulocity rejected it ("contains invalid characters"). Captured output is now stripped of escape sequences (tedge_shell_clean_output()), and SmartREST quoting drops any remaining control character. Line breaks stay inside the quoted field.
  • New Kconfig: APP_IDENTIFY (default y with TEDGE), APP_IDENTIFY_DURATION_S (30), APP_IDENTIFY_PRESS_COUNT (2). No public tedge_* API change.
  • Docs: README "Identifying a device", button gesture table, DEVICES.md "Identify measured"; OpenSpec change device-identify archived (new device-identify spec; tedge-diagnostics and wifi-provisioning updated).

Cloud identify needs the cloud shell, so today it is on the S3-DevKitC and QT Py modbus/agent full images only. The button works on every tedge-* image with sw0.

Testing

  • native_sim unit suite (93 tests, 3 new), Kconfig checks (27/27), button gesture host tests, check-independence.py.
  • All 36 release/devices.yml builds plus native_sim; release/size-baseline.json rewritten. Against main built the same way: S3 modbus full + shell +463 B image / +32 B dram0; WROOM agent ota +336 B / +24 B.
  • On eu-latest, app-only flashes keeping Wi-Fi and identity:
    • S3-DevKitC and QT Py S3 (modbus full + shell): tedge identify, 10, 3600 (→ 300) succeed in 1–3 s; 0, soon, 1 2 and kernel uptime too many args now end FAILED with the reason (they stayed EXECUTING before the fix); help lists the command.
    • ESP32-C6 (no shell): c8y_Command is not advertised, and a tedge identify sent anyway fails with "no handler (511)".
    • S3, QT Py, C6 and ESP32-CAM: a double press puts a zephyr_Identify event on the right device within ~2 s; LED behaviour confirmed by eye on all four.
  • Events Smart Function tests pass in the tenant's Data Preparation runtime.

🤖 Generated with Claude Code

With several identical boards it was hard to tell which cloud device is
which board. Every tedge-* image can now be matched both ways:

- Cloud to device: `tedge identify [seconds]` (a shell subcommand, run
  through c8y_Command) blinks the status LED in the identify pattern for
  30 s by default, at most 300 s, and returns at once. It is on the
  shell-diagnostics allow-list.
- Device to cloud: two quick presses of sw0 send a zephyr_Identify event
  naming the hostname (at most one per 5 s), acknowledged on the LED. The
  device keeps serving. The new tedge-zephyr-events Smart Function maps
  te/device/*///e/* to Cumulocity events, which nothing did before.

The sw0 watcher moves out of the provisioning hand-off into button.c, so
it runs with either feature; the gesture classifier gains the identify
count, and each gesture can be switched off.

Also fixes tedge-zephyr leaving a failed shell command EXECUTING: the
shell wraps shell_error() text in ANSI colour codes, and Cumulocity
refuses a status message that carries them. Captured output is now
stripped of escape sequences, and SmartREST quoting drops any other
control character (line breaks stay inside the quoted field).

Tested on an S3-DevKitC, a QT Py S3, an ESP32-C6 and an ESP32-CAM.
Image +463 B / dram0 +32 B on the S3 modbus full build against main;
release/size-baseline.json updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@reubenmiller
reubenmiller merged commit 79992c1 into main Oct 6, 2026
23 checks passed
@reubenmiller
reubenmiller deleted the feat/device-identify branch October 6, 2026 19:33
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