-
Notifications
You must be signed in to change notification settings - Fork 41
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
how to send association request with zigpy-znp #152
Comments
Zigpy currently focuses on managing the device as a coordinator, not a router, so this isn't directly supported. However, you can use the low-level operations in zigpy-znp to join an existing network: import sys
import asyncio
import logging
import zigpy.types as t
import zigpy.exceptions
import zigpy.zdo.types as zdo_t
import zigpy_znp.commands as c
import zigpy_znp.types as znp_t
from zigpy_znp.tools.common import setup_parser
from zigpy_znp.zigbee.application import (
ControllerApplication as ZNPControllerApplication,
)
LOGGER = logging.getLogger(__name__)
async def test_join_as_router(radio_path):
app = ZNPControllerApplication({"device": {"path": radio_path}})
await app.connect()
try:
# Always throws `NetworkNotFormed`, needs to be fixed for routers
await app.load_network_info()
except zigpy.exceptions.NetworkNotFormed:
await app.form_network()
if app.state.node_info.logical_type != zdo_t.LogicalType.Router:
await app.write_network_info(
node_info=app.state.node_info.replace(
logical_type=zdo_t.LogicalType.Router, nwk=0x1234
),
network_info=app.state.network_info,
)
joined_as_router = app._znp.wait_for_response(
c.ZDO.StateChangeInd.Callback(State=znp_t.DeviceState.JoinedAsRouter)
)
# Run `zigpy_znp/tools/network_scan.py` to scan for networks
await app._znp.request(
c.ZDO.JoinReq.Req(
LogicalChannel=25,
PanId=0xABCD,
ExtendedPanId=t.EUI64.convert("AA:BB:CC:DD:AA:BB:CC:DD"),
ChosenParent=0x380A,
Depth=1,
StackProfile=2,
),
callback=c.ZDO.JoinCnf.Callback(partial=True),
)
# TODO: how do you re-join a network? The network key is not stored in NVRAM...
await joined_as_router
await asyncio.sleep(60)
await app.shutdown()
async def main(argv):
parser = setup_parser("Test joining a network as a router")
args = parser.parse_args(argv)
await test_join_as_router(args.serial)
if __name__ == "__main__":
asyncio.run(main(sys.argv[1:])) # pragma: no cover After the device joined my network, however, it did not respond to the coordinator's node descriptor request and I can't figure out how to re-join a network. Z-Stack's serial MT interface isn't documented very well so you will have to figure out how to get router mode properly working (if it's even possible using the coordinator firmware). If you do, please post an update! |
oh thank you!!!
|
I didn't see one, nor could I find the key in NVRAM. I think there is something that must be done after the join request succeeds. You should be able to sniff it being sent over-the-air though. |
i had try to use killerbee to forge an end device,which send and recv capture at sametime. |
My mistake. The above code depends on the new radio API: zigpy/zigpy-cli#2 |
Z-Stack has two types of requests:
If your command returns a response and then a callback, you would use |
@jbgod how did you resolve this? |
i can't solve this by zigpy. |
i can't find the document abot zigpy-znp.i read the source code.
i find there is not RSP about the c.MAC only REQ find.
i also try the c.ZDO.JoinReq.Req and c.ZDO.NwkAddrReq.Req but it is no work.
i want to use my cc2652 work as an endpoit to join my normal zigbee gateway.
The text was updated successfully, but these errors were encountered: