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;
30 public void turnOff() throws IOException {
31 IoTHTTP httpConnection = null;
33 httpConnection = new IoTHTTP(deviceAddress);
34 httpConnection.setURL("/upnp/control/basicevent1");
36 httpConnection.openConnection();
37 httpConnection.setDoOutput(true);
38 httpConnection.setRequestMethod("POST");
39 httpConnection.setRequestProperty("Connection", "close");
40 httpConnection.setRequestProperty("Content-type", "text/xml; charset=\"utf-8\"");
41 httpConnection.setRequestProperty("SOAPACTION", "\"urn:Belkin:service:basicevent:1#SetBinaryState\"");
43 httpConnection.setRequestProperty("User-Agent", "Java/1.8.0");
44 httpConnection.setRequestProperty("Host", "\"192.168.1.5:49153");
45 httpConnection.setRequestProperty("Accept", "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2");
47 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";
49 OutputStream reqStream = httpConnection.getOutputStream();
50 reqStream.write(reqXML.getBytes());
52 InputStream resStream = httpConnection.getInputStream();
53 byte[] byteBuf = new byte[10240];
54 int len = resStream.read(byteBuf);
61 if (httpConnection != null) {
63 httpConnection.disconnect();
65 } catch (Exception e) {
74 public void turnOn() throws IOException {
75 IoTHTTP httpConnection = null;
77 httpConnection = new IoTHTTP(deviceAddress);
78 httpConnection.setURL("/upnp/control/basicevent1");
80 httpConnection.openConnection();
81 httpConnection.setDoOutput(true);
82 httpConnection.setRequestMethod("POST");
83 httpConnection.setRequestProperty("Content-type", "text/xml; charset=\"utf-8\"");
84 httpConnection.setRequestProperty("SOAPACTION", "\"urn:Belkin:service:basicevent:1#SetBinaryState\"");
85 httpConnection.setRequestProperty("Accept", "");
87 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";
89 OutputStream reqStream = httpConnection.getOutputStream();
90 reqStream.write(reqXML.getBytes());
92 InputStream resStream = httpConnection.getInputStream();
93 byte[] byteBuf = new byte[10240];
94 int len = resStream.read(byteBuf);
100 if (httpConnection != null) {
102 httpConnection.disconnect();
104 } catch (Exception e) {