Skip to content

Commit

Permalink
Updating hue emulation repsonses using hue android app. fixed issues in
Browse files Browse the repository at this point in the history
returning the hue config and for requesting the mac address.
  • Loading branch information
bwssytems committed Dec 16, 2015
1 parent 3c54ccd commit b27bb5e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>1.2.2</version>
<version>1.2.2a</version>
<packaging>jar</packaging>

<name>HA Bridge</name>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/bwssystems/HABridge/api/hue/HueConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ private static String getMacAddress(String addr)

sb.append("00:00:88:00:bb:ee");

} catch (Exception e){

sb.append("00:00:88:00:bb:ee");

}

return sb.toString();
Expand Down
27 changes: 16 additions & 11 deletions src/main/java/com/bwssystems/HABridge/hue/HueMulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void setupServer() {
String aDeviceType = null;

if(bridgeSettings.isTraceupnp())
log.info("Traceupnp: hue api user create requested: " + request.body() + " from " + request.ip());
log.info("Traceupnp: hue api/ user create requested: " + request.body() + " from " + request.ip());
log.debug("hue api user create requested: " + request.body() + " from " + request.ip());

if(request.body() != null && !request.body().isEmpty()) {
Expand Down Expand Up @@ -155,7 +155,8 @@ public void setupServer() {
String newUser = null;
String aDeviceType = null;

log.info("HH trace: hue api user create requested: " + request.body() + " from " + request.ip());
if(bridgeSettings.isTraceupnp())
log.info("Traceupnp: hue api/* user create requested: " + request.body() + " from " + request.ip());

if(request.body() != null && !request.body().isEmpty()) {
aNewUser = new Gson().fromJson(request.body(), UserCreateRequest.class);
Expand All @@ -177,22 +178,26 @@ public void setupServer() {

// http://ip_address:port/api/config returns json objects for the config when no user is given
get(HUE_CONTEXT + "/config", "application/json", (request, response) -> {
String userId = request.params(":userid");
log.debug("hue api config requested: " + userId + " from " + request.ip());
HueApiResponse apiResponse = new HueApiResponse("Philips hue", request.ip(), "My App", userId);
if(bridgeSettings.isTraceupnp())
log.info("Traceupnp: hue api/config config requested: <no_user> from " + request.ip());
log.debug("hue api config requested: <no_user> from " + request.ip());
HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(), "My App", "none");

response.type("application/json; charset=utf-8");
response.status(HttpStatus.SC_OK);
String responseString = null;
responseString = "[{\"swversion\":\"" + apiResponse.getConfig().getSwversion() + "\",\"apiversion\":\"" + apiResponse.getConfig().getApiversion() + "\",\"name\":\"" + apiResponse.getConfig().getName() + "\",\"mac\":\"" + apiResponse.getConfig().getMac() + "\"}]";
return responseString;
});
// String responseString = null;
// responseString = "[{\"swversion\":\"" + apiResponse.getConfig().getSwversion() + "\",\"apiversion\":\"" + apiResponse.getConfig().getApiversion() + "\",\"name\":\"" + apiResponse.getConfig().getName() + "\",\"mac\":\"" + apiResponse.getConfig().getMac() + "\"}]";
// return responseString;
return apiResponse.getConfig();
}, new JsonTransformer());

// http://ip_address:port/api/{userId}/config returns json objects for the config
get(HUE_CONTEXT + "/:userid/config", "application/json", (request, response) -> {
String userId = request.params(":userid");
if(bridgeSettings.isTraceupnp())
log.info("Traceupnp: hue api/:userid/config config requested: " + userId + " from " + request.ip());
log.debug("hue api config requested: " + userId + " from " + request.ip());
HueApiResponse apiResponse = new HueApiResponse("Philips hue", request.ip(), "My App", userId);
HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(), "My App", userId);

response.type("application/json; charset=utf-8");
response.status(HttpStatus.SC_OK);
Expand All @@ -216,7 +221,7 @@ public void setupServer() {
deviceList.put(descriptor.getId(), deviceResponse);
}
);
HueApiResponse apiResponse = new HueApiResponse("Philips hue", request.ip(), "My App", userId);
HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(), "My App", userId);
apiResponse.setLights(deviceList);

response.type("application/json; charset=utf-8");
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/com/bwssystems/HABridge/upnp/UpnpListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,30 +96,33 @@ protected boolean isSSDPDiscovery(DatagramPacket packet){
//Only respond to discover request for strict upnp form
String packetString = new String(packet.getData());
if(packetString != null && packetString.startsWith("M-SEARCH * HTTP/1.1") && packetString.contains("\"ssdp:discover\"")){
if(traceupnp) {
log.info("Traceupnp: SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + ", body: " + packetString);
log.info("Traceupnp: isSSDPDiscovery found message to be an M-SEARCH message.");
}
else {
log.debug("Got SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + ", body: " + packetString);
log.debug("Found message to be an M-SEARCH message.");
}
log.debug("isSSDPDiscovery Found message to be an M-SEARCH message.");
log.debug("isSSDPDiscovery Got SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + ", body: " + packetString);

if(strict && (packetString.contains("ST: urn:schemas-upnp-org:device:basic:1") || packetString.contains("ST: upnp:rootdevice") || packetString.contains("ST: ssdp:all")))
{
if(traceupnp)
if(traceupnp) {
log.info("Traceupnp: isSSDPDiscovery found message to be an M-SEARCH message.");
log.info("Traceupnp: isSSDPDiscovery found message to be valid under strict rules - strict: " + strict);
log.info("Traceupnp: SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + ", body: " + packetString);
}
log.debug("isSSDPDiscovery found message to be valid under strict rules - strict: " + strict);
return true;
}
else if (!strict)
{
if(traceupnp)
if(traceupnp) {
log.info("Traceupnp: isSSDPDiscovery found message to be an M-SEARCH message.");
log.info("Traceupnp: isSSDPDiscovery found message to be valid under loose rules - strict: " + strict);
log.info("Traceupnp: SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + ", body: " + packetString);
}
log.debug("isSSDPDiscovery found message to be valid under loose rules - strict: " + strict);
return true;
}
}
if(traceupnp)
log.info("Traceupnp: isSSDPDiscovery found message to not be valid - strict: " + strict);
log.debug("isSSDPDiscovery found message to be an M-SEARCH message.");
log.debug("isSSDPDiscovery found message to not be valid - strict: " + strict);
log.debug("SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + ", body: " + packetString);
return false;
}

Expand Down

0 comments on commit b27bb5e

Please sign in to comment.