Search in sources :

Example 1 with Lwm2mDeviceProfileTransportConfiguration

use of org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration in project thingsboard by thingsboard.

the class LwM2mClientContextImpl method getPowerMode.

private PowerMode getPowerMode(LwM2mClient lwM2MClient) {
    PowerMode powerMode = lwM2MClient.getPowerMode();
    if (powerMode == null) {
        Lwm2mDeviceProfileTransportConfiguration deviceProfile = getProfile(lwM2MClient.getProfileId());
        powerMode = deviceProfile.getClientLwM2mSettings().getPowerMode();
    }
    return powerMode;
}
Also used : PowerMode(org.thingsboard.server.common.data.device.data.PowerMode) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration)

Example 2 with Lwm2mDeviceProfileTransportConfiguration

use of org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration in project thingsboard by thingsboard.

the class LwM2mClientContextImpl method getObjectIdByKeyNameFromProfile.

@Override
public String getObjectIdByKeyNameFromProfile(LwM2mClient client, String keyName) {
    Lwm2mDeviceProfileTransportConfiguration profile = getProfile(client.getProfileId());
    for (Map.Entry<String, String> entry : profile.getObserveAttr().getKeyName().entrySet()) {
        String k = entry.getKey();
        String v = entry.getValue();
        if (v.equals(keyName) && client.isValidObjectVersion(k).isEmpty()) {
            return k;
        }
    }
    throw new IllegalArgumentException(keyName + " is not configured in the device profile!");
}
Also used : Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with Lwm2mDeviceProfileTransportConfiguration

use of org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration in project thingsboard by thingsboard.

the class DeviceBulkImportService method setUpLwM2mDeviceProfile.

private DeviceProfile setUpLwM2mDeviceProfile(TenantId tenantId, Device device) {
    DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileByName(tenantId, device.getType());
    if (deviceProfile != null) {
        if (deviceProfile.getTransportType() != DeviceTransportType.LWM2M) {
            deviceProfile.setTransportType(DeviceTransportType.LWM2M);
            deviceProfile.getProfileData().setTransportConfiguration(new Lwm2mDeviceProfileTransportConfiguration());
            deviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile);
        }
    } else {
        findOrCreateDeviceProfileLock.lock();
        try {
            deviceProfile = deviceProfileService.findDeviceProfileByName(tenantId, device.getType());
            if (deviceProfile == null) {
                deviceProfile = new DeviceProfile();
                deviceProfile.setTenantId(tenantId);
                deviceProfile.setType(DeviceProfileType.DEFAULT);
                deviceProfile.setName(device.getType());
                deviceProfile.setTransportType(DeviceTransportType.LWM2M);
                deviceProfile.setProvisionType(DeviceProfileProvisionType.DISABLED);
                DeviceProfileData deviceProfileData = new DeviceProfileData();
                DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration();
                DeviceProfileTransportConfiguration transportConfiguration = new Lwm2mDeviceProfileTransportConfiguration();
                DisabledDeviceProfileProvisionConfiguration provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(null);
                deviceProfileData.setConfiguration(configuration);
                deviceProfileData.setTransportConfiguration(transportConfiguration);
                deviceProfileData.setProvisionConfiguration(provisionConfiguration);
                deviceProfile.setProfileData(deviceProfileData);
                deviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile);
            }
        } finally {
            findOrCreateDeviceProfileLock.unlock();
        }
    }
    return deviceProfile;
}
Also used : DefaultDeviceProfileConfiguration(org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) DeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData) DisabledDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration)

Example 4 with Lwm2mDeviceProfileTransportConfiguration

use of org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration in project thingsboard by thingsboard.

the class AbstractLwM2MIntegrationTest method basicTestConnectionObserveTelemetry.

