I was trying to execute the TPLINK smartplug python script: https://github.com/softScheck/tplink-smartplug/blob/master/tplink-smartplug.py
The main issue is related with the "sock_tcp.send(encrypt(cmd))". The variable cmd is a string that I pass as argument in the terminal (see example below). Executing this code with Python2 I got a successful response from the smartplug
bash:~/tplink-smartplug-master$ python tplink-smartplug.py -t 192.168.xx.xx -j '{"emeter":{"get_realtime":{}}}'
Output - print
Sent: {"emeter":{"get_realtime":{}}}
('Received: ', '{"emeter":{"get_realtime":{"current":0.039509,"voltage":236.064036,"power":4.880813,"total":0.004000,"err_code":0}}}')
If I execute the code with Python3 I got the error "TypeError: a bytes-like object is required, not 'str'". This is related with Python3 using unicode for strings while Python2 uses bytes.
However if I change the code to accommodate Python3 demands as such: "sock_tcp.send(encrypt(cmd).encode())" to force a conversion from Unicode to bytes. The response when executing the code is:
bash:~/tplink-smartplug-master$ python3 tplink-smartplug.py -t 192.168.xx.xx -j '{"emeter":{"get_realtime":{}}}'
Output - print
Sent: {"emeter":{"get_realtime":{}}}
Received:
Any ideas what kind of conversation should I do to make it working in Python3 ?
The encrypt() functions only add a extra chart you can check it on the link above.
Thank you for the help! Jp