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

Can not permit join #130

Open
hwzolin opened this issue Sep 21, 2022 · 1 comment
Open

Can not permit join #130

hwzolin opened this issue Sep 21, 2022 · 1 comment

Comments

@hwzolin
Copy link

hwzolin commented Sep 21, 2022

Hi, I have a question need you help.
I use zigpy-cli and add a function to permit join. The code is in the picture below.
image

It calls the "permit_ncp" function in the "application" file in the "zigpy zigate" library. This function calls the "permit_join" function in the "api" file of the same code base.

The dongle I use is nxp 5169. After running the code, my zigbee device cannot be added by dongle. But in Python's third-party code library "zigate", after I use the code connect dongle and the command "z.permit_join()", the led light on dongle can flash, and the device can be added normally.
image

This shows that my dongle is normal. But why can't I use zigpy zigate to achieve the same effect? I looked at the data sent by the function "permit_join", the data contains b'00003c01'. As shown below:
image
I looked at the source code, this is what was set when serializing.
image
But in the zigate library, I see the command and data when sending permit is "return self.send_data(0x0049, 'FFFC{:02X}00'.format(duration))"
image
I don't know what the difference is between b'00003c01' and b'fffc3c00' if the wait time is set to 60 seconds. But I still changed the code of the function permit_join in the zigpy-zigate library to the one shown in the following figure.
image
This makes the permit join command issued by zigpy-zigate consistent with that of zigate. But my dongle still does not enter the permit join mode, and the device cannot be added. I don't know what else is wrong or insufficient. Could you help me to see the problem?

The following is the log of the code running, please help to take a look, thank you.

