artificial-intelligence-class / spherov2.py

Unofficial Python API for all Sphero toys
MIT License
64 stars 24 forks source link

spherov2.controls.PacketDecodingException: Bad response checksum when connecting to multiple Spheros #37

Open r-bt opened 1 year ago

r-bt commented 1 year ago

I'm trying to connect to multiple Sphero Bolts at once but when I get to around 3 connections sometimes I'll get the following error

spherov2.controls.PacketDecodingException: Bad response checksum

I modified v2.py to log the unescaped packet that didn't have the correct checksum

Sphero 1:

0x8d 0x30 0x11 0x2 0x18 0x2 0xff 0x3f 0x7f 0xf3 0x84 0x3c 0x28 0xcf 0xc2 0x3c 0x87 0xcb 0xf5 0x38 0x5f 0xd 0xfc 0x3f 0x97 0x23 0x72 0x3f 0xf3 0x26 0x3a 0xbb 0xc7 0xba 0x18 0x3c 0xff 0xdf 0x38 0xbc 0x6a 0xd5 0x56 0x3f 0x7e 0x5d 0xb8 0x8d 0x30 0x11 0x2 0x18 0x2 0xff 0x3f 0x7f 0xf3 0x8f 0x3c 0x26 0x36 0xdf 0x3c 0x88 0x46 0x62 0x38 0x69 0x11 0xb9 0x3f 0x94 0xcf 0xf8 0x3f 0xf4 0x1 0x9e 0xbb 0xd0 0xb1 0xab 0x23 0x3c 0xff 0x13 0x60 0xbc 0xb5 0x98 0x98 0x3f 0x7e 0x5e 0x4c 0x3f 0x7e 0x8e 0x75 0xb6 0x98 0x56 0xfd 0xb8 0x2d 0x1a 0xfd 0xb6 0x8f 0x38 0x75 0xb7 0x85 0x64 0x50 0x41 0xde 0xbc 0xb1 0x3c 0xca 0xae 0x24 0xbe 0xb3 0x22 0x36 0x0 0x0 0x0 0x0 0x43 0xbd 0xcf 0x5c 0x75 0xd8

Sphero 2:

0x8d 0x30 0x11 0x2 0x18 0x2 0xff 0x3f 0x7f 0xc3 0x25 0x3d 0x6 0x18 0xd0 0xbc 0xe5 0x73 0x85 0xb8 0x2a 0x12 0x8d 0x30 0x11 0x2 0x18 0x2 0xff 0x3f 0x7f 0xc2 0xe9 0x3d 0x6 0xd5 0x43 0xbc 0xe4 0xc6 0xb9 0xb8 0xc 0xa 0x3 0x40 0x71 0x8c 0x74 0xc0 0x4c 0xbc 0x13 0x3b 0x7a 0xf9 0x23 0xbd 0x4d 0x7a 0xdd 0xbd 0x8b 0x7a 0x68 0x3f 0x80 0x5 0x2d 0x3f 0x80 0x7a 0x2c 0x36 0xb6 0x59 0x20 0x39 0x5 0xe0 0x32 0x37 0xc 0xd9 0x11 0xb7 0x87 0xd 0x55 0x41 0xba 0x97 0xa7 0x3c 0xc8 0xb8 0xb4 0x3e 0x58 0x6d 0x91 0x0 0x0 0x0 0x0 0x43 0x9c 0x18 0x0 0xfb 0xd8

Sphero 3:

0x8d 0x30 0x11 0x2 0x18 0x2 0xff 0x3f 0x7f 0xd0 0x2d 0x3d 0x1b 0xeb 0x8c 0xbb 0x4d 0x57 0x17 0xb9 0x45 0xc3 0x93 0x40 0x8b 0x9e 0x83 0xbe 0xb8 0x1e 0x4d 0x3c 0xb1 0x2d 0x42 0xbb 0xb4 0x54 0x9c 0xbd 0x99 0x7e 0x72 0x3f 0x7f 0xc8 0xfb 0x8d 0x30 0x11 0x2 0x18 0x2 0xff 0x3f 0x7f 0xcf 0xdc 0x3d 0x1c 0x77 0xd1 0xbb 0x48 0x8b 0x6b 0xb9 0x4c 0x79 0xde 0x40 0x8c 0x1c 0x29 0xbe 0xb3 0xd7 0xd9 0x3c 0xb7 0x30 0xe6 0xbb 0xb4 0x75 0x53 0xbd 0x99 0x79 0xc 0x3f 0x7e 0xc7 0xe5 0x3f 0x7f 0x81 0x86 0xb5 0xdb 0xb2 0xe9 0x36 0x34 0x2f 0xad 0xb6 0xb 0x58 0x91 0x38 0x30 0xf2 0xaa 0x41 0x50 0x84 0xb5 0xbd 0x87 0x97 0xaf 0xbd 0x2e 0x69 0x9d 0x0 0x0 0x0 0x0 0x42 0xea 0xc3 0xd6 0xa0 0xd8

Looking through the packets each has a SOP byte after the initial SOP byte which is why I assume the checksum is failing

r-bt commented 1 year ago

I had Wireshark opened at the same time and it looks like some packets are being dropped. Attached is a file with the faulty packets for Sphero 1. What's wrong is that it's a mash of two different Sphero commands with some bluetooth packets just being dropped.

faulty_packets.pcapng.zip

superfashi commented 1 year ago

appreciate the investigation. i'll look into it as well once i came back from vacation.

r-bt commented 1 year ago

Just to link things together, I found that the BlueZ dbus API is not sending the packets to Bleak – here's the issue on the Bleak repo: https://github.com/hbldh/bleak/issues/1343

r-bt commented 1 year ago

Ok it looks like it's a BlueZ issue, I tried using AcquireNotify instead of StartNotify and it also gives the error (with even less ~5 instead of ~12) simultaneous connections. Issue at: https://github.com/bluez/bluez/issues/539