/** * Tries to connect either by IP or serial bus, depending on supplied config data. * * @return true if connection was established, false otherwise */ public static synchronized boolean connect() { if (cvIp != null && cvPort > 0) { OwfsConnectionFactory owfsConnectorFactory = new OwfsConnectionFactory(cvIp, cvPort); OwfsConnectionConfig owConnectionConfig = new OwfsConnectionConfig(cvIp, cvPort); owConnectionConfig.setTemperatureScale(cvTempScale); owConnectionConfig.setPersistence(OwPersistence.ON); owConnectionConfig.setBusReturn(OwBusReturn.ON); owfsConnectorFactory.setConnectionConfig(owConnectionConfig); try { cvOwConnection = owfsConnectorFactory.createNewConnection(); cvOwConnection.listDirectory("/"); logger.info("Connected to owserver [IP '" + cvIp + "' Port '" + cvPort + "']"); cvIsEstablished = true; return true; } catch (Exception exception) { logger.error( "Couldn't connect to owserver [IP '" + cvIp + "' Port '" + cvPort + "']: ", exception.getLocalizedMessage()); cvIsEstablished = false; return false; } } else { logger.warn( "Couldn't connect to owserver because of missing connection parameters [IP '{}' Port '{}'].", cvIp, cvPort); return false; } }
void connectIfNecessary() { if (client == null) { client = factory.createNewConnection(); } }
public void addAlarmingDeviceHandler(AlarmingDeviceListener commander) throws IOException, OwfsException { commander.onInitialize(factory.createNewConnection()); alarmingDevices.put(commander.getDeviceName(), commander); }