Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

BLERadio.start_scan throws ValueError: non-hexadecimal
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

BLERadio.start_scan throws ValueError: non-hexadecimal

by tlpada on Sun Apr 05, 2020 7:41 pm

When running the "ble_broadcastnet_blinka_bridge.py" example on Raspberry Pi, the call to "adafruit_ble.BLERadio.start_scan" throws the following error: "ValueError: non-hexadecimal number found in fromhex() arg at position 19".

That is, this "start_scan" call in ble_broadcastnet_blinka_bridge.py:

Code: Select all | TOGGLE FULL SIZE
# By providing Advertisement as well we include everything, not just specific advertisements.
for measurement in ble.start_scan(
    adafruit_ble_broadcastnet.AdafruitSensorMeasurement, interval=0.5
):

results in this output:

Code: Select all | TOGGLE FULL SIZE
scanning

Traceback (most recent call last):
  File "ble_broadcastnet_blinka_bridge.py", line 113, in <module>
    adafruit_ble_broadcastnet.AdafruitSensorMeasurement, interval=0.5
  File "/usr/local/lib/python3.5/dist-packages/adafruit_ble/__init__.py", line 243, in start_scan
    active=active,
  File "/usr/local/lib/python3.5/dist-packages/_bleio.py", line 257, in start_scan
    buffered, prefixes, minimum_rssi, active
  File "/usr/local/lib/python3.5/dist-packages/_bleio.py", line 189, in _parse_buffered
    data = bytes.fromhex("".join([x.decode("utf-8") for x in buffered]))
ValueError: non-hexadecimal number found in fromhex() arg at position 19

This exception is thrown from the underlying library file "_bleio.py" (/usr/local/lib/python3.5/dist-packages/_bleio.py) by the statement on line 189 of _bleio.py:

Code: Select all | TOGGLE FULL SIZE
data = bytes.fromhex("".join([x.decode("utf-8") for x in buffered]))

The "fromhex()" parsing function fails, apparently, upon encountering a non-hexadecimal character at array "position 19".

Scanning using hcitool reveals numerous Bluetooth devices are broadcasting:

Code: Select all | TOGGLE FULL SIZE
/home/pi$ hcitool lescan
LE Scan ...
4D:14:D9:21:57:BC (unknown)
7E:DC:3F:51:48:CC (unknown)
7E:DC:3F:51:48:CC (unknown)
A4:D1:8C:6A:C3:90 (unknown)
25:EB:3C:85:53:C1 (unknown)
70:F0:3B:48:F8:EF (unknown)
70:F0:3B:48:F8:EF (unknown)
C8:D0:83:C0:4B:4B (unknown)
68:DC:86:C7:0E:A6 (unknown)
68:DC:86:C7:0E:A6 (unknown)
5F:D9:30:E0:1C:FA (unknown)
5F:D9:30:E0:1C:FA (unknown)
25:3C:7D:54:D9:1C (unknown)
67:46:E5:57:D7:0A (unknown)
EC:81:93:04:F6:4B
[etc...]

So it seems that 'out of the box' the _bleio module fails to parse these addresses, trying to convert non-hexadecimal portions of the string into hexadecimal numbers.

Any experienced this or have any idea why this is failing?

tlpada
 
Posts: 36
Joined: Thu Feb 27, 2020 2:38 pm

Re: BLERadio.start_scan throws ValueError: non-hexadecimal

by adafruit_support_bill on Sun Apr 05, 2020 7:56 pm

Please do not double-post: viewtopic.php?f=53&t=164205

adafruit_support_bill
 
Posts: 79084
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.