corneliusmunz / legoino

Arduino Library for controlling Powered UP and Boost controllers
MIT License
259 stars 34 forks source link

Check getHubType Function #21

Closed corneliusmunz closed 4 years ago

corneliusmunz commented 4 years ago

Some users reported that from version 0.7.0 on the getHubType function does not work as expected: https://gitter.im/legoinochat/community?at=5f5b395bdf4af236f9fda9b1

corneliusmunz commented 4 years ago

It seems that the switch of the BLE library changed the behaviour. If i use the 0.6.2 lib it works as expected. With 0.7.0 and above it doesn't work. The Advertisment message is different. Maybe it is a timing Problem. It seems that the NimBLE lib only receives the last part of the message and the hub type information is before the last part of the message after the pattern 0x09, 0xFF

Advertisment message (NimBLE, >= 0.7.0)

Remote      :14-9-6D-79-54-72-61-69-6E-48-75-62-0-0-0-0-0-0-0-0-0-5-12-10-0-20-0-2-A
PoweredUp   :5-12-10-0-20-0-2-A-0-B-9-6D-79-54-72-61-69-6E-48-75

Advertisment message (BLE lib, < 0.7.0)

Remote      :2-1-6-11-7-23-D1-BC-EA-5F-78-23-16-DE-EF-12-12-23-16-0-0-9-FF-97-3-0-42-A-1B-61-0-14-9-6D-79-54-72-61-69-6E-48-75-62-0-0-0-0-0-0-0-0-0-5-12-10-0-20-0-2-A
PoweredUp   :2-1-6-11-7-23-D1-BC-EA-5F-78-23-16-DE-EF-12-12-23-16-0-0-9-FF-97-3-0-41-7-80-63-0-5-12-10-0-20-0-2-A-0-B-9-6D-79-54-72-61-69-6E-48-75
corneliusmunz commented 4 years ago

After some more evaluation it seems that the m_payload member variable is overwritten every time so the overall payload could not be consumed:

12:02:17.885 -> E NimBLEAdvertisedDevice: "payload: 020106110723d1bcea5f782316deef12122316000009ff9703004107806300"
12:02:17.885 -> E NimBLEAdvertisedDevice: "payload: 051210002000020a000b096d79547261696e487562"
12:02:17.885 -> Device Address: 90:84:2b:03:19:7f

If the two payloads are concatenated, the overall payload is the same as in the "old" BLE library

When looking at the address and the payload length (additional log messages added in the NimBLE lib) it seems that the original location is overwritten:

13:43:34.066 -> I NimBLEScan: "NEW DEVICE FOUND: 90:84:2b:03:19:7f"
13:43:34.066 -> D NimBLEAdvertisedDevice: "payload address: 3ffc86ac"
13:43:34.066 -> D NimBLEAdvertisedDevice: "payload length: 31"
13:43:34.066 -> D NimBLEAdvertisedDevice: "payload: 020106110723d1bcea5f782316deef12122316000009ff9703004107806300"
13:43:34.066 -> I NimBLEScan: "UPDATING PREVIOUSLY FOUND DEVICE: 90:84:2b:03:19:7f"
13:43:34.066 -> D NimBLEAdvertisedDevice: "payload address: 3ffc86ac"
13:43:34.102 -> D NimBLEAdvertisedDevice: "payload length: 21"
13:43:34.102 -> D NimBLEAdvertisedDevice: "payload: 051210002000020a000b096d79547261696e487562"
corneliusmunz commented 4 years ago

Fixed with the following release: https://github.com/corneliusmunz/legoino/releases/tag/0.8.1