Added settings for strict upnp mode of checking ig it is a request for a

hue or not before responding.
Updated Readme
This commit is contained in:
Admin
2015-09-01 13:59:35 -05:00
parent 7294dbf175
commit d61d10b5b6
5 changed files with 61 additions and 78 deletions

View File

@@ -34,8 +34,51 @@ POST http://host:8080/api/devices
"onUrl" : "http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=41",
"offUrl" : "http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=41"
}
Dimming
----
Dimming is also supported by using the expessions ${intensity.percent} or ${intensity.byte} for 0-100 and 0-255 respectively.
e.g.
```
{
"name": "entry light",
"deviceType": "switch",
"offUrl": "http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=31",
"onUrl": "http://192.168.1.201:3480/data_request?id=action&output_format=json&DeviceNum=31&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=${intensity.percent}"
}
```
See the echo's documentation for the dimming phrase.
POST/PUT support
-----
added optional fields
* contentType (currently un-validated)
* httpVerb (POST/PUT/GET only supported)
* contentBody your post/put body here
This will allow control of any other application that may need mroe then GET.
e.g:
```
{
"name": "test device",
"deviceType": "switch",
"offUrl": "http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=31",
"onUrl": "http://192.168.1.201:3480/data_request?id=action&output_format=json&DeviceNum=31&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=${intensity.percent}",
"contentType" : "application/json",
"httpVerb":"POST",
"contentBody" : "{\"fooBar\":\"baz\"}"
}
```
Anything that takes an action as a result of an HTTP request will probably work - like putting Vera in and out of night mode:
```
{
"name": "night mode",
"deviceType": "switch",
"offUrl": "http://192.168.1.201:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=SetHouseMode&Mode=1",
"onUrl": "http://192.168.1.201:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=SetHouseMode&Mode=3"
}
```
Ask Alexa
----
After this Tell Alexa: "Alexa, discover my devices"
Then you can say "Alexa, Turn on the office light" or whatever name you have given your configured devices.

View File

@@ -6,6 +6,7 @@ public class BridgeSettings {
private String upnpresponseport;
private String upnpdevicedb;
private String veraaddress;
private boolean upnpStrict;
public String getUpnpConfigAddress() {
return upnpconfigaddress;
@@ -37,6 +38,11 @@ public class BridgeSettings {
public void setVeraAddress(String veraAddress) {
this.veraaddress = veraAddress;
}
public boolean isUpnpStrict() {
return upnpStrict;
}
public void setUpnpStrict(boolean upnpStrict) {
this.upnpStrict = upnpStrict;
}
}

View File

@@ -12,7 +12,6 @@ import com.bwssystems.HABridge.devicemanagmeent.*;
import com.bwssystems.HABridge.hue.HueMulator;
import com.bwssystems.HABridge.upnp.UpnpListener;
import com.bwssystems.HABridge.upnp.UpnpSettingsResource;
import com.bwssystems.vera.VeraInfo;
public class HABridge {
@@ -55,6 +54,7 @@ public class HABridge {
bridgeSettings.setUpnpDeviceDb(System.getProperty("upnp.device.db", "data/device.db"));
bridgeSettings.setUpnpResponsePort(System.getProperty("upnp.response.port", "50000"));
bridgeSettings.setVeraAddress(System.getProperty("vera.address", "192.168.1.100"));
bridgeSettings.setUpnpStrict(Boolean.parseBoolean(System.getProperty("upnp.strict", "true")));
// sparkjava config directive to set ip address for the web server to listen on
// ipAddress("0.0.0.0"); // not used

View File

@@ -1,72 +0,0 @@
package com.bwssystems.HABridge.api;
/**
* Created by arm on 4/13/15.
*/
public class Device {
private String name;
private String deviceType;
private String offUrl;
private String onUrl;
private String httpVerb;
private String contentType;
private String contentBody;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public String getOffUrl() {
return offUrl;
}
public void setOffUrl(String offUrl) {
this.offUrl = offUrl;
}
public String getOnUrl() {
return onUrl;
}
public void setOnUrl(String onUrl) {
this.onUrl = onUrl;
}
public String getHttpVerb() {
return httpVerb;
}
public void setHttpVerb(String httpVerb) {
this.httpVerb = httpVerb;
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
public String getContentBody() {
return contentBody;
}
public void setContentBody(String contentBody) {
this.contentBody = contentBody;
}
}

View File

@@ -22,12 +22,15 @@ public class UpnpListener {
private int httpServerPort;
private String responseAddress;
private boolean strict;
public UpnpListener(BridgeSettings theSettings) {
super();
upnpResponsePort = Integer.valueOf(theSettings.getUpnpResponsePort());
httpServerPort = Integer.valueOf(theSettings.getServerPort());
responseAddress = theSettings.getUpnpConfigAddress();
strict = theSettings.isUpnpStrict();
}
public void startListening(){
@@ -63,7 +66,8 @@ public class UpnpListener {
DatagramPacket packet = new DatagramPacket(buf, buf.length);
upnpMulticastSocket.receive(packet);
String packetString = new String(packet.getData());
log.debug("Got SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + " body : " + packetString);
if(packetString != null && packetString.startsWith("M-SEARCH * HTTP/1.1"))
log.debug("Got SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + " body : " + packetString);
if(isSSDPDiscovery(packetString)){
sendUpnpResponse(responseSocket, packet.getAddress(), packet.getPort());
}
@@ -85,9 +89,11 @@ public class UpnpListener {
protected boolean isSSDPDiscovery(String body){
// log.debug("Check if this is a MAN ssdp-discover packet for a upnp basic device: " + body);
//Only respond to discover request for upnp basic device from echo, the others are for the wemo
// other check: && body.contains("ST: urn:schemas-upnp-org:device:basic:1")
if(body != null && body.startsWith("M-SEARCH * HTTP/1.1") && body.contains("MAN: \"ssdp:discover\"")){
return true;
if(strict && body.contains("ST: urn:schemas-upnp-org:device:basic:1"))
return true;
else if (!strict)
return true;
}
return false;
}