2022-09-21 15:22:18.963 Computer-2021QA asyncio DEBUG Using proactor: IocpProactor
2022-09-21 15:22:19.072 Computer-2021QA zigpy.appdb DEBUG SQLite version for <module 'sqlite3' from 'D:\\software\\python3.10\\lib\\sqlite3\\__init__.py'>: 3.37.2
2022-09-21 15:22:19.148 Computer-2021QA zigpy_zigate.uart DEBUG Connection made
2022-09-21 15:22:19.148 Computer-2021QA zigpy_zigate.api DEBUG Sending CommandId.SET_RAWMODE (b'\x01'), waiting for status: True, waiting for response: None
2022-09-21 15:22:19.148 Computer-2021QA zigpy_zigate.uart DEBUG Send: 0x0002 b'01'
2022-09-21 15:22:19.148 Computer-2021QA zigpy_zigate.uart DEBUG Frame to send: b'\x00\x02\x00\x01\x02\x01'
2022-09-21 15:22:19.148 Computer-2021QA zigpy_zigate.uart DEBUG Frame escaped: b'\x02\x10\x02\x12\x02\x10\x02\x11\x02\x12\x02\x11'
2022-09-21 15:22:19.148 Computer-2021QA zigpy_zigate.api DEBUG Wait for status to command CommandId.SET_RAWMODE
2022-09-21 15:22:19.164 Computer-2021QA zigpy_zigate.uart DEBUG Frame received: 800000098b000000020000000000
2022-09-21 15:22:19.164 Computer-2021QA zigpy_zigate.api DEBUG data received 0x8000 b'0000000200000000' LQI:0
2022-09-21 15:22:19.164 Computer-2021QA zigpy_zigate.zigbee.application DEBUG zigate_callback_handler ResponseId.STATUS [<Status.Success: 0>, 0, 2, b'\x00\x00\x00\x00']
2022-09-21 15:22:19.164 Computer-2021QA zigpy_zigate.api DEBUG Sending CommandId.SET_TIMESERVER (b'*\xbd\xe8\xab'), waiting for status: True, waiting for response: None
2022-09-21 15:22:19.164 Computer-2021QA zigpy_zigate.uart DEBUG Send: 0x0016 b'2abde8ab'
2022-09-21 15:22:19.164 Computer-2021QA zigpy_zigate.uart DEBUG Frame to send: b'\x00\x16\x00\x04\xc6*\xbd\xe8\xab'
2022-09-21 15:22:19.164 Computer-2021QA zigpy_zigate.uart DEBUG Frame escaped: b'\x02\x10\x16\x02\x10\x02\x14\xc6*\xbd\xe8\xab'
2022-09-21 15:22:19.164 Computer-2021QA zigpy_zigate.api DEBUG Wait for status to command CommandId.SET_TIMESERVER
2022-09-21 15:22:19.179 Computer-2021QA zigpy_zigate.uart DEBUG Frame received: 800000099f000000160000000000
2022-09-21 15:22:19.179 Computer-2021QA zigpy_zigate.api DEBUG data received 0x8000 b'0000001600000000' LQI:0
2022-09-21 15:22:19.179 Computer-2021QA zigpy_zigate.zigbee.application DEBUG zigate_callback_handler ResponseId.STATUS [<Status.Success: 0>, 0, 22, b'\x00\x00\x00\x00']
2022-09-21 15:22:19.179 Computer-2021QA zigpy_zigate.api DEBUG Sending CommandId.GET_VERSION (b''), waiting for status: True, waiting for response: ResponseId.VERSION_LIST
2022-09-21 15:22:19.179 Computer-2021QA zigpy_zigate.uart DEBUG Send: 0x0010 b''
2022-09-21 15:22:19.179 Computer-2021QA zigpy_zigate.uart DEBUG Frame to send: b'\x00\x10\x00\x00\x10'
2022-09-21 15:22:19.179 Computer-2021QA zigpy_zigate.uart DEBUG Frame escaped: b'\x02\x10\x10\x02\x10\x02\x10\x10'
2022-09-21 15:22:19.179 Computer-2021QA zigpy_zigate.api DEBUG Wait for status to command CommandId.GET_VERSION
2022-09-21 15:22:19.179 Computer-2021QA zigpy_zigate.api DEBUG Wait for response ResponseId.VERSION_LIST
2022-09-21 15:22:19.196 Computer-2021QA zigpy_zigate.uart DEBUG Frame received: 8000000999000000100000000000
2022-09-21 15:22:19.196 Computer-2021QA zigpy_zigate.api DEBUG data received 0x8000 b'0000001000000000' LQI:0
2022-09-21 15:22:19.196 Computer-2021QA zigpy_zigate.zigbee.application DEBUG zigate_callback_handler ResponseId.STATUS [<Status.Success: 0>, 0, 16, b'\x00\x00\x00\x00']
2022-09-21 15:22:19.196 Computer-2021QA zigpy_zigate.uart DEBUG Frame received: 80100005b40003032100
2022-09-21 15:22:19.196 Computer-2021QA zigpy_zigate.api DEBUG data received 0x8010 b'00030321' LQI:0
2022-09-21 15:22:19.196 Computer-2021QA zigpy_zigate.zigbee.application DEBUG zigate_callback_handler ResponseId.VERSION_LIST [3, 801]
2022-09-21 15:22:19.196 Computer-2021QA zigpy_zigate.zigbee.application DEBUG Broadcast not implemented.
2022-09-21 15:22:19.196 Computer-2021QA zigpy_zigate.api DEBUG Sending CommandId.SET_LED (b'\x01'), waiting for status: True, waiting for response: None
2022-09-21 15:22:19.196 Computer-2021QA zigpy_zigate.uart DEBUG Send: 0x0018 b'01'
2022-09-21 15:22:19.196 Computer-2021QA zigpy_zigate.uart DEBUG Frame to send: b'\x00\x18\x00\x01\x18\x01'
2022-09-21 15:22:19.197 Computer-2021QA zigpy_zigate.uart DEBUG Frame escaped: b'\x02\x10\x18\x02\x10\x02\x11\x18\x02\x11'
2022-09-21 15:22:19.197 Computer-2021QA zigpy_zigate.api DEBUG Wait for status to command CommandId.SET_LED
2022-09-21 15:22:19.211 Computer-2021QA zigpy_zigate.uart DEBUG Frame received: 8000000991000000180000000000
2022-09-21 15:22:19.211 Computer-2021QA zigpy_zigate.api DEBUG data received 0x8000 b'0000001800000000' LQI:0
2022-09-21 15:22:19.211 Computer-2021QA zigpy_zigate.zigbee.application DEBUG zigate_callback_handler ResponseId.STATUS [<Status.Success: 0>, 0, 24, b'\x00\x00\x00\x00']
2022-09-21 15:22:19.211 Computer-2021QA zigpy_zigate.api DEBUG Sending CommandId.PERMIT_JOINING_REQUEST (b'\xff\xfc<\x00'), waiting for status: True, waiting for response: None
2022-09-21 15:22:19.211 Computer-2021QA zigpy_zigate.uart DEBUG Send: 0x0049 b'fffc3c00'
2022-09-21 15:22:19.211 Computer-2021QA zigpy_zigate.uart DEBUG Frame to send: b'\x00I\x00\x04r\xff\xfc<\x00'
2022-09-21 15:22:19.211 Computer-2021QA zigpy_zigate.uart DEBUG Frame escaped: b'\x02\x10I\x02\x10\x02\x14r\xff\xfc<\x02\x10'
2022-09-21 15:22:19.211 Computer-2021QA zigpy_zigate.api DEBUG Wait for status to command CommandId.PERMIT_JOINING_REQUEST
2022-09-21 15:22:19.227 Computer-2021QA zigpy_zigate.uart DEBUG Frame received: 80000009400061004902e2010000
2022-09-21 15:22:19.227 Computer-2021QA zigpy_zigate.api DEBUG data received 0x8000 b'0061004902e20100' LQI:0
2022-09-21 15:22:19.227 Computer-2021QA zigpy_zigate.zigbee.application DEBUG zigate_callback_handler ResponseId.STATUS [<Status.Success: 0>, 97, 73, b'\x02\xe2\x01\x00']
2022-09-21 15:22:19.227 Computer-2021QA zigpy_zigate.api DEBUG Sending CommandId.RESET (b''), waiting for status: True, waiting for response: None
2022-09-21 15:22:19.227 Computer-2021QA zigpy_zigate.uart DEBUG Send: 0x0011 b''
2022-09-21 15:22:19.227 Computer-2021QA zigpy_zigate.uart DEBUG Frame to send: b'\x00\x11\x00\x00\x11'
2022-09-21 15:22:19.227 Computer-2021QA zigpy_zigate.uart DEBUG Frame escaped: b'\x02\x10\x11\x02\x10\x02\x10\x11'
2022-09-21 15:22:19.227 Computer-2021QA zigpy_zigate.api DEBUG Wait for status to command CommandId.RESET
2022-09-21 15:22:19.244 Computer-2021QA zigpy_zigate.uart DEBUG Frame received: 8000000999000000110000010000
2022-09-21 15:22:19.244 Computer-2021QA zigpy_zigate.api DEBUG data received 0x8000 b'0000001100000100' LQI:0
2022-09-21 15:22:19.244 Computer-2021QA zigpy_zigate.zigbee.application DEBUG zigate_callback_handler ResponseId.STATUS [<Status.Success: 0>, 0, 17, b'\x00\x00\x01\x00']
2022-09-21 15:22:19.244 Computer-2021QA zigpy_zigate.uart DEBUG Closed serial connection
@puddly
Copy link
Collaborator

puddly commented Oct 6, 2022

The permit call is asynchronous, so it permits joins for 60s and then immediately returns. The shutdown code in zigpy-zigate resets the dongle so what likely happens is that joins are being permitted, but the dongle is reset immediately after on shutdown.

Try adding an await asyncio.sleep(60) after your call to permit.

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

No branches or pull requests

2 participants