Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve broadcasting via sendZclFrameToAll #1028

Merged
merged 28 commits into from
Apr 28, 2024

Conversation

burmistrzak
Copy link
Contributor

Just adds an optional parameter to the sendZclFrameToAll method so sleepy end devices (i.e. 0xFFFF) can be included in broadcast messages. 馃槉

Seems to be required for this to work properly.

@Nerivec
Copy link
Collaborator

Nerivec commented Apr 23, 2024

I'd say no boolean, just a variable for the address:

/** Broadcast to all routers. */
export const BROADCAST_ADDRESS = 0xFFFC;
/** Broadcast to all non-sleepy devices. */
export const BROADCAST_RX_ON_WHEN_IDLE_ADDRESS = 0xFFFD;
/** Broadcast to all devices, including sleepy end devices. */
export const BROADCAST_SLEEPY_ADDRESS = 0xFFFF;

These should be with Zigbee spec types, usable everywhere.

And the adapter function becomes

public abstract sendZclFrameToAll(endpoint: number, zclFrame: ZclFrame, sourceEndpoint: number, address: number = BROADCAST_ADDRESS): Promise<void>;

Note:

ZigBee specifies three different broadcast addresses that reach different collections of nodes. Broadcasts are normally sent only to routers. Broadcasts can also be forwarded to end devices, either all of them or only those that do not sleep. Broadcasting to end devices is both significantly more resource-intensive and significantly less reliable than broadcasting to routers.

* Support custom clusters

* WIP

* updates

* updates

* updates

* update

* updates

* Process feedback

* fix lint
@burmistrzak
Copy link
Contributor Author

I'd say no boolean, just a variable for the address:

Funnily enough, that was my initial idea. 馃槉

These should be with Zigbee spec types, usable everywhere.

Sure, is adapter.ts the right place for such definitions?

And the adapter function becomes

public abstract sendZclFrameToAll(endpoint: number, zclFrame: ZclFrame, sourceEndpoint: number, address: number = BROADCAST_ADDRESS): Promise<void>;

We'll have to keep the current behavior, so BROADCAST_RX_ON_WHEN_IDLE_ADDRESS should be default.

ZigBee specifies three different broadcast addresses that reach different collections of nodes. Broadcasts are normally sent only to routers. Broadcasts can also be forwarded to end devices, either all of them or only those that do not sleep. Broadcasting to end devices is both significantly more resource-intensive and significantly less reliable than broadcasting to routers.

For the mentioned use.case, reaching every sleeping ZED seems kinda important. 馃槈

@Nerivec
Copy link
Collaborator

Nerivec commented Apr 23, 2024

Only 6 use cases of sendZclFrameToAll currently, all are for GP, so not complicated to refactor. Better to use the proper default broadcast (FFFC) and change calls as needed to FFFD or FFFF by specifying it.

@burmistrzak
Copy link
Contributor Author

Only 6 use cases of sendZclFrameToAll currently, all are for GP, so not complicated to refactor. Better to use the proper default broadcast (FFFC) and change calls as needed to FFFD or FFFF by specifying it.

Sounds reasonable.
Will do that next, when I'm done here.

@burmistrzak
Copy link
Contributor Author

burmistrzak commented Apr 23, 2024

These should be with Zigbee spec types, usable everywhere.

@Nerivec Not entirely sure what you mean by that. Can you please elaborate?

Edit: Do you mean something similar to status.ts, e.g. Zcl.Broadcast.NON_SLEEPY_DEVICES? 馃

@Nerivec
Copy link
Collaborator

Nerivec commented Apr 24, 2024

@Koenkk Not sure what convention we want to use for naming, but since we're gonna introduce the zdo spec too, I figure we can put global stuff at the root and zcl/zdo as subfolders. Feel free to rename! (I didn't move the content of the zcl folder here, since that's a bigger refactor. I also didn't add the million or so consts that can be introduced to remove magic numbers/strings throughout the code 馃榿)

