mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-21 09:13:21 +00:00
Merge remote-tracking branch 'origin/master' into postv3.5.1changes
This commit is contained in:
@@ -5,6 +5,8 @@ Emulates Philips Hue api to other home automation gateways such as an Amazon Ech
|
|||||||
|
|
||||||
**NOTE: This software does require the user to have knwoledge on how processes run on Linux or Windows with java. Also, an understanding of networking basics will help as well. This system reveives upnp udp multicast packets from devices to be found, so that is some thing to understand. Please make sure you have all your devices use static IP addresses from your router. Most all questions have been answered already. PLEASE USE GOOGLE TO FIND YOUR ANSWERS!**
|
**NOTE: This software does require the user to have knwoledge on how processes run on Linux or Windows with java. Also, an understanding of networking basics will help as well. This system reveives upnp udp multicast packets from devices to be found, so that is some thing to understand. Please make sure you have all your devices use static IP addresses from your router. Most all questions have been answered already. PLEASE USE GOOGLE TO FIND YOUR ANSWERS!**
|
||||||
|
|
||||||
|
**NOTE: This software does not control Philips Hue devices directly. A physical Philips Hue Hub is required for that, by which the ha-bridge can then proxy all of your real Hue bridges behind this bridge.**
|
||||||
|
|
||||||
In the cases of systems that require authorization and/or have API's that cannot be handled in the current method, a module may need to be built. The Harmony Hub is such a module and so is the Nest module. The Bridge has helpers to build devices for the gateway for the Logitech Harmony Hub, Vera, Vera Lite or Vera Edge, Nest and the ability to proxy all of your real Hue bridges behind this bridge.
|
In the cases of systems that require authorization and/or have API's that cannot be handled in the current method, a module may need to be built. The Harmony Hub is such a module and so is the Nest module. The Bridge has helpers to build devices for the gateway for the Logitech Harmony Hub, Vera, Vera Lite or Vera Edge, Nest and the ability to proxy all of your real Hue bridges behind this bridge.
|
||||||
|
|
||||||
Alternatively the Bridge supports custom calls as well using http/https/udp and tcp such as the LimitlessLED/MiLight bulbs using the UDP protocol. Binary data is supported with UDP/TCP.
|
Alternatively the Bridge supports custom calls as well using http/https/udp and tcp such as the LimitlessLED/MiLight bulbs using the UDP protocol. Binary data is supported with UDP/TCP.
|
||||||
|
|||||||
@@ -1,72 +1,72 @@
|
|||||||
package com.bwssystems.util;
|
package com.bwssystems.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class UDPDatagramSender {
|
public class UDPDatagramSender {
|
||||||
private Logger log = LoggerFactory.getLogger(UDPDatagramSender.class);
|
private Logger log = LoggerFactory.getLogger(UDPDatagramSender.class);
|
||||||
private DatagramSocket responseSocket = null;
|
private DatagramSocket responseSocket = null;
|
||||||
private int udpResponsePort;
|
private int udpResponsePort;
|
||||||
|
|
||||||
public UDPDatagramSender() {
|
public UDPDatagramSender() {
|
||||||
super();
|
super();
|
||||||
udpResponsePort = 0;
|
udpResponsePort = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UDPDatagramSender createUDPDatagramSender(int udpResponsePort) {
|
public static UDPDatagramSender createUDPDatagramSender(int udpResponsePort) {
|
||||||
UDPDatagramSender aDatagramSender = new UDPDatagramSender();
|
UDPDatagramSender aDatagramSender = new UDPDatagramSender();
|
||||||
if(aDatagramSender.initializeSocket(udpResponsePort))
|
if(aDatagramSender.initializeSocket(udpResponsePort))
|
||||||
return aDatagramSender;
|
return aDatagramSender;
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean initializeSocket(int port) {
|
private boolean initializeSocket(int port) {
|
||||||
log.info("Initializing UDP response Seocket...");
|
log.info("Initializing UDP response Socket...");
|
||||||
udpResponsePort = port;
|
udpResponsePort = port;
|
||||||
boolean portLoopControl = true;
|
boolean portLoopControl = true;
|
||||||
int retryCount = 0;
|
int retryCount = 0;
|
||||||
while(portLoopControl) {
|
while(portLoopControl) {
|
||||||
try {
|
try {
|
||||||
responseSocket = new DatagramSocket(udpResponsePort);
|
responseSocket = new DatagramSocket(udpResponsePort);
|
||||||
portLoopControl = false;
|
portLoopControl = false;
|
||||||
} catch(SocketException e) {
|
} catch(SocketException e) {
|
||||||
if(retryCount == 0)
|
if(retryCount == 0)
|
||||||
log.warn("UDP Response Port is in use, starting loop to find open port for 20 tries - configured port is: " + udpResponsePort);
|
log.warn("UDP Response Port is in use, starting loop to find open port for 20 tries - configured port is: " + udpResponsePort);
|
||||||
if(retryCount >= 20) {
|
if(retryCount >= 20) {
|
||||||
portLoopControl = false;
|
portLoopControl = false;
|
||||||
log.error("UDP Response Port issue, could not find open port - last port tried: " + udpResponsePort + " with message: " + e.getMessage());
|
log.error("UDP Response Port issue, could not find open port - last port tried: " + udpResponsePort + " with message: " + e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(portLoopControl) {
|
if(portLoopControl) {
|
||||||
retryCount++;
|
retryCount++;
|
||||||
udpResponsePort++;
|
udpResponsePort++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info("UDP response Seocket initialized to: " + udpResponsePort);
|
log.info("UDP response Seocket initialized to: " + udpResponsePort);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUdpResponsePort() {
|
public int getUdpResponsePort() {
|
||||||
return udpResponsePort;
|
return udpResponsePort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeResponseSocket() {
|
public void closeResponseSocket() {
|
||||||
responseSocket.close();
|
responseSocket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendUDPResponse(String udpResponse, InetAddress requester, int sourcePort) throws IOException {
|
public void sendUDPResponse(String udpResponse, InetAddress requester, int sourcePort) throws IOException {
|
||||||
log.debug("Sending response string: <<<" + udpResponse + ">>>");
|
log.debug("Sending response string: <<<" + udpResponse + ">>>");
|
||||||
if(responseSocket == null)
|
if(responseSocket == null)
|
||||||
throw new IOException("Socket not initialized");
|
throw new IOException("Socket not initialized");
|
||||||
DatagramPacket response = new DatagramPacket(udpResponse.getBytes(), udpResponse.length(), requester, sourcePort);
|
DatagramPacket response = new DatagramPacket(udpResponse.getBytes(), udpResponse.length(), requester, sourcePort);
|
||||||
responseSocket.send(response);
|
responseSocket.send(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user