ggeorgovassilis / linuxscripts

Script collection for linux
Other
386 stars 112 forks source link

Command check always returns off although connection successful #9

Closed pplucky closed 7 years ago

pplucky commented 7 years ago

Hello.

I'm trying to use your script to do 3 basic things:

It's an HS100 with Hardware version 1.0 and Firmware version 1.1.0 Build 160503 Rel.145047 (also tried in an HS110 with Hardware version 1.0 and Firmware version 1.0.8 Build 151101 Rel.24452 and result is the same).

Is there anything I can provide you for you to check, or am I doing something wrong?

Thanks in advance and kind regards.

ggeorgovassilis commented 7 years ago

I don't own the hs100 anymore so it's a bit hard to look that issue up :-( If you're not above experimenting a bit:

  1. get a copy of the hs100.sh script here: https://github.com/ggeorgovassilis/linuxscripts/blob/master/tp-link-hs100-smartplug/hs100.sh

  2. Modify line 90 to: output=`send_to_plug $ip $port "$payload_query" | decode`

  3. Run check for both the on and off state

  4. Post the results here

pplucky commented 7 years ago

Here it is...

HS100 - While OFF:

Connection to xxx.xxx.xxx.xxx 9999 port [tcp/*] succeeded!
{"system":{"get_sysinfo":{"err_code":0,"sw_ver":"1.1.0 Build 160503 Rel.145047","hw_ver":"1.0","type":"IOT.SMARTPLUGSWITCH","model":"HS100(EU)","mac":"AA:BB:CC:DD:EE:FF","deviceId":"DFA50CF68526DEFDD63B8A820D33BFD61064B383","hwId":"E6A1B260E7A5E7ECAA208D4E6A623FA3","fwId":"3D7D7213EC7C4FFAA3B1BEB812629CA4","oemId":"09D038443827AFB89CFA22EA916BF007","alias":"Tomada Sala","dev_name":"Wi-Fi Smart Plug","icon_hash":"","relay_state":0,"on_time":0,"active_mode":"none","feature":"TIM","updating":0,"rssi":-62,"led_off":0,"latitude":xx.xxxxxx,"longitude":-x.xxxxxx}}}OFF

HS100 - While ON:

Connection to xxx.xxx.xxx.xxx 9999 port [tcp/*] succeeded!
{"system":{"get_sysinfo":{"err_code":0,"sw_ver":"1.1.0 Build 160503 Rel.145047","hw_ver":"1.0","type":"IOT.SMARTPLUGSWITCH","model":"HS100(EU)","mac":"AA:BB:CC:DD:EE:FF","deviceId":"DFA50CF68526DEFDD63B8A820D33BFD61064B383","hwId":"E6A1B260E7A5E7ECAA208D4E6A623FA3","fwId":"3D7D7213EC7C4FFAA3B1BEB812629CA4","oemId":"09D038443827AFB89CFA22EA916BF007","alias":"Tomada Sala","dev_name":"Wi-Fi Smart Plug","icon_hash":"","relay_state":1,"on_time":5,"active_mode":"none","feature":"TIM","updating":0,"rssi":-64,"led_off":0,"latitude":xx.xxxxxx,"longitude":-x.xxxxxx}}}OFF

HS110 - While OFF:

Connection to xxx.xxx.xxx.xxx 9999 port [tcp/*] succeeded!
{"system":{"get_sysinfo":{"err_code":0,"sw_ver":"1.0.8 Build 151101 Rel.24452","hw_ver":"1.0","type":"smartplug","model":"HS110(EU)","mac":"AA:BB:CC:DD:EE:FF","deviceId":"EDD917B395F21B66906452BC87F37ADB5F4A00ED","hwId":"4EDAEA482B92280E23958DB25B688542","fwId":"0BCCDA6A9F9A70403669C00B93A40017","oemId":"EE436C93039DECC2E4B0C31352424041","alias":"ZTomada Consumos","dev_name":"Wi-Fi Smart Plug With Energy Monitoring","icon_hash":"","relay_state":0,"on_time":0,"active_mode":"schedule","feature":"TIM:ENE","updating":0,"rssi":-55,"led_off":0,"latitude":xx.xxxxxx,"longitude":-x.xxxxxx}}}OFF

HS110 - While ON:

Connection to xxx.xxx.xxx.xxx 9999 port [tcp/*] succeeded!
{"system":{"get_sysinfo":{"err_code":0,"sw_ver":"1.0.8 Build 151101 Rel.24452","hw_ver":"1.0","type":"smartplug","model":"HS110(EU)","mac":"AA:BB:CC:DD:EE:FF","deviceId":"EDD917B395F21B66906452BC87F37ADB5F4A00ED","hwId":"4EDAEA482B92280E23958DB25B688542","fwId":"0BCCDA6A9F9A70403669C00B93A40017","oemId":"EE436C93039DECC2E4B0C31352424041","alias":"ZTomada Consumos","dev_name":"Wi-Fi Smart Plug With Energy Monitoring","icon_hash":"","relay_state":1,"on_time":2,"active_mode":"schedule","feature":"TIM:ENE","updating":0,"rssi":-54,"led_off":0,"latitude":xx.xxxxxx,"longitude":-x.xxxxxx}}}OFF

It seems that even though relay_state = 1 (both for HS100 and HS110), response of your script is always OFF (I also tried echoing variable $output and it shows empty on screen).

Connection to xxx.xxx.xxx.xxx 9999 port [tcp/*] succeeded!

OFF
ggeorgovassilis commented 7 years ago

Thanks for the logs. With your input the expression matcher works fine for me:

cmd_print_plug_relay_state(){
   input='{"system":{"get_sysinfo":{"err_code":0,"sw_ver":"1.1.0 Build 160503 Rel.145047","hw_ver":"1.0","type":"IOT.SMARTPLUGSWITCH","model":"HS100(EU)","mac":"AA:BB:CC:DD:EE:FF","deviceId":"DFA50CF68526DEFDD63B8A820D33BFD61064B383","hwId":"E6A1B260E7A5E7ECAA208D4E6A623FA3","fwId":"3D7D7213EC7C4FFAA3B1BEB812629CA4","oemId":"09D038443827AFB89CFA22EA916BF007","alias":"Tomada Sala","dev_name":"Wi-Fi Smart Plug","icon_hash":"","relay_state":0,"on_time":0,"active_mode":"none","feature":"TIM","updating":0,"rssi":-62,"led_off":0,"latitude":xx.xxxxxx,"longitude":-x.xxxxxx}}}';

   echo $input

   output=`echo "$input" | egrep -o 'relay_state":[0,1]' | egrep -o '[0,1]'`
   echo State is: $output
   if [[ $output -eq 0 ]]; then
     echo OFF
   elif [[ $output -eq 1 ]]; then
     echo ON
   else
     echo Couldn''t understand plug response $output
   fi
}

That outputs "ON" for me.

Could it be that you execute the check right after changing the plug's status? In my tests I've found a variable delay until the status updates

pplucky commented 7 years ago

Actually my results were not consistent using you script. Besides that, outputting the state took too long, so I decided to work on a python approach and get results from the resulting json.

Thanks anyway for your efforts.