What will aioble scanResult.name() report for an advertisement containing unprintable characters? #13750
Answered
by
bixb922
brianreinhold
asked this question in
Libraries & Drivers
-
I have device that is sending the following advertisment
Note the device name
The name has a whole slew of unprintable null characters at the end. What will ScanResult.name() return? Is it |
Beta Was this translation helpful? Give feedback.
Answered by
bixb922
Feb 26, 2024
Replies: 1 comment 2 replies
-
ScanResult.name() will interpret (decode) the name as UTF-8 string using str(name,'utf8'). The trailing nulls will remain as null characters at the end of the string. To be sure to have the "ascii only" characters, replace the nulls by "": >>> advertised_name=b'1SC100\x00\x00\x00\x00\x00\x00\x00\x00'
>>> name_as_string=str(advertised_name,"utf-8")
>>> name_as_string
'1SC100\x00\x00\x00\x00\x00\x00\x00\x00'
>>> trimmed_name=name_as_string.replace("\x00","")
>>> trimmed_name
'1SC100' |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
brianreinhold
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ScanResult.name() will interpret (decode) the name as UTF-8 string using str(name,'utf8'). The trailing nulls will remain as null characters at the end of the string. To be sure to have the "ascii only" characters, replace the nulls by "":