I added a test that mirrors the requirements of the Bosch in Koenkk/zigbee-herdsman-converters#7427. I think it makes more sense that way?
ZHC can just do

 await meta.device.triggerBroadcast(255, 1, BroadcastAddress.SLEEPY, Zcl.Direction.CLIENT_TO_SERVER, 'boschSmokeDetectorSiren', Zcl.Clusters.ssIasZone.ID, {data: index});

@Nerivec Nerivec changed the title Add optional inclSleepyZED parameter to sendZclFrameToAll Improve broadcasting via sendZclFrameToAll Apr 24, 2024
@burmistrzak
Copy link
Contributor Author

Not sure what convention we want to use for naming, but since we're gonna introduce the zdo spec too, I figure we can put global stuff at the root and zcl/zdo as subfolders.

Ah, I see! So I wasn't that far off with my guess. 馃槄

ZHC can just do

 await meta.device.triggerBroadcast(255, 1, BroadcastAddress.SLEEPY, Zcl.Direction.CLIENT_TO_SERVER, 'boschSmokeDetectorSiren', Zcl.Clusters.ssIasZone.ID, {data: index});

Very elegant solution!
Makes it generally more useful for converter developers. Excellent job! 馃

@burmistrzak
Copy link
Contributor Author

Can we export BroadcastAddress (or better zspec) at the root, so using it from ZHC is more convenient?

@Nerivec
Copy link
Collaborator

Nerivec commented Apr 24, 2024

Waiting for Koenkk's input on naming & co, so we can export this properly. The spec folder structure will affect a lot of stuff, better to start with a solid base.

@Nerivec
Copy link
Collaborator

Nerivec commented Apr 26, 2024

I figure, might as well keep entirely in line with the rest, so zclCommandToAll seems the best option?

@Koenkk Can you confirm if this.customClusters should be passed in this scenario (to getCluster and to ZclFrame.create)? Same question for this.manufacturerID to getCluster (that's what endpoint is using)? Seems a bit conflicting between using device (this) and using options.

@burmistrzak
Copy link
Contributor Author

I figure, might as well keep entirely in line with the rest, so zclCommandToAll seems the best option?

Agree. 馃憤
And thanks for cleaning up after me, looking good so far. 馃

@burmistrzak
Copy link
Contributor Author

Waiting for Koenkk's input on naming & co, so we can export this properly. The spec folder structure will affect a lot of stuff, better to start with a solid base.

@Koenkk The proposed folder structure seems sensible, but we'll eventually have to move ZCL to the Zspec directory.

  • src/zspec/
  • src/zspec/zcl/
  • src/zspec/zdo/

Ultimately, it's your decision. 馃槈

@Nerivec
Copy link
Collaborator

Nerivec commented Apr 28, 2024

The move will be in a separate PR. It was just the right time to create the base for it since we needed a couple of "global zigbee" consts for this.

@burmistrzak
Copy link
Contributor Author

burmistrzak commented Apr 28, 2024

The move will be in a separate PR. It was just the right time to create the base for it since we needed a couple of "global zigbee" consts for this.

Sounds good.
Should we already export BroadcastAddress (e.g. as Zspec.BroadcastAddress.SLEEPY), before the "big move" PR comes around? Or do we want to keep these things in separate PRs?

@Koenkk Koenkk merged commit ccfd299 into Koenkk:master Apr 28, 2024
1 check passed
@Koenkk
Copy link
Owner

Koenkk commented Apr 28, 2024

@burmistrzak let's do this in a separate PR such that we can also merge Koenkk/zigbee-herdsman-converters#7427 before the new release.

@burmistrzak burmistrzak deleted the feat-sendZclFrameToAll-sleepyZED branch May 2, 2024 20:14
@Nerivec Nerivec mentioned this pull request May 6, 2024
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.

None yet

3 participants