linuxscripts icon indicating copy to clipboard operation
linuxscripts copied to clipboard

binary characters found in status payload

Open spideyb opened this issue 7 years ago • 4 comments

I found that running the status payload was returning binary characters, adjusting cmd_print_plug_relay_state() to the following strips it out (added tr -cd '\11\12\15\40-\176'):

output=send_to_plug $ip $port "$payload_query" | decode | tr -cd '\11\12\15\40-\176' | egrep -o 'relay_state":[0,1]' | egrep -o '[0,1]'

spideyb avatar Apr 24 '17 19:04 spideyb

Thanks @spideyb . Which device/firmware version?

ggeorgovassilis avatar Apr 26 '17 20:04 ggeorgovassilis

HS110 v1.0 - Firmware: 1.0.8 HS200 v1.0 - Firmware: 1.1.0

BTW - thanks for the scripts, real useful

spideyb avatar Apr 27 '17 19:04 spideyb

Hello, i got the same "issue". But i decided to deal with it by adding "a" as option of the first egrep. This allow grep to check content as text even with binary char. Because the binary character is outside of the json, it doesn't pose any trouble to match the string relay_state.

the egrep become: send_to_plug $ip $port "$payload_query" | decode | egrep -oa 'relay_state":[0,1]' | egrep -o '[0,1]'

and this should also fix the #13

Result recieved by cmd_print_plug_relay_state():

{"system":{"get_sysinfo":{"sw_ver":"1.1.1 Build 191209 Rel.103408","hw_ver":"4.0","model":"HS100(FR)","deviceId":"XXX","oemId":"XXXX","hwId":"XXXX","rssi":-XXXX,"longitude_i":XXXX,"latitude_i":XXXX,"alias":"prise 1 test","status":"new","mic_type":"IOT.SMARTPLUGSWITCH","feature":"TIM","mac":"XXXX","updating":0,"led_off":0,"relay_state":0,"on_time":0,"active_mode":"none","icon_hash":"","dev_name":"Smart Wi-Fi Plug","next_action":{"type":-1},"err_code":0}}}▒,^A^@^K^F^W^]^F^ANT^[O^Q^F^E^\^\^C^_^W
^]^\^B^P^Y^@^@^@^YP^_^]^FT{/^W^S_K^M^Z^G^]^G^M^W)}S^F^V^@^F^@^A^A^AE+

Beanux avatar Sep 17 '20 10:09 Beanux

Thank you @Beanux for the analysis and fix. Unfortunately I don't have the hs100 any more and cannot test this. Nevertheless I will modify the script according to your suggestion - if anybody complains, we'll know it didn't work :)

ggeorgovassilis avatar Sep 17 '20 15:09 ggeorgovassilis