Fixing initialization to just create a table on the cloud side.
[iotcloud.git] / version2 / src / java / light_fan_embed_benchmark / Wemo.java
1 // IoT Packages
2
3 //import iotcode.annotation.*;
4
5 // Native Java Packages
6 import java.util.Iterator;
7 import javax.xml.parsers.*;
8 import java.io.InputStream;
9 import java.io.OutputStream;
10 import java.io.IOException;
11 import java.nio.charset.StandardCharsets;
12 import org.w3c.dom.*;
13 import org.xml.sax.SAXException;
14 import java.util.concurrent.atomic.AtomicBoolean;
15 import java.util.concurrent.Semaphore;
16 import java.util.List;
17 import java.util.ArrayList;
18
19 public class Wemo {
20
21     private IoTDeviceAddress deviceAddress = null;
22
23     public Wemo(IoTDeviceAddress _deviceAddress) {
24         deviceAddress = _deviceAddress;
25
26     }
27
28     public void turnOff() throws IOException {
29         IoTHTTP httpConnection = null;
30         try {
31             httpConnection = new IoTHTTP(deviceAddress);
32             httpConnection.setURL("/upnp/control/basicevent1");
33
34             httpConnection.openConnection();
35             httpConnection.setDoOutput(true);
36             httpConnection.setRequestMethod("POST");
37             httpConnection.setRequestProperty("Connection", "close");
38             httpConnection.setRequestProperty("Content-type", "text/xml; charset=\"utf-8\"");
39             httpConnection.setRequestProperty("SOAPACTION", "\"urn:Belkin:service:basicevent:1#SetBinaryState\"");
40             
41             httpConnection.setRequestProperty("User-Agent", "Java/1.8.0");
42             httpConnection.setRequestProperty("Host", "\"192.168.1.5:49153");
43             httpConnection.setRequestProperty("Accept", "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2");
44
45             String reqXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetBinaryState xmlns:u=\"urn:Belkin:service:basicevent:1\"><BinaryState>0</BinaryState></u:SetBinaryState></s:Body></s:Envelope>\n";
46
47             OutputStream reqStream = httpConnection.getOutputStream();
48             reqStream.write(reqXML.getBytes());
49
50             InputStream resStream = httpConnection.getInputStream();
51             byte[] byteBuf = new byte[10240];
52             int len = resStream.read(byteBuf);
53
54             reqStream.close();
55             resStream.close();
56
57
58         } finally {
59             if (httpConnection != null) {
60                 try {
61                     httpConnection.disconnect();
62
63                 } catch (Exception e) {
64                     e.printStackTrace();
65
66                 }
67             }
68         }
69
70     }
71
72     public void turnOn() throws IOException {
73         IoTHTTP httpConnection = null;
74         try {
75             httpConnection = new IoTHTTP(deviceAddress);
76             httpConnection.setURL("/upnp/control/basicevent1");
77
78             httpConnection.openConnection();
79             httpConnection.setDoOutput(true);
80             httpConnection.setRequestMethod("POST");
81             httpConnection.setRequestProperty("Content-type", "text/xml; charset=\"utf-8\"");
82             httpConnection.setRequestProperty("SOAPACTION", "\"urn:Belkin:service:basicevent:1#SetBinaryState\"");
83             httpConnection.setRequestProperty("Accept", "");
84
85             String reqXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetBinaryState xmlns:u=\"urn:Belkin:service:basicevent:1\"><BinaryState>1</BinaryState></u:SetBinaryState></s:Body></s:Envelope>\n";
86
87             OutputStream reqStream = httpConnection.getOutputStream();
88             reqStream.write(reqXML.getBytes());
89
90             InputStream resStream = httpConnection.getInputStream();
91             byte[] byteBuf = new byte[10240];
92             int len = resStream.read(byteBuf);
93
94             reqStream.close();
95             resStream.close();
96
97         } finally {
98             if (httpConnection != null) {
99                 try {
100                     httpConnection.disconnect();
101
102                 } catch (Exception e) {
103                     e.printStackTrace();
104
105                 }
106             }
107         }
108     }
109 }