public void basicTestConnectionObserveTelemetry(Security security, LwM2MDeviceCredentials deviceCredentials, Configuration coapConfig, String endpoint) throws Exception {
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS, getBootstrapServerCredentialsNoSec(NONE));
    createDeviceProfile(transportConfiguration);
    Device device = createDevice(deviceCredentials, endpoint);
    SingleEntityFilter sef = new SingleEntityFilter();
    sef.setSingleEntity(device.getId());
    LatestValueCmd latestCmd = new LatestValueCmd();
    latestCmd.setKeys(Collections.singletonList(new EntityKey(EntityKeyType.TIME_SERIES, "batteryLevel")));
    EntityDataQuery edq = new EntityDataQuery(sef, new EntityDataPageLink(1, 0, null, null), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    EntityDataCmd cmd = new EntityDataCmd(1, edq, null, latestCmd, null);
    TelemetryPluginCmdsWrapper wrapper = new TelemetryPluginCmdsWrapper();
    wrapper.setEntityDataCmds(Collections.singletonList(cmd));
    wsClient.send(mapper.writeValueAsString(wrapper));
    wsClient.waitForReply();
    wsClient.registerWaitForUpdate();
    createNewClient(security, coapConfig, false, endpoint, false, null);
    String msg = wsClient.waitForUpdate();
    EntityDataUpdate update = mapper.readValue(msg, EntityDataUpdate.class);
    Assert.assertEquals(1, update.getCmdId());
    List<EntityData> eData = update.getUpdate();
    Assert.assertNotNull(eData);
    Assert.assertEquals(1, eData.size());
    Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
    Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.TIME_SERIES));
    var tsValue = eData.get(0).getLatest().get(EntityKeyType.TIME_SERIES).get("batteryLevel");
    Assert.assertThat(Long.parseLong(tsValue.getValue()), instanceOf(Long.class));
    int expectedMax = 50;
    int expectedMin = 5;
    Assert.assertTrue(expectedMax >= Long.parseLong(tsValue.getValue()));
    Assert.assertTrue(expectedMin <= Long.parseLong(tsValue.getValue()));
}
Also used : Device(org.thingsboard.server.common.data.Device) EntityDataPageLink(org.thingsboard.server.common.data.query.EntityDataPageLink) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) EntityData(org.thingsboard.server.common.data.query.EntityData) EntityDataUpdate(org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate) EntityKey(org.thingsboard.server.common.data.query.EntityKey) LatestValueCmd(org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd) EntityDataQuery(org.thingsboard.server.common.data.query.EntityDataQuery) SingleEntityFilter(org.thingsboard.server.common.data.query.SingleEntityFilter) EntityDataCmd(org.thingsboard.server.service.telemetry.cmd.v2.EntityDataCmd) TelemetryPluginCmdsWrapper(org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmdsWrapper)

Example 5 with Lwm2mDeviceProfileTransportConfiguration

use of org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration in project thingsboard by thingsboard.

the class AbstractLwM2MIntegrationTest method getTransportConfiguration.

protected Lwm2mDeviceProfileTransportConfiguration getTransportConfiguration(String observeAttr, List<LwM2MBootstrapServerCredential> bootstrapServerCredentials) {
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = new Lwm2mDeviceProfileTransportConfiguration();
    TelemetryMappingConfiguration observeAttrConfiguration = JacksonUtil.fromString(observeAttr, TelemetryMappingConfiguration.class);
    OtherConfiguration clientLwM2mSettings = JacksonUtil.fromString(CLIENT_LWM2M_SETTINGS, OtherConfiguration.class);
    transportConfiguration.setBootstrapServerUpdateEnable(true);
    transportConfiguration.setObserveAttr(observeAttrConfiguration);
    transportConfiguration.setClientLwM2mSettings(clientLwM2mSettings);
    transportConfiguration.setBootstrap(bootstrapServerCredentials);
    return transportConfiguration;
}
Also used : OtherConfiguration(org.thingsboard.server.common.data.device.profile.lwm2m.OtherConfiguration) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) TelemetryMappingConfiguration(org.thingsboard.server.common.data.device.profile.lwm2m.TelemetryMappingConfiguration)

Aggregations

Lwm2mDeviceProfileTransportConfiguration (org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration)30 LwM2MDeviceCredentials (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials)19 Test (org.junit.Test)16 AbstractSecurityLwM2MIntegrationTest (org.thingsboard.server.transport.lwm2m.security.AbstractSecurityLwM2MIntegrationTest)13 PrivateKey (java.security.PrivateKey)10 X509Certificate (java.security.cert.X509Certificate)10 Security (org.eclipse.leshan.client.object.Security)8 Device (org.thingsboard.server.common.data.Device)6 X509ClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.X509ClientCredential)6 MvcResult (org.springframework.test.web.servlet.MvcResult)5 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)4 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 PSKClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.PSKClientCredential)3 RPKClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.RPKClientCredential)3 KvEntry (org.thingsboard.server.common.data.kv.KvEntry)3 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)3 OtaPackageUpdateStatus (org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus)3 AbstractOtaLwM2MIntegrationTest (org.thingsboard.server.transport.lwm2m.ota.AbstractOtaLwM2MIntegrationTest)3 Collections (java.util.Collections)2