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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LQI and RSSI sensors for some devices #153

Merged
merged 7 commits into from
Oct 11, 2023
Merged

LQI and RSSI sensors for some devices #153

merged 7 commits into from
Oct 11, 2023

Conversation

Shulyaka
Copy link
Contributor

@Shulyaka Shulyaka commented Sep 30, 2023

This PR adds LQI and RSSI sensors to certain devices.

Problem:
The XBee API does not provide an API to directly measure LQI of a zigbee packet. There is DB (Last Packet RSSI) AT command that measures the RSSI of a last received packet, but 0x91 Explicit Receive Indicator API frame is missing the address of the last hop node, so it is not clear to which device the RSSI is related. It also lacks the LQI or RSSI info. There is ND (Network Discovery) AT command which can provide the RSSI of a node, but this only works for other XBee devices and not any Zigbee device. There is also AS (Active Scan) AT command which provides both LQI and RSSI information, but the active scan ignores the network topology and thus useless, it does not also work on end devices because they are sleeping nodes an don't respond to the scan.

But not all hope is lost.

Solution:
Instead o relying on the API, we will use ZDO. In fact, we already do all the needed ZDO requests for the topology scan. All e need is to listen and interpret the results. The sensor values will be updated as often as the topology scan is run (every hours by default and min 20 minutes).

LQI: As part of topology scanning we do a neighbors scan from all routers by sending Mgmt_Lqi_req. The response is a table of neighbors, including their relationship and LQI. If a neighbor is a parent, then we save the LQI for the device that responded, and if a neighbor is a child, then we save the LQI for the child. Siblings and other devices are ignored.
Limitation: Because the XBee devices don't handle well self-addressed ZDO requests, this does not work for end devices that are immediate children of the coordinator.

RSSI: For the topology scan we also request the route information from the routers, by sending Mgmt_Rtg_req ZDO request. The response is a list of routes from the node. If that response contains a direct route to the coordinator, we realize it is the last hop, so we immediately execute the DB AT command and save the RSSI value.
Limitation: This technique only works for routers that are direct children of the coordinator.

@codecov
Copy link

codecov bot commented Oct 3, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (39ef2f1) 100.00% compared to head (576f148) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #153   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          758       779   +21     
=========================================
+ Hits           758       779   +21     
Files Coverage Δ
zigpy_xbee/zigbee/application.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Shulyaka
Copy link
Contributor Author

Shulyaka commented Oct 3, 2023

Rebased and added tests

zigpy_xbee/zigbee/application.py Outdated Show resolved Hide resolved
zigpy_xbee/zigbee/application.py Outdated Show resolved Hide resolved
@Shulyaka Shulyaka requested a review from puddly October 9, 2023 21:12
@puddly puddly merged commit 468fe69 into zigpy:dev Oct 11, 2023
14 checks passed
@Shulyaka Shulyaka deleted the lqi_scan branch October 11, 2023 22:12
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.

2 participants