Adam-Langley / pybleno

A direct port of the Bleno bluetooth LE peripheral role library to Python2/3
MIT License
68 stars 34 forks source link

Web bluetooth breaks callbackResponse #44

Open FPSUsername opened 4 years ago

FPSUsername commented 4 years ago

I am trying to get the characteristics using web bluetooth, but I receive this error when the javascript calls the service.

return device.gatt.connect().
            then(server => {
                return server.getPrimaryService('b923d807-d8de-469d-89aa-c0d61a4e59a4');
            }).
            then(service => {
                service.getCharacteristic('b923d807-d8de-469d-89aa-c0d61a4e59a5');
            })';

Error from the beacon:

Exception in thread HCISocketPoller: Traceback (most recent call last): File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner self.run() File "/usr/lib/python3.6/threading.py", line 864, in run self._target(*self._args, *self._kwargs) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/BluetoothHCI/BluetoothHCI.py", line 197, in _socket_poller self._socket_on_data_user_callback(bytearray(data)) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Hci.py", line 414, in onSocketData self.emit('aclDataPkt', [handle, cid, pktData]) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Emit.py", line 17, in emit handler(arguments) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Bindings.py", line 169, in onAclDataPkt self._aclStream.push(cid, data) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/AclStream.py", line 18, in push self.emit('data', [cid, data]) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Emit.py", line 17, in emit handler(*arguments) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Gatt.py", line 228, in onAclStreamData self.handleRequest(data) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Gatt.py", line 271, in handleRequest response = self.handleReadOrReadBlobRequest(request) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Gatt.py", line 681, in handleReadOrReadBlobRequest callback(result, data) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Gatt.py", line 620, in callback callbackResponse[1 + i] = data[i] TypeError: an integer is required (got type str)

Adam-Langley commented 4 years ago

Hi, Please provide your code which is returning the characteristic result.

Thanks

On Sat, Feb 8, 2020 at 2:46 AM FPSUsername notifications@github.com wrote:

I am trying to get the characteristics using web bluetooth, but I receive this error when the javascript calls the service.

return device.gatt.connect(). then(server => { return server.getPrimaryService('b923d807-d8de-469d-89aa-c0d61a4e59a4'); }). then(service => { service.getCharacteristic('b923d807-d8de-469d-89aa-c0d61a4e59a5'); })';

Error from the beacon:

Exception in thread HCISocketPoller: Traceback (most recent call last): File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner self.run() File "/usr/lib/python3.6/threading.py", line 864, in run self._target(*self._args, *self._kwargs) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/BluetoothHCI/BluetoothHCI.py", line 197, in _socket_poller self._socket_on_data_user_callback(bytearray(data)) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Hci.py", line 414, in onSocketData self.emit('aclDataPkt', [handle, cid, pktData]) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Emit.py", line 17, in emit handler(arguments) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Bindings.py", line 169, in onAclDataPkt self._aclStream.push(cid, data) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/AclStream.py", line 18, in push self.emit('data', [cid, data]) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Emit.py", line 17, in emit handler(*arguments) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Gatt.py", line 228, in onAclStreamData self.handleRequest(data) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Gatt.py", line 271, in handleRequest response = self.handleReadOrReadBlobRequest(request) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Gatt.py", line 681, in handleReadOrReadBlobRequest callback(result, data) File "/home/ubuntu/.local/lib/python3.6/site-packages/pybleno/hci_socket/Gatt.py", line 620, in callback callbackResponse[1 + i] = data[i] TypeError: an integer is required (got type str)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://u2567673.ct.sendgrid.net/ls/click?upn=tqQDaGrBSQqIjEc4PHVNCytArFpG0wBWrxX8rj9l5vwuxnO-2Fx1Qp6YpGUPl3oCKw6D7FO8acisQ4NJV-2BEj1iBs0jhhd6pM4jggZCAN-2FlL9NzBdTCkEfYDR1nRi5cxPbxQaUM-2FZn5nwdiQAGX4idRxiCgQztlGy89a02YgSVBCvw4JtrPiX-2F1b5LS1g1-2ByGrt8ZnCnND7HfZfHkAXlcUjE3kfWTpxNliT0tbl9KCIDxuCTCmHi-2BewgOY4LPTtu7Q1qgiY9LkZ6s4wR8GektEf-2Fg-3D-3DJQ7v_U31jt5HgHBh7k3Grc5s4l2CaK8vlz0Mz3vk33oTst5V8UicD8LEunbMVjP2LiFk03ItHF-2BT0uzXit-2B3l6kNEDVS-2BYr0cXAo-2BfqkgRbZJ9s-2FGol956o9O9m6tLvdL1ypkwP814nqee9f3sMSR8PJge5kL6mX68yPZrqHw5-2BDCXOIk-2FkW6x5ltjWSTk14909T-2BjZcVNUBZHISY6NxYj0khs8vS0OomZIVE44xDqHyXEAeRyBA-2B9KGu-2F-2FlwIWMsGpmvL6wkskI-2F8zQg4cOsFgtWiXnHUzLnwP8OHj6voSYxV3g-3D, or unsubscribe https://u2567673.ct.sendgrid.net/ls/click?upn=tqQDaGrBSQqIjEc4PHVNC16Ei41ODE2E8fJSuorRJxmfrPbL8QxdihhdTrVyaU0-2BAa7WxqmylejDayK-2BHLAScyrvEFVRD9kD6PbwSioFUbMJnv9Yf-2FvT4-2B8oEEbwmVq2ketgz5IXJFd0rjWVWDxQhw-3D-3D_0Iw_U31jt5HgHBh7k3Grc5s4l2CaK8vlz0Mz3vk33oTst5V8UicD8LEunbMVjP2LiFk03ItHF-2BT0uzXit-2B3l6kNEDVS-2BYr0cXAo-2BfqkgRbZJ9s-2FGol956o9O9m6tLvdL1ypkTXO83jDFvljGpJbOXRGYNECT836IjcgRWNPxlGPsQkFHFCrNNc9iqmaUUb680WxCPagCRB-2FYz-2FUJkFDRpcjh4EH4SY6v2kZqFH1K9sxEatZl3YivLMjzZXcfWCHreVlfgiotwDURdZXG0c24KwhjaI1-2FkE0gcUuJvRnP9YIlAbA-3D .

FPSUsername commented 4 years ago

I only used the onReadRequest funtion from the echo example. Apparently adding self._updateValueCallback = None fixed the issue.

I also tried using the callback method from the pizza example (onReadRequest) callback(Characteristic.RESULT_SUCCESS, data); but that gave me some errors regarding the data (I defined data the same way it has been set in the class itself).

Last problem is that the descriptor doesn't work unless I put the uuid and value into a dict. This however produces the same TypeError when doing a read request for the descriptor (which I tried with BLE Scanner)