use of tuwien.auto.calimero.link.medium.TPSettings in project openhab1-addons by openhab.
the class KNXConnection method connectByIp.
private static KNXNetworkLink connectByIp(int ipConnectionType, String localIp, String ip, int port) throws KNXException, UnknownHostException, InterruptedException {
InetSocketAddress localEndPoint = null;
if (StringUtils.isNotBlank(localIp)) {
localEndPoint = new InetSocketAddress(localIp, 0);
} else {
try {
InetAddress localHost = InetAddress.getLocalHost();
localEndPoint = new InetSocketAddress(localHost, 0);
} catch (UnknownHostException uhe) {
sLogger.warn("Couldn't find an IP address for this host. Please check the .hosts configuration or use the 'localIp' parameter to configure a valid IP address.");
}
}
return new KNXNetworkLinkIP(ipConnectionType, localEndPoint, new InetSocketAddress(ip, port), sUseNAT, new TPSettings(new IndividualAddress(sLocalSourceAddr), true));
}
use of tuwien.auto.calimero.link.medium.TPSettings in project openremote by openremote.
the class KNXConnection method connect.
public synchronized void connect() {
if (connectionStatus == ConnectionStatus.CONNECTED || connectionStatus == ConnectionStatus.CONNECTING) {
LOG.finest("Already connected or connection in progress");
return;
}
onConnectionStatusChanged(ConnectionStatus.CONNECTING);
InetSocketAddress localEndPoint;
InetSocketAddress remoteEndPoint = new InetSocketAddress(this.gatewayAddress, this.gatewayPort);
try {
TPSettings tpSettings = new TPSettings(new IndividualAddress(this.messageSourceAddress));
if (StringUtils.isNotBlank(this.bindAddress)) {
localEndPoint = new InetSocketAddress(this.bindAddress, 0);
} else {
InetAddress localHost = InetAddress.getLocalHost();
localEndPoint = new InetSocketAddress(localHost, 0);
}
if (!routingMode) {
knxLink = KNXNetworkLinkIP.newTunnelingLink(localEndPoint, remoteEndPoint, this.natMode, tpSettings);
} else {
knxLink = KNXNetworkLinkIP.newRoutingLink(localEndPoint.getAddress(), remoteEndPoint.getAddress(), tpSettings);
}
if (knxLink.isOpen()) {
LOG.fine("Successfully connected to: " + gatewayAddress + ":" + port);
processCommunicator = new ProcessCommunicatorImpl(knxLink);
processCommunicator.addProcessListener(this);
knxLink.addLinkListener(this);
reconnectTask = null;
reconnectDelayMilliseconds = INITIAL_RECONNECT_DELAY_MILLIS;
onConnectionStatusChanged(ConnectionStatus.CONNECTED);
// Get the values of all registered group addresses
LOG.finer("Initialising group address values");
synchronized (groupAddressConsumerMap) {
groupAddressConsumerMap.forEach((groupAddress, datapointConsumerList) -> {
if (!datapointConsumerList.isEmpty()) {
// Take first data point for the group address and request the value
Pair<StateDP, Consumer<Object>> datapointConsumer = datapointConsumerList.get(0);
getGroupAddressValue(datapointConsumer.key.getMainAddress(), datapointConsumer.key.getPriority());
}
});
}
} else {
LOG.log(Level.INFO, "Connection error");
// Failed to connect so schedule reconnection attempt
scheduleReconnect();
}
} catch (final KNXException | InterruptedException e) {
LOG.log(Level.INFO, "Connection error", e.getMessage());
scheduleReconnect();
} catch (final UnknownHostException e) {
LOG.log(Level.INFO, "Connection error", e.getMessage());
}
}
Aggregations