Search in sources :

Example 1 with TradfriCoapEndpoint

use of org.eclipse.smarthome.binding.tradfri.internal.TradfriCoapEndpoint in project smarthome by eclipse.

the class TradfriGatewayHandler method establishConnection.

private void establishConnection() {
    TradfriGatewayConfig configuration = getConfigAs(TradfriGatewayConfig.class);
    this.gatewayURI = "coaps://" + configuration.host + ":" + configuration.port + "/" + DEVICES;
    this.gatewayInfoURI = "coaps://" + configuration.host + ":" + configuration.port + "/" + GATEWAY + "/" + GATEWAY_DETAILS;
    try {
        URI uri = new URI(gatewayURI);
        deviceClient = new TradfriCoapClient(uri);
    } catch (URISyntaxException e) {
        logger.error("Illegal gateway URI '{}': {}", gatewayURI, e.getMessage());
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
        return;
    }
    DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(0));
    builder.setPskStore(new StaticPskStore(configuration.identity, configuration.preSharedKey.getBytes()));
    dtlsConnector = new DTLSConnector(builder.build());
    endPoint = new TradfriCoapEndpoint(dtlsConnector, NetworkConfig.getStandard());
    deviceClient.setEndpoint(endPoint);
    updateStatus(ThingStatus.UNKNOWN);
    // schedule a new scan every minute
    scanJob = scheduler.scheduleWithFixedDelay(this::startScan, 0, 1, TimeUnit.MINUTES);
}
Also used : StaticPskStore(org.eclipse.californium.scandium.dtls.pskstore.StaticPskStore) TradfriGatewayConfig(org.eclipse.smarthome.binding.tradfri.internal.config.TradfriGatewayConfig) InetSocketAddress(java.net.InetSocketAddress) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DtlsConnectorConfig(org.eclipse.californium.scandium.config.DtlsConnectorConfig) DTLSConnector(org.eclipse.californium.scandium.DTLSConnector) TradfriCoapEndpoint(org.eclipse.smarthome.binding.tradfri.internal.TradfriCoapEndpoint) TradfriCoapClient(org.eclipse.smarthome.binding.tradfri.internal.TradfriCoapClient)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 DTLSConnector (org.eclipse.californium.scandium.DTLSConnector)1 DtlsConnectorConfig (org.eclipse.californium.scandium.config.DtlsConnectorConfig)1 StaticPskStore (org.eclipse.californium.scandium.dtls.pskstore.StaticPskStore)1 TradfriCoapClient (org.eclipse.smarthome.binding.tradfri.internal.TradfriCoapClient)1 TradfriCoapEndpoint (org.eclipse.smarthome.binding.tradfri.internal.TradfriCoapEndpoint)1 TradfriGatewayConfig (org.eclipse.smarthome.binding.tradfri.internal.config.TradfriGatewayConfig)1