Skip to content

Conversation

@miri64
Copy link
Member

@miri64 miri64 commented Nov 16, 2024

Contribution description

Little weekend (or rather Thursday and Friday night) project of mine. This extends Skald, who advertises to the world with BTHome, "an energy efficient but flexible BLE format for devices to broadcast their sensor data and button presses". The main use case is to integrate BLE-powered devices into Home Assistant.

Most of the spec is supported, except "Trigger based advertisements" (since Skald at the moment only advertises periodically). For encryption, I was able to confirm with the spec examples that at least from the generated output
is the expected one, given the example input, but Home Assistant is for some reason not able to decrypt the message (even the one in the examples)... So further investigation is needed.

TODOs:

  • Investigate why encryption does not work with HA
  • Finish doc

Testing procedure

  • TODO: Provide tests

So far only tested by flashing a node and seeing the device pop-up in Home Assistant:

image
image

Issues/PRs references

None

@miri64 miri64 requested review from bergzand and maribu November 16, 2024 11:05
@github-actions github-actions bot added Area: network Area: Networking Area: doc Area: Documentation Area: build system Area: Build system Area: drivers Area: Device drivers Area: BLE Area: Bluetooth Low Energy support Area: sys Area: System Area: examples Area: Example Applications labels Nov 16, 2024
@miri64 miri64 marked this pull request as draft November 16, 2024 11:09
@miri64 miri64 added State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Type: new feature The issue requests / The PR implemements a new feature for RIOT labels Nov 16, 2024
@miri64
Copy link
Member Author

miri64 commented Nov 26, 2024

Investigate why encryption does not work with HA

After talking to @BOZHENG001, I think the problem is that Skald is implementing an older BLE version than BTHome expects and thus fields (such as TXAdd which is used as part of the nonce for encryption) are not in the place Home Assistant expects them to be. Will try to confirm this somehow.

@miri64 miri64 force-pushed the bthome/feat/initial branch from adea8cd to 5d6f27b Compare November 26, 2024 20:36
/* start advertising */
_sched_next(ctx);
#if IS_USED(MODULE_SKALD_UPDATE_PKT_CB)
event_loop(&ctx->queue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale for introducing an event queue here? This will prevent the skald_adv_start function from returning, which should at least be documented somewhere for the user.

But I would rather call the user-provided callback within ISR context and shift thread-safety and the onus of having an event queue to the user side.

Copy link
Contributor

@kfessel kfessel Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of starting and running a queue exclusiv for skald a already exiting one might be used either given by parameter to skald_adv_start or CONFIG_SKALD_QUEUE or just depending on event_thread

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just depending on event_thread

That'd sound more sensible to me. Also, I think this dependence would then only be needed for skald_bthome_saul and not for skald_update_pkt_cb.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I just copied that behavior from the other skald “daemons” (that's what I see them as). I can have a look, if I find some time.

@crasbe crasbe added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: needs rebase State: The codebase was changed since the creation of the PR, making a rebase necessary and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 5, 2025
@miri64 miri64 force-pushed the bthome/feat/initial branch from f2afd01 to 5f22fdb Compare September 5, 2025 08:47
@miri64
Copy link
Member Author

miri64 commented Sep 5, 2025

Rebased to current master

@crasbe crasbe added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed State: needs rebase State: The codebase was changed since the creation of the PR, making a rebase necessary labels Sep 5, 2025
@miri64 miri64 force-pushed the bthome/feat/initial branch 2 times, most recently from 2a68e3b to eed3e65 Compare September 5, 2025 09:29
@miri64 miri64 force-pushed the bthome/feat/initial branch 2 times, most recently from 433bfca to 462222a Compare September 5, 2025 09:48
@miri64 miri64 force-pushed the bthome/feat/initial branch from b907d14 to 7bf991b Compare September 5, 2025 11:08
@miri64
Copy link
Member Author

miri64 commented Sep 5, 2025

I think I addressed all your comments now.

What I will now do, to get this in a mergeable state:

  • Split out encryption into another (draft) PR. Since we need BLE 5 support for skald for this, I don't expect that to be merged anytime soon, but this way we at least have a memorandum.
  • Provide tests for BTHome and or BTHome+Skald.

@miri64 miri64 force-pushed the bthome/feat/initial branch 3 times, most recently from 9a1845a to e31af82 Compare September 5, 2025 11:26
@miri64
Copy link
Member Author

miri64 commented Sep 5, 2025

Encryption part is now in #21699

@miri64 miri64 force-pushed the bthome/feat/initial branch from e31af82 to f24fbc4 Compare September 5, 2025 11:42
@riot-ci
Copy link

riot-ci commented Sep 5, 2025

Murdock results

✔️ PASSED

ad6d2d4 squash! tests: add test for BTHome

Success Failures Total Runtime
10518 0 10518 16m:28s

Artifacts

@github-actions github-actions bot added the Area: tests Area: tests and testing framework label Sep 5, 2025
@miri64
Copy link
Member Author

miri64 commented Sep 5, 2025

Added a test, it is still WIP though (did not check if the output is actually correct and I also want to increase the coverage).

@miri64 miri64 force-pushed the bthome/feat/initial branch from 802e09c to 4b47bbf Compare September 5, 2025 13:49
Comment on lines +128 to +133
// if ((res = skald_bthome_add_int8_measurement(
// &_ctx, BTHOME_ID_TEMPERATURE_FACTOR_1, 0x12
// )) < 0) {
// printf("Unable to add temperature factor 1 measurement: %s\n", strerror(res));
// return 1;
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// if ((res = skald_bthome_add_int8_measurement(
// &_ctx, BTHOME_ID_TEMPERATURE_FACTOR_1, 0x12
// )) < 0) {
// printf("Unable to add temperature factor 1 measurement: %s\n", strerror(res));
// return 1;
// }
/* if ((res = skald_bthome_add_int8_measurement(
* &_ctx, BTHOME_ID_TEMPERATURE_FACTOR_1, 0x12
* )) < 0) {
* printf("Unable to add temperature factor 1 measurement: %s\n", strerror(res));
* return 1;
* }
*/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason to keep this, actually (in case the test output is correct). However, it also serves as a test if the overflow protection works. So keeping as is ftm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: BLE Area: Bluetooth Low Energy support Area: build system Area: Build system Area: doc Area: Documentation Area: drivers Area: Device drivers Area: examples Area: Example Applications Area: network Area: Networking Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants