From 73b2be752e3ce69c52550dcd19ec40b47b5f5ae9 Mon Sep 17 00:00:00 2001 From: Admin Date: Fri, 29 Apr 2016 12:27:15 -0500 Subject: [PATCH] Issue with http/https handling trying to token out line. Updated Readme Fixes #96 Fixes #98 --- README.md | 12 +++- pom.xml | 2 +- .../HABridge/api/hue/DeviceState.java | 2 +- .../bwssystems/HABridge/hue/HueMulator.java | 72 ++++++++++--------- 4 files changed, 49 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 174b891..cef2feb 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ The helper tabs will also show you what you have already configured for that tar #### The Manual Add Tab Another way to add a device is through the Manual Add Tab. This allows you to manually enter the name, the on and off URLs and select if there are custom handling with the type of call that can be made. This allows for control of anything that has a distinct request that can be executed so you are not limited to the Vera, Harmony, Nest or other Hue. -The format of these can be the default HTTP request which executes the URLs formatted as http:// as a GET. Other options to this are to select the HTTP Verb and add the data type and add a body that is passed with the request. Secure https is supported as well, just use https://. When using POST and PUT, you have the ability to specify the body that will be sent with the request as well as the application type for the http call. +The format of these can be the default HTTP request which executes the URLs formatted as `http://` as a GET. Other options to this are to select the HTTP Verb and add the data type and add a body that is passed with the request. Secure https is supported as well, just use `https://`. When using POST and PUT, you have the ability to specify the body that will be sent with the request as well as the application type for the http call. Headers can be added as well using a Json construct [{"name":"header type name","value":"the header value"}] with the format example: ``` @@ -125,7 +125,7 @@ Headers can be added as well using a Json construct [{"name":"header type name", {"name":"Pragma","value":"no-cache"}] ``` -Another option that is detected by the bridge is to use UDP or TCP direct calls such as udp://:/ to send a UDP request. TCP calls are handled the same way as tcp://:/. If your data for the UDP or TCP request is formatted as "0x00F009B9" lexical hex format, the bridge will convert the data into a binary stream to send. +Another option that is detected by the bridge is to use UDP or TCP direct calls such as `udp://:/` to send a UDP request. TCP calls are handled the same way as `tcp://:/`. If your data for the UDP or TCP request is formatted as "0x00F009B9" lexical hex format, the bridge will convert the data into a binary stream to send. You can also use the value replacement constructs within these statements. Such as using the expressions ${intensity.percent} for 0-100 or ${intensity.byte} for 0-255 for straight pass through of the value or items that require special calculated values using ${intensity.math()} i.e. "${intensity.math(X/4)}". Examples: @@ -138,6 +138,14 @@ http://192.168.1.1:8280/set/this ContentBody: {"someValue":"${intensity..byte}"} udp://192.168.1.1:5000/0x45${intensity.percent}55 + +udp://192.168.2.2:6000/fireoffthismessage\n + +tcp://192.168.3.3:9000/sendthismessage + +tcp://192.168.4.4:10000/0x435f12dd${intensity.math((X -4)*50)}438c + +tcp://192.168.5.5:110000/0x ``` #### Multiple Call Construct diff --git a/pom.xml b/pom.xml index 31469b5..7e8c09b 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 2.0.1 + 2.0.2 jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/api/hue/DeviceState.java b/src/main/java/com/bwssystems/HABridge/api/hue/DeviceState.java index 6f229f6..1f24783 100644 --- a/src/main/java/com/bwssystems/HABridge/api/hue/DeviceState.java +++ b/src/main/java/com/bwssystems/HABridge/api/hue/DeviceState.java @@ -1,6 +1,6 @@ package com.bwssystems.HABridge.api.hue; -import java.util.ArrayList; +// import java.util.ArrayList; import java.util.List; /** diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index 35c35f7..2c67da0 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -583,41 +583,43 @@ public class HueMulator implements HueErrorStringSet { Thread.sleep(bridgeSettings.getButtonsleep()); } try { - String intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3); - String hostPortion = intermediate.substring(0, intermediate.indexOf('/')); - String theUrlBody = intermediate.substring(intermediate.indexOf('/')+1); - String hostAddr = null; - String port = null; - if(hostPortion.contains(":")) { - hostAddr = hostPortion.substring(0, intermediate.indexOf(':')); - port = hostPortion.substring(intermediate.indexOf(':') + 1); - } - else - hostAddr = hostPortion; - InetAddress IPAddress = InetAddress.getByName(hostAddr);; - if(theUrlBody.startsWith("0x")) { - theUrlBody = replaceIntensityValue(theUrlBody, state.getBri(), true); - sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2)); - } - else { - theUrlBody = replaceIntensityValue(theUrlBody, state.getBri(), false); - sendData = theUrlBody.getBytes(); - } - if(callItems[i].getItem().contains("udp://")) { - log.debug("executing HUE api request to UDP: " + callItems[i].getItem()); - DatagramSocket responseSocket = new DatagramSocket(Integer.parseInt(port)); - DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, Integer.parseInt(port)); - responseSocket.send(sendPacket); - responseSocket.close(); - } - else if(callItems[i].getItem().contains("tcp://")) - { - log.debug("executing HUE api request to TCP: " + callItems[i].getItem()); - Socket dataSendSocket = new Socket(IPAddress, Integer.parseInt(port)); - DataOutputStream outToClient = new DataOutputStream(dataSendSocket.getOutputStream()); - outToClient.write(sendData); - outToClient.flush(); - dataSendSocket.close(); + if(callItems[i].getItem().contains("udp://") || callItems[i].getItem().contains("tcp://")) { + String intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3); + String hostPortion = intermediate.substring(0, intermediate.indexOf('/')); + String theUrlBody = intermediate.substring(intermediate.indexOf('/')+1); + String hostAddr = null; + String port = null; + if(hostPortion.contains(":")) { + hostAddr = hostPortion.substring(0, intermediate.indexOf(':')); + port = hostPortion.substring(intermediate.indexOf(':') + 1); + } + else + hostAddr = hostPortion; + InetAddress IPAddress = InetAddress.getByName(hostAddr);; + if(theUrlBody.startsWith("0x")) { + theUrlBody = replaceIntensityValue(theUrlBody, state.getBri(), true); + sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2)); + } + else { + theUrlBody = replaceIntensityValue(theUrlBody, state.getBri(), false); + sendData = theUrlBody.getBytes(); + } + if(callItems[i].getItem().contains("udp://")) { + log.debug("executing HUE api request to UDP: " + callItems[i].getItem()); + DatagramSocket responseSocket = new DatagramSocket(Integer.parseInt(port)); + DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, Integer.parseInt(port)); + responseSocket.send(sendPacket); + responseSocket.close(); + } + else if(callItems[i].getItem().contains("tcp://")) + { + log.debug("executing HUE api request to TCP: " + callItems[i].getItem()); + Socket dataSendSocket = new Socket(IPAddress, Integer.parseInt(port)); + DataOutputStream outToClient = new DataOutputStream(dataSendSocket.getOutputStream()); + outToClient.write(sendData); + outToClient.flush(); + dataSendSocket.close(); + } } else { log.debug("executing HUE api request to Http " + (device.getHttpVerb() == null?"GET":device.getHttpVerb()) + ": " + callItems[i].getItem());