mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-16 10:14: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.net.*;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
// import java.time.Instant;
|
||||
// import java.time.temporal.ChronoUnit;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.apache.http.conn.util.*;
|
||||
@@ -63,7 +63,7 @@ public class UpnpListener {
|
||||
"ST: urn:schemas-upnp-org:device:basic:1\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" +
|
||||
"CACHE-CONTROL: max-age=100\r\n" +
|
||||
"LOCATION: http://%s:%s/description.xml\r\n" +
|
||||
@@ -202,8 +202,8 @@ public class UpnpListener {
|
||||
} catch (SocketException e1) {
|
||||
log.warn("Could not sent soTimeout on multi-cast socket");
|
||||
}
|
||||
Instant current, previous;
|
||||
previous = Instant.now();
|
||||
// Instant current, previous;
|
||||
// previous = Instant.now();
|
||||
while (loopControl) { // trigger shutdown here
|
||||
byte[] buf = new byte[1024];
|
||||
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
||||
@@ -379,7 +379,7 @@ public class UpnpListener {
|
||||
// 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);
|
||||
if (traceupnp) {
|
||||
log.info("Traceupnp: sendUpnpNotify notifyTemplate1");
|
||||
@@ -416,22 +416,6 @@ public class UpnpListener {
|
||||
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
|
||||
// Ruthlessly stolen from
|
||||
// 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 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"
|
||||
+ "<specVersion>\n"
|
||||
+ "<major>1</major>\n"
|
||||
@@ -41,8 +41,9 @@ public class UpnpSettingsResource {
|
||||
+ "<modelNumber>" + HueConstants.MODEL_ID + "</modelNumber>\n"
|
||||
+ "<modelURL>http://www.meethue.com</modelURL>\n"
|
||||
+ "<serialNumber>%s</serialNumber>\n"
|
||||
+ "<UDN>uuid:" + HueConstants.UUID_PREFIX + "%s</UDN>\n"
|
||||
+ "<presentationURL>index.html</presentationURL>\n"
|
||||
+ "<UDN>uuid:" + HueConstants.UUID_PREFIX + "%s</UDN>\n";
|
||||
|
||||
private String hueTemplate_post = "<presentationURL>index.html</presentationURL>\n"
|
||||
+ "<iconList>\n"
|
||||
+ "<icon>\n"
|
||||
+ "<mimetype>image/png</mimetype>\n"
|
||||
@@ -62,6 +63,17 @@ public class UpnpSettingsResource {
|
||||
+ "</device>\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) {
|
||||
super();
|
||||
this.bridgeSettings = theBridgeSettings;
|
||||
@@ -80,7 +92,16 @@ public class UpnpSettingsResource {
|
||||
|
||||
String portNumber = Integer.toString(request.port());
|
||||
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();
|
||||
filledTemplate = String.format(hueTemplate, httpLocationAddr, portNumber, httpLocationAddr, bridgeIdMac, bridgeIdMac);
|
||||
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