mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-16 18:24:36 +00:00
Update upnp original to be like v3.5.1
This commit is contained in:
@@ -12,8 +12,8 @@ import com.bwssystems.HABridge.util.UDPDatagramSender;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.time.Instant;
|
// import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
// import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
|
||||||
import org.apache.http.conn.util.*;
|
import org.apache.http.conn.util.*;
|
||||||
@@ -63,7 +63,7 @@ public class UpnpListener {
|
|||||||
"ST: urn:schemas-upnp-org:device:basic:1\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";
|
||||||
|
|
||||||
private String notifyTemplate = "NOTIFY * HTTP/1.1\r\n" +
|
private String notifyTemplate1 = "NOTIFY * HTTP/1.1\r\n" +
|
||||||
"HOST: %s:%s\r\n" +
|
"HOST: %s:%s\r\n" +
|
||||||
"CACHE-CONTROL: max-age=100\r\n" +
|
"CACHE-CONTROL: max-age=100\r\n" +
|
||||||
"LOCATION: http://%s:%s/description.xml\r\n" +
|
"LOCATION: http://%s:%s/description.xml\r\n" +
|
||||||
@@ -202,8 +202,8 @@ public class UpnpListener {
|
|||||||
} 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
|
||||||
byte[] buf = new byte[1024];
|
byte[] buf = new byte[1024];
|
||||||
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
||||||
@@ -379,7 +379,7 @@ public class UpnpListener {
|
|||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyData = String.format(notifyTemplate, Configuration.UPNP_MULTICAST_ADDRESS,
|
notifyData = String.format(notifyTemplate1, Configuration.UPNP_MULTICAST_ADDRESS,
|
||||||
Configuration.UPNP_DISCOVERY_PORT, upnpConfigIP, httpServerPort, bridgeId, bridgeSNUUID, bridgeSNUUID);
|
Configuration.UPNP_DISCOVERY_PORT, upnpConfigIP, httpServerPort, bridgeId, bridgeSNUUID, bridgeSNUUID);
|
||||||
if (traceupnp) {
|
if (traceupnp) {
|
||||||
log.info("Traceupnp: sendUpnpNotify notifyTemplate1");
|
log.info("Traceupnp: sendUpnpNotify notifyTemplate1");
|
||||||
@@ -416,22 +416,6 @@ public class UpnpListener {
|
|||||||
sendUDPResponse(notifyData.getBytes(), aSocketAddress, Configuration.UPNP_DISCOVERY_PORT);
|
sendUDPResponse(notifyData.getBytes(), aSocketAddress, Configuration.UPNP_DISCOVERY_PORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendNotifyDatagram(String notifyData, InetAddress aSocketAddress, String templateNumber) {
|
|
||||||
if (traceupnp) {
|
|
||||||
log.info("Traceupnp: sendUpnpNotify {}", templateNumber);
|
|
||||||
}
|
|
||||||
log.debug("sendUpnpNotify {} is <<<{}>>>", templateNumber, notifyData);
|
|
||||||
DatagramPacket notifyPacket = new DatagramPacket(notifyData.getBytes(), notifyData.length(), aSocketAddress,
|
|
||||||
Configuration.UPNP_DISCOVERY_PORT);
|
|
||||||
try {
|
|
||||||
upnpMulticastSocket.send(notifyPacket);
|
|
||||||
} catch (IOException e1) {
|
|
||||||
log.warn("UpnpListener encountered an error sending upnp {}. IP: {} with message: {}", templateNumber,
|
|
||||||
notifyPacket.getAddress().getHostAddress(), e1.getMessage());
|
|
||||||
log.debug("UpnpListener send {} exception: ", templateNumber, e1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// added by https://github.com/pvint
|
// added by https://github.com/pvint
|
||||||
// Ruthlessly stolen from
|
// Ruthlessly stolen from
|
||||||
// https://stackoverflow.com/questions/22045165/java-datagrampacket-receive-how-to-determine-local-ip-interface
|
// https://stackoverflow.com/questions/22045165/java-datagrampacket-receive-how-to-determine-local-ip-interface
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class UpnpSettingsResource {
|
|||||||
private BridgeSettingsDescriptor theSettings;
|
private BridgeSettingsDescriptor theSettings;
|
||||||
private BridgeSettings bridgeSettings;
|
private BridgeSettings bridgeSettings;
|
||||||
|
|
||||||
private String hueTemplate = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
|
private String hueTemplate_pre = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
|
||||||
+ "<root xmlns=\"urn:schemas-upnp-org:device-1-0\">\n"
|
+ "<root xmlns=\"urn:schemas-upnp-org:device-1-0\">\n"
|
||||||
+ "<specVersion>\n"
|
+ "<specVersion>\n"
|
||||||
+ "<major>1</major>\n"
|
+ "<major>1</major>\n"
|
||||||
@@ -41,8 +41,9 @@ public class UpnpSettingsResource {
|
|||||||
+ "<modelNumber>" + HueConstants.MODEL_ID + "</modelNumber>\n"
|
+ "<modelNumber>" + HueConstants.MODEL_ID + "</modelNumber>\n"
|
||||||
+ "<modelURL>http://www.meethue.com</modelURL>\n"
|
+ "<modelURL>http://www.meethue.com</modelURL>\n"
|
||||||
+ "<serialNumber>%s</serialNumber>\n"
|
+ "<serialNumber>%s</serialNumber>\n"
|
||||||
+ "<UDN>uuid:" + HueConstants.UUID_PREFIX + "%s</UDN>\n"
|
+ "<UDN>uuid:" + HueConstants.UUID_PREFIX + "%s</UDN>\n";
|
||||||
+ "<presentationURL>index.html</presentationURL>\n"
|
|
||||||
|
private String hueTemplate_post = "<presentationURL>index.html</presentationURL>\n"
|
||||||
+ "<iconList>\n"
|
+ "<iconList>\n"
|
||||||
+ "<icon>\n"
|
+ "<icon>\n"
|
||||||
+ "<mimetype>image/png</mimetype>\n"
|
+ "<mimetype>image/png</mimetype>\n"
|
||||||
@@ -62,6 +63,17 @@ public class UpnpSettingsResource {
|
|||||||
+ "</device>\n"
|
+ "</device>\n"
|
||||||
+ "</root>\n";
|
+ "</root>\n";
|
||||||
|
|
||||||
|
private String hueTemplate_mid_orig = "<serviceList>\n"
|
||||||
|
+ "<service>\n"
|
||||||
|
+ "<serviceType>(null)</serviceType>\n"
|
||||||
|
+ "<serviceId>(null)</serviceId>\n"
|
||||||
|
+ "<controlURL>(null)</controlURL>\n"
|
||||||
|
+ "<eventSubURL>(null)</eventSubURL>\n"
|
||||||
|
+ "<SCPDURL>(null)</SCPDURL>\n"
|
||||||
|
+ "</service>\n"
|
||||||
|
+ "</serviceList>\n";
|
||||||
|
|
||||||
|
|
||||||
public UpnpSettingsResource(BridgeSettings theBridgeSettings) {
|
public UpnpSettingsResource(BridgeSettings theBridgeSettings) {
|
||||||
super();
|
super();
|
||||||
this.bridgeSettings = theBridgeSettings;
|
this.bridgeSettings = theBridgeSettings;
|
||||||
@@ -80,7 +92,16 @@ public class UpnpSettingsResource {
|
|||||||
|
|
||||||
String portNumber = Integer.toString(request.port());
|
String portNumber = Integer.toString(request.port());
|
||||||
String filledTemplate = null;
|
String filledTemplate = null;
|
||||||
String httpLocationAddr = getOutboundAddress(request.ip(), request.port()).getHostAddress();
|
String httpLocationAddr = null;
|
||||||
|
String hueTemplate = null;
|
||||||
|
if(theSettings.isUpnporiginal()) {
|
||||||
|
httpLocationAddr = theSettings.getUpnpConfigAddress();
|
||||||
|
hueTemplate = hueTemplate_pre + hueTemplate_mid_orig + hueTemplate_post;
|
||||||
|
} else {
|
||||||
|
httpLocationAddr = getOutboundAddress(request.ip(), request.port()).getHostAddress();
|
||||||
|
hueTemplate = hueTemplate_pre + hueTemplate_post;
|
||||||
|
}
|
||||||
|
|
||||||
String bridgeIdMac = HuePublicConfig.createConfig("temp", httpLocationAddr, HueConstants.HUB_VERSION, theSettings.getHubmac()).getSNUUIDFromMac();
|
String bridgeIdMac = HuePublicConfig.createConfig("temp", httpLocationAddr, HueConstants.HUB_VERSION, theSettings.getHubmac()).getSNUUIDFromMac();
|
||||||
filledTemplate = String.format(hueTemplate, httpLocationAddr, portNumber, httpLocationAddr, bridgeIdMac, bridgeIdMac);
|
filledTemplate = String.format(hueTemplate, httpLocationAddr, portNumber, httpLocationAddr, bridgeIdMac, bridgeIdMac);
|
||||||
if(theSettings.isTraceupnp())
|
if(theSettings.isTraceupnp())
|
||||||
|
|||||||
BIN
src/main/resources/public/hue_logo_0.png
Normal file
BIN
src/main/resources/public/hue_logo_0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.6 KiB |
BIN
src/main/resources/public/hue_logo_3.png
Normal file
BIN
src/main/resources/public/hue_logo_3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
Reference in New Issue
Block a user