Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm trying to control a tp-link electrical socket from the command line...

By now I've done interesting progresses, being able to get the plug id...

Now I'd like to go a step further and activate or deactivate it.

In order to do that I've followed an Internet page that explains how to do it from Linux... And I would like to do it from Windows 10.

If I get this to work I'll make a small article/tip here at CP to explain the steps, which by now have been very easy...

The original linux script would be:

curl --request POST "https://eu-wap.tplinkcloud.com/?token=74adcc7e-64f7-47c1-a751-dece6d2f4704 \
 --data '{"method":"passthrough", "params": {"deviceId": "80067AC4FDBD41C54C55896BFA28EAD38A87A5A4", "requestData": "{\"system\":{\"set_relay_state\":{\"state\":1}}}" }}' \
--header "Content-Type: application/json"


From the windows 10 CMD, I've written what I think would be the right translation, but it fails:

curl -X POST -H "Content-Type: application/json" -d "{ \"method\" : \"passthrough\", \"params\" : { \"deviceId\" : \"80067AC4FDBD41C54C55896BFA28EAD38A87A5A4\", \"requestData\" : { \"system\" : { \"set_relay_state\" : { \"state\" : 1 }}}}}" https://eu-wap.tplinkcloud.com/?token=74adcc7e-64f7-47c1-a751-dece6d2f4704


It returns
{"error_code":-10100,"msg":"JSON format error"}


Note: the DeviceId and token used are the same ones used in the original web page.

As an example, one curl call (used to get the devices in the network) that works:
curl -X POST -H "Content-Type: application/json" -d "{ \"method\" : \"getDeviceList\" }" https://eu-wap.tplinkcloud.com?token=74adcc7e-64f7-47c1-a751-dece6d2f4704


Can you see something wrong here?

Thank you very much.

What I have tried:

Moved quotes, escaped quotes (I've got 2 curl calls to work and tried to emulate them here)...
Posted
Updated 17-Jul-19 2:04am
Comments
Peter_in_2780 17-Jul-19 7:25am    
Your Win10 example seems to be missing quotes around the requestData {...} (outside the 3rd innermost pair of braces).
Joan M 17-Jul-19 8:03am    
Yes! and those had to be replaced for ' in windows...

thanks Peter...

1 solution

curl -X POST -H "Content-Type: application/json" -d "{ \"method\" : \"passthrough\", \"params\" : { \"deviceId\" : \"80067AC4FDBD41C54C55896BFA28EAD38A87A5A4\", \"requestData\" : '{ \"system\" : { \"set_relay_state\" : { \"state\" : 1 }}}'}}" https://eu-wap.tplinkcloud.com/?token=74adcc7e-64f7-47c1-a751-dece6d2f4704

Had to put single ' from requestdata...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900