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;
31 public void turnOff() throws IOException {
32 IoTHTTP httpConnection = null;
34 httpConnection = new IoTHTTP(deviceAddress);
35 httpConnection.setURL("/upnp/control/basicevent1");
37 httpConnection.openConnection();
38 httpConnection.setDoOutput(true);
39 httpConnection.setRequestMethod("POST");
40 httpConnection.setRequestProperty("Content-type", "text/xml; charset=\"utf-8\"");
41 httpConnection.setRequestProperty("SOAPACTION", "\"urn:Belkin:service:basicevent:1#SetBinaryState\"");
42 httpConnection.setRequestProperty("Accept", "");
44 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 OutputStream reqStream = httpConnection.getOutputStream();
47 reqStream.write(reqXML.getBytes());
49 InputStream resStream = httpConnection.getInputStream();
50 byte[] byteBuf = new byte[10240];
51 int len = resStream.read(byteBuf);
58 if (httpConnection != null) {
60 httpConnection.disconnect();
62 } catch (Exception e) {
71 public void turnOn() throws IOException {
72 IoTHTTP httpConnection = null;
74 httpConnection = new IoTHTTP(deviceAddress);
75 httpConnection.setURL("/upnp/control/basicevent1");
77 httpConnection.openConnection();
78 httpConnection.setDoOutput(true);
79 httpConnection.setRequestMethod("POST");
80 httpConnection.setRequestProperty("Content-type", "text/xml; charset=\"utf-8\"");
81 httpConnection.setRequestProperty("SOAPACTION", "\"urn:Belkin:service:basicevent:1#SetBinaryState\"");
82 httpConnection.setRequestProperty("Accept", "");
84 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 OutputStream reqStream = httpConnection.getOutputStream();
87 reqStream.write(reqXML.getBytes());
89 InputStream resStream = httpConnection.getInputStream();
90 byte[] byteBuf = new byte[10240];
91 int len = resStream.read(byteBuf);
97 if (httpConnection != null) {
99 httpConnection.disconnect();
101 } catch (Exception e) {