3 //import iotcode.annotation.*;
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;
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;
21 private IoTDeviceAddress deviceAddress = null;
23 public Wemo(IoTDeviceAddress _deviceAddress) {
24 deviceAddress = _deviceAddress;
28 public void turnOff() throws IOException {
29 IoTHTTP httpConnection = null;
31 httpConnection = new IoTHTTP(deviceAddress);
32 httpConnection.setURL("/upnp/control/basicevent1");
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\"");
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");
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";
47 OutputStream reqStream = httpConnection.getOutputStream();
48 reqStream.write(reqXML.getBytes());
50 InputStream resStream = httpConnection.getInputStream();
51 byte[] byteBuf = new byte[10240];
52 int len = resStream.read(byteBuf);
59 if (httpConnection != null) {
61 httpConnection.disconnect();
63 } catch (Exception e) {
72 public void turnOn() throws IOException {
73 IoTHTTP httpConnection = null;
75 httpConnection = new IoTHTTP(deviceAddress);
76 httpConnection.setURL("/upnp/control/basicevent1");
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", "");
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";
87 OutputStream reqStream = httpConnection.getOutputStream();
88 reqStream.write(reqXML.getBytes());
90 InputStream resStream = httpConnection.getInputStream();
91 byte[] byteBuf = new byte[10240];
92 int len = resStream.read(byteBuf);
98 if (httpConnection != null) {
100 httpConnection.disconnect();
102 } catch (Exception e) {