Compare commits

...

11 Commits

Author SHA1 Message Date
bwssystems
969ed352f7 Update handling of upnp and updated how unique ids are generated 2020-12-01 19:32:42 -06:00
bwssystems
c98513c365 remove .project file 2020-11-19 12:16:08 -06:00
bwssystems
add9617a07 Fix command line config path issue
When the command line config path is used and the ocnfig file has no entry for configfile a null pointer exception occurrs
2020-11-19 12:09:13 -06:00
BWS Systems
f9e9f16756 Update Readme for RC2 2020-11-09 14:20:53 -05:00
BWS Systems
f15cc0d53a Merge pull request #1238 from bwssytems/dependabot/maven/junit-junit-4.13.1
Bump junit from 4.12 to 4.13.1
2020-11-09 13:08:53 -05:00
BWS Systems
0f791c1e71 Merge pull request #1249 from marcopollacci/dev_branch_5.3.x
Dev branch 5.3.x merge changes
2020-11-09 13:07:29 -05:00
Marco Pollacci
9887042f4d Update DeviceRepository.java 2020-11-06 10:26:00 +01:00
Marco Pollacci
c840f2bc4d Update DeviceResponse.java 2020-11-06 10:07:40 +01:00
dependabot[bot]
9a355b7906 Bump junit from 4.12 to 4.13.1
Bumps [junit](https://github.com/junit-team/junit4) from 4.12 to 4.13.1.
- [Release notes](https://github.com/junit-team/junit4/releases)
- [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.12.md)
- [Commits](https://github.com/junit-team/junit4/compare/r4.12...r4.13.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-10-13 06:42:38 +00:00
BWS Systems
9399af7ec7 Merge pull request #1138 from jimirocks/proxy
Fix nginx example
2019-09-30 08:29:21 -05:00
Jiří Mikulášek
be72f7e62c Fix nginx example 2019-09-28 00:52:06 +02:00
12 changed files with 176 additions and 120 deletions

2
.gitignore vendored
View File

@@ -12,6 +12,7 @@ data
/.settings/ /.settings/
/start.bat /start.bat
/.classpath /.classpath
/.project
sftp-config\.json sftp-config\.json
/bin/ /bin/
@@ -23,3 +24,4 @@ sftp-config\.json
/node_modules /node_modules
package-lock.json package-lock.json
.project

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ha-bridge</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@@ -57,20 +57,20 @@ Then locate the jar and start the server with:
ATTENTION: Due to port 80 being the default, Linux restricts this to super user. Use the instructions below. ATTENTION: Due to port 80 being the default, Linux restricts this to super user. Use the instructions below.
``` ```
java -jar ha-bridge-5.3.1RC1.jar java -jar ha-bridge-5.3.1RC3.jar
``` ```
## Manual installation of ha-bridge and setup of systemd service ## Manual installation of ha-bridge and setup of systemd service
Next gen Linux systems (this includes the Raspberry Pi), use systemd to run and manage services. Next gen Linux systems (this includes the Raspberry Pi), use systemd to run and manage services.
Here is a link on how to use systemd: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units Here is a link on how to use systemd: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
Create the directory and make sure that ha-bridge-5.3.1RC1.jar is in your /home/pi/ha-bridge directory. Create the directory and make sure that ha-bridge-5.3.1RC3.jar is in your /home/pi/ha-bridge directory.
``` ```
pi@raspberrypi:~ $ mkdir ha-bridge pi@raspberrypi:~ $ mkdir ha-bridge
pi@raspberrypi:~ $ cd ha-bridge pi@raspberrypi:~ $ cd ha-bridge
pi@raspberrypi:~/ha-bridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v5.3.1RC1/ha-bridge-5.3.1RC1.jar pi@raspberrypi:~/ha-bridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v5.3.1RC3/ha-bridge-5.3.1RC3.jar
``` ```
Create the ha-bridge.service unit file: Create the ha-bridge.service unit file:
@@ -89,7 +89,7 @@ After=network.target
Type=simple Type=simple
WorkingDirectory=/home/pi/ha-bridge WorkingDirectory=/home/pi/ha-bridge
ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/ha-bridge/data/habridge.config /home/pi/ha-bridge/ha-bridge-5.3.1RC1.jar ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/ha-bridge/data/habridge.config /home/pi/ha-bridge/ha-bridge-5.3.1RC3.jar
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
@@ -222,7 +222,7 @@ proxy.server = (
``` ```
### nginx Example ### nginx Example
``` ```
location /api/ { location /api {
proxy_pass http://127.0.0.1:8080/api; proxy_pass http://127.0.0.1:8080/api;
} }
``` ```

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId> <groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId> <artifactId>ha-bridge</artifactId>
<version>5.3.1RC1</version> <version>5.3.1RC3</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HA Bridge</name> <name>HA Bridge</name>
@@ -116,7 +116,7 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.12</version> <version>4.13.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
@@ -172,7 +172,7 @@
<configuration> <configuration>
<rules> <rules>
<requireMavenVersion> <requireMavenVersion>
<!-- Change this to Version 3.3 for Java 1.8 and Raspberry PI compilation --> <!-- Change this to Version 3.3 for Java 1.8 and Raspberry PI compilation, Java 11 is 3.6 -->
<version>3.6</version> <version>3.6</version>
</requireMavenVersion> </requireMavenVersion>
</rules> </rules>

View File

@@ -250,10 +250,10 @@ public class BridgeSettings extends BackupHandler {
return; return;
try { try {
theBridgeSettings = new Gson().fromJson(jsonContent, BridgeSettingsDescriptor.class); theBridgeSettings = new Gson().fromJson(jsonContent, BridgeSettingsDescriptor.class);
} catch (Exception e) {
log.warn("Issue loading values from file: " + aPath.toUri().toString() + ", Gson convert failed.");
theBridgeSettings = new BridgeSettingsDescriptor();
theBridgeSettings.setConfigfile(aPath.toString()); theBridgeSettings.setConfigfile(aPath.toString());
} catch (Exception e) {
log.warn("Issue loading values from file: " + aPath.toUri().toString() + ", Gson convert failed. Using default settings.");
theBridgeSettings = new BridgeSettingsDescriptor();
} }
} }

View File

@@ -132,6 +132,9 @@ public class BridgeSettingsDescriptor {
@SerializedName("haaddressessecured") @SerializedName("haaddressessecured")
@Expose @Expose
private boolean haaddressessecured; private boolean haaddressessecured;
@SerializedName("upnpadvanced")
@Expose
private boolean upnpadvanced;
// @SerializedName("activeloggers") // @SerializedName("activeloggers")
// @Expose // @Expose
// private List<NameValue> activeloggers; // private List<NameValue> activeloggers;
@@ -192,6 +195,8 @@ public class BridgeSettingsDescriptor {
this.upnporiginal = false; this.upnporiginal = false;
this.seedid = 100; this.seedid = 100;
this.haaddressessecured = false; this.haaddressessecured = false;
this.configfile = Configuration.CONFIG_FILE;
this.upnpadvanced = false;
} }
public String getUpnpConfigAddress() { public String getUpnpConfigAddress() {
@@ -847,4 +852,12 @@ public class BridgeSettingsDescriptor {
public void setHaaddressessecured(boolean haaddressessecured) { public void setHaaddressessecured(boolean haaddressessecured) {
this.haaddressessecured = haaddressessecured; this.haaddressessecured = haaddressessecured;
} }
public boolean isUpnpadvanced() {
return upnpadvanced;
}
public void setUpnpadvanced(boolean upnpadvanced) {
this.upnpadvanced = upnpadvanced;
}
} }

View File

@@ -17,6 +17,7 @@ public class DeviceResponse {
private String swversion; private String swversion;
private String swconfigid; private String swconfigid;
private String productid; private String productid;
private String productname;
public DeviceState getState() { public DeviceState getState() {
return state; return state;
@@ -90,6 +91,14 @@ public class DeviceResponse {
this.productid = productid; this.productid = productid;
} }
public String getProductName() {
return productname;
}
public void setProductName(String productname) {
this.productname = productname;
}
public String getLuminaireuniqueid() { public String getLuminaireuniqueid() {
return luminaireuniqueid; return luminaireuniqueid;
@@ -109,10 +118,11 @@ public class DeviceResponse {
if (device.isColorDevice()) { if (device.isColorDevice()) {
response.setType("Extended color light"); response.setType("Extended color light");
response.setModelid("LCT010"); response.setModelid("LCT015");
response.setSwversion("1.15.2_r19181"); response.setSwversion("1.46.13_r26312");
response.setSwconfigid("F921C859"); response.setSwconfigid("52E3234B");
response.setProductid("Philips-LCT010-1-A19ECLv4"); response.setProductid("Philips-LCT015-1-A19ECLv5");
response.setProductName("Hue color lamp");
} else { } else {
response.setType("Dimmable light"); response.setType("Dimmable light");
response.setModelid("LWB007"); response.setModelid("LWB007");
@@ -129,13 +139,14 @@ public class DeviceResponse {
response.setState(group.getAction()); response.setState(group.getAction());
response.setName(group.getName()); response.setName(group.getName());
response.setUniqueid("00:17:88:5E:D3:FF-" + String.format("%02X", Integer.parseInt(group.getId()))); response.setUniqueid("00:11:22:33:44:55:66:77-" + String.format("%02X", Integer.parseInt(group.getId())));
response.setManufacturername("Philips"); response.setManufacturername("Philips");
response.setType("Extended color light"); response.setType("Extended color light");
response.setModelid("LCT010"); response.setModelid("LCT015");
response.setSwversion("1.15.2_r19181"); response.setSwversion("1.46.13_r26312");
response.setSwconfigid("F921C859"); response.setSwconfigid("52E3234B");
response.setProductid("Philips-LCT010-1-A19ECLv4"); response.setProductid("Philips-LCT015-1-A19ECLv5");
response.setProductName("Hue color lamp");
response.setLuminaireuniqueid(null); response.setLuminaireuniqueid(null);

View File

@@ -2,7 +2,7 @@ package com.bwssystems.HABridge.api.hue;
public class HueConstants { public class HueConstants {
public final static String HUB_VERSION = "9999999999"; public final static String HUB_VERSION = "9999999999";
public final static String API_VERSION = "1.19.0"; public final static String API_VERSION = "1.17.0";
public final static String MODEL_ID = "BSB002"; public final static String MODEL_ID = "BSB002";
public final static String UUID_PREFIX = "2f402f80-da50-11e1-9b23-"; public final static String UUID_PREFIX = "2f402f80-da50-11e1-9b23-";
} }

View File

@@ -30,6 +30,8 @@ import com.google.gson.JsonSyntaxException;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Arrays; import java.util.Arrays;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/* /*
* This is an in memory list to manage the configured devices and saves the list as a JSON string to a file for later * This is an in memory list to manage the configured devices and saves the list as a JSON string to a file for later
@@ -188,7 +190,7 @@ public class DeviceRepository extends BackupHandler {
nextId++; nextId++;
} }
if (descriptors[i].getUniqueid() == null || descriptors[i].getUniqueid().length() == 0) { if (descriptors[i].getUniqueid() == null || descriptors[i].getUniqueid().length() == 0) {
descriptors[i].setUniqueid("00:17:88:5E:D3:" + hueUniqueId(Integer.valueOf(descriptors[i].getId()))); descriptors[i].setUniqueid(hueUniqueId(Integer.valueOf(descriptors[i].getId())));
} }
put(descriptors[i].getId(), descriptors[i]); put(descriptors[i].getId(), descriptors[i]);
theNames = theNames + " " + descriptors[i].getName() + ", "; theNames = theNames + " " + descriptors[i].getName() + ", ";
@@ -206,7 +208,6 @@ public class DeviceRepository extends BackupHandler {
DeviceDescriptor theDevice; DeviceDescriptor theDevice;
boolean findNext = true; boolean findNext = true;
nextId = seedId; nextId = seedId;
while (deviceIterator.hasNext()) { while (deviceIterator.hasNext()) {
theDevice = deviceIterator.next(); theDevice = deviceIterator.next();
@@ -228,7 +229,7 @@ public class DeviceRepository extends BackupHandler {
} }
} }
theDevice.setId(String.valueOf(nextId)); theDevice.setId(String.valueOf(nextId));
theDevice.setUniqueid("00:17:88:5E:D3:" + hueUniqueId(nextId)); theDevice.setUniqueid(hueUniqueId(nextId));
nextId++; nextId++;
} }
newdevices.put(theDevice.getId(), theDevice); newdevices.put(theDevice.getId(), theDevice);
@@ -297,11 +298,35 @@ public class DeviceRepository extends BackupHandler {
} }
private String hueUniqueId(Integer anId) { private String hueUniqueId(Integer anId) {
String theUniqueId; String theUniqueId = null;
Integer newValue; Integer newValue;
String hexValueLeft; String hexValueLeft;
String hexValueRight; String hexValueRight;
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
log.warn("Cannot get MD5 utility to hash unique ids.");
}
if(md != null) {
md.update(anId.toString().getBytes());
byte[] digest = md.digest();
theUniqueId = String.format("%s:%s:%s:%s:%s:%s:%s-%s",
HexLibrary.encodeHexString(digest).substring(0, 2),
HexLibrary.encodeHexString(digest).substring(2, 4),
HexLibrary.encodeHexString(digest).substring(4, 6),
HexLibrary.encodeHexString(digest).substring(6, 8),
HexLibrary.encodeHexString(digest).substring(8, 10),
HexLibrary.encodeHexString(digest).substring(10, 12),
HexLibrary.encodeHexString(digest).substring(12, 14),
HexLibrary.encodeHexString(digest).substring(14, 16));
}
if(theUniqueId == null) {
newValue = anId % 256; newValue = anId % 256;
if (newValue <= 0) if (newValue <= 0)
newValue = 1; newValue = 1;
@@ -316,8 +341,8 @@ public class DeviceRepository extends BackupHandler {
newValue = 255; newValue = 255;
hexValueRight = HexLibrary.byteToHex(newValue.byteValue()); hexValueRight = HexLibrary.byteToHex(newValue.byteValue());
theUniqueId = String.format("%s-%s", hexValueLeft, hexValueRight).toUpperCase(); theUniqueId = String.format("11:22:33:44:55:66:%s-%s", hexValueLeft, hexValueRight).toUpperCase();
}
return theUniqueId; return theUniqueId;
} }
} }

View File

@@ -30,6 +30,7 @@ public class UpnpListener {
private String upnpConfigIP; private String upnpConfigIP;
// private boolean strict; // private boolean strict;
private boolean upnpOriginal; private boolean upnpOriginal;
private boolean upnpAdvanced;
private boolean traceupnp; private boolean traceupnp;
private boolean useUpnpIface; private boolean useUpnpIface;
private BridgeControlDescriptor bridgeControl; private BridgeControlDescriptor bridgeControl;
@@ -38,31 +39,37 @@ public class UpnpListener {
private String httpType; private String httpType;
private HuePublicConfig aHueConfig; private HuePublicConfig aHueConfig;
private Integer theUpnpSendDelay; private Integer theUpnpSendDelay;
/* This is the minimum response needed, all others are for the advanced setting */
private String responseTemplate1 = "HTTP/1.1 200 OK\r\n" + "HOST: %s:%s\r\n" + "CACHE-CONTROL: max-age=100\r\n" private String responseTemplate1 = "HTTP/1.1 200 OK\r\n" + "HOST: %s:%s\r\n" + "CACHE-CONTROL: max-age=100\r\n"
+ "EXT:\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + "EXT:\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" + "SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/"
+ HueConstants.API_VERSION + "\r\n" + "hue-bridgeid: %s\r\n" + "ST: upnp:rootdevice\r\n" + "USN: uuid:"
+ HueConstants.UUID_PREFIX + "%s::upnp:rootdevice\r\n\r\n";
private String responseTemplate2 = "HTTP/1.1 200 OK\r\n" + "HOST: %s:%s\r\n" + "CACHE-CONTROL: max-age=100\r\n"
+ "EXT:\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/"
+ HueConstants.API_VERSION + "\r\n" + "hue-bridgeid: %s\r\n" + "ST: uuid:" + HueConstants.UUID_PREFIX
+ "%s\r\n" + "USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n";
private String responseTemplate3 = "HTTP/1.1 200 OK\r\n" + "HOST: %s:%s\r\n" + "CACHE-CONTROL: max-age=100\r\n"
+ "EXT:\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/"
+ HueConstants.API_VERSION + "\r\n" + "hue-bridgeid: %s\r\n" + "ST: urn:schemas-upnp-org:device:basic:1\r\n" + HueConstants.API_VERSION + "\r\n" + "hue-bridgeid: %s\r\n" + "ST: urn:schemas-upnp-org:device:basic:1\r\n"
+ "USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n"; + "USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n";
/* These next 2 templates are for the advanced upnp option */
private String responseTemplate2 = "HTTP/1.1 200 OK\r\n" + "HOST: %s:%s\r\n" + "CACHE-CONTROL: max-age=100\r\n"
+ "EXT:\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" + "SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/"
+ HueConstants.API_VERSION + "\r\n" + "hue-bridgeid: %s\r\n" + "ST: uuid:" + HueConstants.UUID_PREFIX
+ "%s\r\n" + "USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n";
private String responseTemplate3 = "HTTP/1.1 200 OK\r\n" + "HOST: %s:%s\r\n" + "CACHE-CONTROL: max-age=100\r\n"
+ "EXT:\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" + "SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/"
+ HueConstants.API_VERSION + "\r\n" + "hue-bridgeid: %s\r\n" + "ST: upnp:rootdevice\r\n" + "USN: uuid:"
+ HueConstants.UUID_PREFIX + "%s::upnp:rootdevice\r\n\r\n";
/* These notify templates are for the advanced upnp option */
private String notifyTemplate1 = "NOTIFY * HTTP/1.1\r\n" + "HOST: %s:%s\r\n" + "CACHE-CONTROL: max-age=100\r\n" private String notifyTemplate1 = "NOTIFY * HTTP/1.1\r\n" + "HOST: %s:%s\r\n" + "CACHE-CONTROL: max-age=100\r\n"
+ "LOCATION: %s://%s:%s/description.xml\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + "LOCATION: %s://%s:%s/description.xml\r\n" + "SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/"
+ HueConstants.API_VERSION + "\r\n" + "NTS: ssdp:alive\r\n" + "hue-bridgeid: %s\r\n" + "NT: uuid:" + HueConstants.API_VERSION + "\r\n" + "NTS: ssdp:alive\r\n" + "hue-bridgeid: %s\r\n" + "NT: uuid:"
+ HueConstants.UUID_PREFIX + "%s\r\n" + "USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n"; + HueConstants.UUID_PREFIX + "%s\r\n" + "USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n";
private String notifyTemplate2 = "NOTIFY * HTTP/1.1\r\n" + "HOST: %s:%s\r\n" + "CACHE-CONTROL: max-age=100\r\n" private String notifyTemplate2 = "NOTIFY * HTTP/1.1\r\n" + "HOST: %s:%s\r\n" + "CACHE-CONTROL: max-age=100\r\n"
+ "LOCATION: %s://%s:%s/description.xml\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + "LOCATION: %s://%s:%s/description.xml\r\n" + "SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/"
+ HueConstants.API_VERSION + "\r\n" + "NTS: ssdp:alive\r\n" + "hue-bridgeid: %s\r\n" + HueConstants.API_VERSION + "\r\n" + "NTS: ssdp:alive\r\n" + "hue-bridgeid: %s\r\n"
+ "NT: upnp:rootdevice\r\n" + "USN: uuid:" + HueConstants.UUID_PREFIX + "%s::upnp:rootdevice\r\n\r\n"; + "NT: upnp:rootdevice\r\n" + "USN: uuid:" + HueConstants.UUID_PREFIX + "%s::upnp:rootdevice\r\n\r\n";
private String notifyTemplate3 = "NOTIFY * HTTP/1.1\r\n" + "HOST: %s:%s\r\n" + "CACHE-CONTROL: max-age=100\r\n" private String notifyTemplate3 = "NOTIFY * HTTP/1.1\r\n" + "HOST: %s:%s\r\n" + "CACHE-CONTROL: max-age=100\r\n"
+ "LOCATION: %s://%s:%s/description.xml\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + "LOCATION: %s://%s:%s/description.xml\r\n" + "SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/"
+ HueConstants.API_VERSION + "\r\n" + "NTS: ssdp:alive\r\n" + "hue-bridgeid: %s\r\n" + HueConstants.API_VERSION + "\r\n" + "NTS: ssdp:alive\r\n" + "hue-bridgeid: %s\r\n"
+ "NT: urn:schemas-upnp-org:device:basic:1\r\n" + "USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n"; + "NT: urn:schemas-upnp-org:device:basic:1\r\n" + "USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n";
@@ -75,6 +82,7 @@ public class UpnpListener {
upnpConfigIP = theSettings.getBridgeSettingsDescriptor().getUpnpConfigAddress(); upnpConfigIP = theSettings.getBridgeSettingsDescriptor().getUpnpConfigAddress();
// strict = theSettings.isUpnpStrict(); // strict = theSettings.isUpnpStrict();
upnpOriginal = theSettings.getBridgeSettingsDescriptor().isUpnporiginal(); upnpOriginal = theSettings.getBridgeSettingsDescriptor().isUpnporiginal();
upnpAdvanced = theSettings.getBridgeSettingsDescriptor().isUpnpadvanced();
traceupnp = theSettings.getBridgeSettingsDescriptor().isTraceupnp(); traceupnp = theSettings.getBridgeSettingsDescriptor().isTraceupnp();
useUpnpIface = theSettings.getBridgeSettingsDescriptor().isUseupnpiface(); useUpnpIface = theSettings.getBridgeSettingsDescriptor().isUseupnpiface();
theUpnpSendDelay = theSettings.getBridgeSettingsDescriptor().getUpnpsenddelay(); theUpnpSendDelay = theSettings.getBridgeSettingsDescriptor().getUpnpsenddelay();
@@ -192,11 +200,14 @@ public class UpnpListener {
log.info("UPNP Discovery Listener running and ready...."); log.info("UPNP Discovery Listener running and ready....");
boolean loopControl = true; boolean loopControl = true;
boolean error = false; boolean error = false;
if(upnpAdvanced) {
try { try {
upnpMulticastSocket.setSoTimeout((int) Configuration.UPNP_NOTIFY_TIMEOUT); upnpMulticastSocket.setSoTimeout((int) Configuration.UPNP_NOTIFY_TIMEOUT);
} catch (SocketException e1) { } catch (SocketException e1) {
log.warn("Could not sent soTimeout on multi-cast socket"); log.warn("Could not sent soTimeout on multi-cast socket");
} }
}
// Instant current, previous; // Instant current, previous;
// previous = Instant.now(); // previous = Instant.now();
while (loopControl) { // trigger shutdown here while (loopControl) { // trigger shutdown here
@@ -326,6 +337,7 @@ public class UpnpListener {
+ " with discovery responseTemplate1 is <<<" + discoveryResponse + ">>>"); + " with discovery responseTemplate1 is <<<" + discoveryResponse + ">>>");
sendUDPResponse(discoveryResponse.getBytes(), requester, sourcePort); sendUDPResponse(discoveryResponse.getBytes(), requester, sourcePort);
if(upnpAdvanced) {
try { try {
Thread.sleep(theUpnpSendDelay); Thread.sleep(theUpnpSendDelay);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@@ -358,6 +370,7 @@ public class UpnpListener {
+ " discovery responseTemplate3 is <<<" + discoveryResponse + ">>>"); + " discovery responseTemplate3 is <<<" + discoveryResponse + ">>>");
sendUDPResponse(discoveryResponse.getBytes(), requester, sourcePort); sendUDPResponse(discoveryResponse.getBytes(), requester, sourcePort);
} }
}
private void sendUDPResponse(byte[] udpMessage, InetAddress requester, int sourcePort) throws IOException { private void sendUDPResponse(byte[] udpMessage, InetAddress requester, int sourcePort) throws IOException {
log.debug("Sending response string: <<<" + new String(udpMessage) + ">>>"); log.debug("Sending response string: <<<" + new String(udpMessage) + ">>>");

View File

@@ -55,10 +55,12 @@ public class UpnpSettingsResource {
+ "<depth>24</depth>\n" + "<depth>24</depth>\n"
+ "<url>hue_logo_3.png</url>\n" + "<url>hue_logo_3.png</url>\n"
+ "</icon>\n" + "</icon>\n"
+ "</iconList>\n" + "</iconList>\n";
+ "</device>\n"
private String hueTemplate_end = "</device>\n"
+ "</root>\n"; + "</root>\n";
/* not utilizing this section any more
private String hueTemplate_mid_orig = "<serviceList>\n" private String hueTemplate_mid_orig = "<serviceList>\n"
+ "<service>\n" + "<service>\n"
+ "<serviceType>(null)</serviceType>\n" + "<serviceType>(null)</serviceType>\n"
@@ -68,7 +70,7 @@ public class UpnpSettingsResource {
+ "<SCPDURL>(null)</SCPDURL>\n" + "<SCPDURL>(null)</SCPDURL>\n"
+ "</service>\n" + "</service>\n"
+ "</serviceList>\n"; + "</serviceList>\n";
*/
public UpnpSettingsResource(BridgeSettings theBridgeSettings) { public UpnpSettingsResource(BridgeSettings theBridgeSettings) {
super(); super();
@@ -92,7 +94,15 @@ public class UpnpSettingsResource {
String hueTemplate = null; String hueTemplate = null;
if(theSettings.isUpnporiginal()) { if(theSettings.isUpnporiginal()) {
httpLocationAddr = theSettings.getUpnpConfigAddress(); httpLocationAddr = theSettings.getUpnpConfigAddress();
hueTemplate = hueTemplate_pre + hueTemplate_mid_orig + hueTemplate_post; hueTemplate = hueTemplate_pre + hueTemplate_end;
} else if(!theSettings.isUpnpadvanced()) {
if(theSettings.isUseupnpiface()) {
httpLocationAddr = theSettings.getUpnpConfigAddress();
} else {
log.debug("Get Outbound address for ip:" + request.ip() + " and port:" + request.port());
httpLocationAddr = AddressUtil.getOutboundAddress(request.ip(), request.port()).getHostAddress();
}
hueTemplate = hueTemplate_pre + hueTemplate_end;
} else { } else {
if(theSettings.isUseupnpiface()) { if(theSettings.isUseupnpiface()) {
@@ -101,7 +111,7 @@ public class UpnpSettingsResource {
log.debug("Get Outbound address for ip:" + request.ip() + " and port:" + request.port()); log.debug("Get Outbound address for ip:" + request.ip() + " and port:" + request.port());
httpLocationAddr = AddressUtil.getOutboundAddress(request.ip(), request.port()).getHostAddress(); httpLocationAddr = AddressUtil.getOutboundAddress(request.ip(), request.port()).getHostAddress();
} }
hueTemplate = hueTemplate_pre + hueTemplate_post; hueTemplate = hueTemplate_pre + hueTemplate_post + hueTemplate_end;
} }
String bridgeIdMac = HuePublicConfig.createConfig("temp", httpLocationAddr, HueConstants.HUB_VERSION, theSettings.getHubmac()).getSNUUIDFromMac(); String bridgeIdMac = HuePublicConfig.createConfig("temp", httpLocationAddr, HueConstants.HUB_VERSION, theSettings.getHubmac()).getSNUUIDFromMac();

View File

@@ -824,6 +824,11 @@
<td><input type="checkbox" ng-model="bridge.settings.upnporiginal" ng-true-value=true <td><input type="checkbox" ng-model="bridge.settings.upnporiginal" ng-true-value=true
ng-false-value=false> {{bridge.settings.upnporiginal}}</td> ng-false-value=false> {{bridge.settings.upnporiginal}}</td>
</tr> </tr>
<tr>
<td>UPNP Advanced (use multiple responses and notifies)</td>
<td><input type="checkbox" ng-model="bridge.settings.upnpadvanced" ng-true-value=true
ng-false-value=false> {{bridge.settings.upnpadvanced}}</td>
</tr>
<tr> <tr>
<td>Trace UPNP Calls</td> <td>Trace UPNP Calls</td>
<td><input type="checkbox" ng-model="bridge.settings.traceupnp" ng-true-value=true <td><input type="checkbox" ng-model="bridge.settings.traceupnp" ng-true-value=true