ggeorgovassilis / linuxscripts

Script collection for linux
Other
383 stars 112 forks source link

binary characters found in status payload #8

Open spideyb opened 7 years ago

spideyb commented 7 years ago

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]'

ggeorgovassilis commented 7 years ago

Thanks @spideyb . Which device/firmware version?

spideyb commented 7 years ago

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

BTW - thanks for the scripts, real useful

Beanux commented 4 years ago

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+
ggeorgovassilis commented 4 years ago

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 :)