Skip to content

Commit 73b2be7

Browse files
committed
Issue with http/https handling trying to token out line. Updated Readme
Fixes #96 Fixes #98
1 parent dda7a7a commit 73b2be7

File tree

4 files changed

+49
-39
lines changed

4 files changed

+49
-39
lines changed

README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ The helper tabs will also show you what you have already configured for that tar
117117
#### The Manual Add Tab
118118
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.
119119

120-
The format of these can be the default HTTP request which executes the URLs formatted as http://<your stuff here> 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://<your secure call here>. 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.
120+
The format of these can be the default HTTP request which executes the URLs formatted as `http://<your stuff here>` 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://<your secure call here>`. 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.
121121

122122
Headers can be added as well using a Json construct [{"name":"header type name","value":"the header value"}] with the format example:
123123
```
124124
[{"name":"Cache-Control","value":"no-store, no-cache, must-revalidate, post-check=0, pre-check=0"},
125125
{"name":"Pragma","value":"no-cache"}]
126126
```
127127

128-
Another option that is detected by the bridge is to use UDP or TCP direct calls such as udp://<ip_address>:<port>/<your stuff here> to send a UDP request. TCP calls are handled the same way as tcp://<ip_address>:<port>/<your stuff here>. 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.
128+
Another option that is detected by the bridge is to use UDP or TCP direct calls such as `udp://<ip_address>:<port>/<your stuff here>` to send a UDP request. TCP calls are handled the same way as `tcp://<ip_address>:<port>/<your stuff here>`. 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.
129129

130130
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)}".
131131
Examples:
@@ -138,6 +138,14 @@ http://192.168.1.1:8280/set/this
138138
ContentBody: {"someValue":"${intensity..byte}"}
139139
140140
udp://192.168.1.1:5000/0x45${intensity.percent}55
141+
142+
udp://192.168.2.2:6000/fireoffthismessage\n
143+
144+
tcp://192.168.3.3:9000/sendthismessage
145+
146+
tcp://192.168.4.4:10000/0x435f12dd${intensity.math((X -4)*50)}438c
147+
148+
tcp://192.168.5.5:110000/0x
141149
```
142150

143151
#### Multiple Call Construct

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.bwssystems.HABridge</groupId>
77
<artifactId>ha-bridge</artifactId>
8-
<version>2.0.1</version>
8+
<version>2.0.2</version>
99
<packaging>jar</packaging>
1010

1111
<name>HA Bridge</name>

src/main/java/com/bwssystems/HABridge/api/hue/DeviceState.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.bwssystems.HABridge.api.hue;
22

3-
import java.util.ArrayList;
3+
// import java.util.ArrayList;
44
import java.util.List;
55

66
/**

src/main/java/com/bwssystems/HABridge/hue/HueMulator.java

+37-35
Original file line numberDiff line numberDiff line change
@@ -583,41 +583,43 @@ else if(device.getDeviceType().startsWith("exec")) {
583583
Thread.sleep(bridgeSettings.getButtonsleep());
584584
}
585585
try {
586-
String intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
587-
String hostPortion = intermediate.substring(0, intermediate.indexOf('/'));
588-
String theUrlBody = intermediate.substring(intermediate.indexOf('/')+1);
589-
String hostAddr = null;
590-
String port = null;
591-
if(hostPortion.contains(":")) {
592-
hostAddr = hostPortion.substring(0, intermediate.indexOf(':'));
593-
port = hostPortion.substring(intermediate.indexOf(':') + 1);
594-
}
595-
else
596-
hostAddr = hostPortion;
597-
InetAddress IPAddress = InetAddress.getByName(hostAddr);;
598-
if(theUrlBody.startsWith("0x")) {
599-
theUrlBody = replaceIntensityValue(theUrlBody, state.getBri(), true);
600-
sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2));
601-
}
602-
else {
603-
theUrlBody = replaceIntensityValue(theUrlBody, state.getBri(), false);
604-
sendData = theUrlBody.getBytes();
605-
}
606-
if(callItems[i].getItem().contains("udp://")) {
607-
log.debug("executing HUE api request to UDP: " + callItems[i].getItem());
608-
DatagramSocket responseSocket = new DatagramSocket(Integer.parseInt(port));
609-
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, Integer.parseInt(port));
610-
responseSocket.send(sendPacket);
611-
responseSocket.close();
612-
}
613-
else if(callItems[i].getItem().contains("tcp://"))
614-
{
615-
log.debug("executing HUE api request to TCP: " + callItems[i].getItem());
616-
Socket dataSendSocket = new Socket(IPAddress, Integer.parseInt(port));
617-
DataOutputStream outToClient = new DataOutputStream(dataSendSocket.getOutputStream());
618-
outToClient.write(sendData);
619-
outToClient.flush();
620-
dataSendSocket.close();
586+
if(callItems[i].getItem().contains("udp://") || callItems[i].getItem().contains("tcp://")) {
587+
String intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
588+
String hostPortion = intermediate.substring(0, intermediate.indexOf('/'));
589+
String theUrlBody = intermediate.substring(intermediate.indexOf('/')+1);
590+
String hostAddr = null;
591+
String port = null;
592+
if(hostPortion.contains(":")) {
593+
hostAddr = hostPortion.substring(0, intermediate.indexOf(':'));
594+
port = hostPortion.substring(intermediate.indexOf(':') + 1);
595+
}
596+
else
597+
hostAddr = hostPortion;
598+
InetAddress IPAddress = InetAddress.getByName(hostAddr);;
599+
if(theUrlBody.startsWith("0x")) {
600+
theUrlBody = replaceIntensityValue(theUrlBody, state.getBri(), true);
601+
sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2));
602+
}
603+
else {
604+
theUrlBody = replaceIntensityValue(theUrlBody, state.getBri(), false);
605+
sendData = theUrlBody.getBytes();
606+
}
607+
if(callItems[i].getItem().contains("udp://")) {
608+
log.debug("executing HUE api request to UDP: " + callItems[i].getItem());
609+
DatagramSocket responseSocket = new DatagramSocket(Integer.parseInt(port));
610+
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, Integer.parseInt(port));
611+
responseSocket.send(sendPacket);
612+
responseSocket.close();
613+
}
614+
else if(callItems[i].getItem().contains("tcp://"))
615+
{
616+
log.debug("executing HUE api request to TCP: " + callItems[i].getItem());
617+
Socket dataSendSocket = new Socket(IPAddress, Integer.parseInt(port));
618+
DataOutputStream outToClient = new DataOutputStream(dataSendSocket.getOutputStream());
619+
outToClient.write(sendData);
620+
outToClient.flush();
621+
dataSendSocket.close();
622+
}
621623
}
622624
else {
623625
log.debug("executing HUE api request to Http " + (device.getHttpVerb() == null?"GET":device.getHttpVerb()) + ": " + callItems[i].getItem());

0 commit comments

Comments
 (0)