awilliams / wifi-presence

Presence detection on OpenWrt routers using connect/disconnect events of WiFi clients. Events are published to MQTT with Home Assistant integration.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SSID with mixed UTF-8 and ASCII characters cannot be handled correctly

zhangjingye03 opened this issue · comments

commented

Hi Adam,

Thanks for this great integration!

However, my WiFi SSID begins with UTF-8 character and then ASCII one, like ω=2πf.
In this case, status from hostapd_cli gives something below, which mixes \x and normal ASCII chars.

ssid[0]=\xcf\x89=2\xcf\x80f

case "ssid[0]":
if strings.HasPrefix(val, "\\x") {
val = strings.ReplaceAll(val, "\\x", "")
h, err := hex.DecodeString(val)
if err != nil {
return err
}
val = string(h)
}
s.SSID = val

The code above just replace \x and then decode hex, which still contains non-hex chars, resulting Error: encoding/hex: invalid byte on my device. I'm not familiar with golang though, but maybe we could use strconv.Unquote instead? (Ref)

Thanks

Thank you for the detailed report @zhangjingye03, and sorry you are experiencing that issue.

I believe you've identified the section of code responsible for this issue. I'll take a closer look in the coming days and hopefully will have a fix soon.

@zhangjingye03 I've added a fix (#8) for your issue. Please, if you can, try out v0.2.0 and let me know if it fixes your issue. Thanks

Closing. Please re-open @zhangjingye03 if you experience any related issues.