Merge branch 'master' of https://github.uci.edu/rtrimana/smart_home_traffic
[pingpong.git] / Code / Projects / TplinkPlugClient / src / main / java / edu / uci / iotproject / tplinkplug / Main.java
1 package edu.uci.iotproject.tplinkplug;
2
3 /**
4  * TODO add class documentation.
5  *
6  * @author Janus Varmarken
7  */
8 public class Main {
9
10     public static void main(String[] args) throws InterruptedException {
11         TplinkPlugWanClient client = new TplinkPlugWanClient();
12         int c = 0;
13         while (c < 15) {
14             if (c % 2 == 0) {
15                 client.powerOn();
16             }
17             else {
18                 client.powerOff();
19             }
20             Thread.sleep(5_000);
21             c++;
22         }
23     }
24
25 }
26
27
28 // To login, POST following JSON to https://wap.tplinkcloud.com
29 // The UUID is generated by the client - possibly used for tracking future logins from the same device?
30 // {
31 //     "method": "login",
32 //     "params": {
33 //     "appType": "Kasa_Android",
34 //     "cloudUserName": "iotuser22@gmail.com",
35 //     "cloudPassword": "Hqeas2tplink",
36 //     "terminalUUID": "7e8691de-cf4b-4727-ab31-863b4d4919b4"
37 //     }
38 // }
39 // Login output
40 // {"error_code":0,"result":{"accountId":"1619813","regTime":"2017-08-06 06:28:38","email":"iotuser22@gmail.com","token":"a749210e-A9F3yu9IMYGWAepK0KCVNp0"}}
41
42 // To get list of devices, POST following JSON to https://wap.tplinkcloud.com?token=TOKEN_FROM_LOGIN_RESPONSE_HERE
43 // {"method":"getDeviceList"}
44 // getDeviceList output (note that the appServerUrl points to the URL to send device control actions (on/off) to (in this case https://use1-wap.tplinkcloud.com)
45 // {"error_code":0,"result":{"deviceList":[{"fwVer":"1.4.3 Build 170504 Rel.144921","deviceName":"Smart Wi-Fi LED Bulb with Color Changing","status":0,"alias":"My_TPLink_LightBulb","deviceType":"IOT.SMARTBULB","appServerUrl":"https://use1-wap.tplinkcloud.com","deviceModel":"LB130(US)","deviceMac":"50C7BF59D584","role":0,"isSameRegion":true,"hwId":"111E35908497A05512E259BB76801E10","fwId":"00000000000000000000000000000000","oemId":"05BF7B3BE1675C5A6867B7A7E4C9F6F7","deviceId":"8012CE834562C3304F4FD28FBFBA86E4185B6843","deviceHwVer":"1.0"},{"fwVer":"1.2.5 Build 171206 Rel.085954","deviceName":"Wi-Fi Smart Plug With Energy Monitoring","status":1,"alias":"My Smart Plug","deviceType":"IOT.SMARTPLUGSWITCH","appServerUrl":"https://use1-wap.tplinkcloud.com","deviceModel":"HS110(US)","deviceMac":"50C7BF331F09","role":0,"isSameRegion":true,"hwId":"60FF6B258734EA6880E186F8C96DDC61","fwId":"00000000000000000000000000000000","oemId":"FFF22CFF774A0B89F7624BFC6F50D5DE","deviceId":"800617CC047187F5251E5B88567ACC6D1819FDCF","deviceHwVer":"1.0"}]}}
46
47
48
49
50 //    async set_relay_state(state){
51 //        return await super.tplink_request( {"system":{"set_relay_state":{"state": state }}} )
52 //    }
53
54 // deviceId 800617CC047187F5251E5B88567ACC6D1819FDCF or alias "My Smart Plug" ?
55 //    {
56 //        "method":"passthrough",
57 //        "params": {
58 //            "deviceId": "My Smart Plug",
59 //            "requestData": {"system":{"set_relay_state":{"state": 0 }}} // 0 for off, 1 for on
60 //        }
61 //    }
62
63 // curl --request POST "https://use1-wap.tplinkcloud.com/?token=a749210e-A9F3yu9IMYGWAepK0KCVNp0 HTTP/1.1" --data '{"method":"passthrough", "params": {"deviceId": "800617CC047187F5251E5B88567ACC6D1819FDCF", "requestData": "{\"system\":{\"set_relay_state\":{\"state\":1}}}" }}' --header "Content-Type: application/json"