tlaukkan / zigbee4java

Zigbee API for Java provides simple Java interface to ZigBee network.
Apache License 2.0
144 stars 68 forks source link

RESEND_TIMEOUT_DEFAULT too short #76

Closed cdealti closed 8 years ago

cdealti commented 8 years ago

I'm facing a timeout problem when I run zigbee-console-javase both with the CC2531ZNP-Pro-Secure_Standard.hex and the CC2531ZNP-Pro-Secure_LinkKeyJoin.hex firmware (note that I'm starting the network clearing the state):

java -jar target/zigbee-console-javase-2.0.3-SNAPSHOT.jar /dev/ttyACM0 11 4952 true
ZigBee API starting up...19:23:28 455  DEBUG  Opening portIdentifier '/dev/ttyACM0'.
19:23:28 463  DEBUG  -> SYS_RESET (Packet: length = 1, apiId = 0x41 0x00, full data = 0xfe 0x01 0x41 0x00 0x01 0x41, checksum = 0x41, error = false, errorMessage = null) 
19:23:30 049  DEBUG  <-- SYS_RESET_RESPONSE (Packet: length = 6, apiId = 0x41 0x80, full data = 0xfe 0x06 0x41 0x80 0x00 0x02 0x00 0x02 0x06 0x03 0xc2, checksum = 0xc2, error = false, errorMessage = null)
19:23:30 049  DEBUG  Resetting network stack.
19:23:30 050  INFO   Setting clean state.
19:23:30 051  DEBUG  -> ZB_WRITE_CONFIGURATION (Packet: length = 3, apiId = 0x26 0x05, full data = 0xfe 0x03 0x26 0x05 0x03 0x01 0x03 0x21, checksum = 0x21, error = false, errorMessage = null) 
19:23:31 051  WARN   ZB_WRITE_CONFIGURATION executed and timed out while waiting for response.
19:23:31 061  WARN   Couldn't set ZCD_NV_STARTUP_OPTION mask 00000003
19:23:31 061  ERROR  Unable to set clean state for dongle
19:23:31 061  DEBUG  Serial portIdentifier '/dev/ttyACM0' closed.
19:23:31 499  WARN   Discarded stream: expected start byte but received this 0x00
19:23:31 499  DEBUG  ZToolPacketParser parserThread exited.
ZigBee API starting up ... [FAIL]

It happens when the application is started while the led on the CC2531 is on, i.e. within the first 60 seconds after it has been plugged.

If I run the above command a second time just after the timeout or I wait more than 60 seconds after the dongle has been plugged (the led goes off) the network always starts successfully.

I've tried to increase the RESEND_TIMEOUT_DEFAULT to 10000 and this seems to fix the problem.

Can anyone confirm this behavior?

cdealti commented 8 years ago

The problem is closely related to #37. The dongle respond to the magic byte with a SYS_RESET_IND. This confuses the subsequent dongle initialization.

As said increasing the RESEND_TIMEOUT_DEFAULT seems to mitigate the problem but the right way to do this is to wait for a while SYS_RESET_IND after sending the magic byte.

cdealti commented 8 years ago

Above commit merged into master. Closing this issue