|
|
@ -5,7 +5,7 @@ |
|
|
* you may not use this file except in compliance with the License. |
|
|
* you may not use this file except in compliance with the License. |
|
|
* You may obtain a copy of the License at |
|
|
* You may obtain a copy of the License at |
|
|
* |
|
|
* |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
* |
|
|
* |
|
|
* Unless required by applicable law or agreed to in writing, software |
|
|
* Unless required by applicable law or agreed to in writing, software |
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
|
@ -31,7 +31,6 @@ import org.eclipse.leshan.core.node.LwM2mObjectInstance; |
|
|
import org.eclipse.leshan.core.node.LwM2mPath; |
|
|
import org.eclipse.leshan.core.node.LwM2mPath; |
|
|
import org.eclipse.leshan.core.node.LwM2mResource; |
|
|
import org.eclipse.leshan.core.node.LwM2mResource; |
|
|
import org.eclipse.leshan.core.observation.Observation; |
|
|
import org.eclipse.leshan.core.observation.Observation; |
|
|
import org.eclipse.leshan.core.request.ContentFormat; |
|
|
|
|
|
import org.eclipse.leshan.core.request.WriteRequest; |
|
|
import org.eclipse.leshan.core.request.WriteRequest; |
|
|
import org.eclipse.leshan.core.response.ReadResponse; |
|
|
import org.eclipse.leshan.core.response.ReadResponse; |
|
|
import org.eclipse.leshan.server.registration.Registration; |
|
|
import org.eclipse.leshan.server.registration.Registration; |
|
|
@ -58,6 +57,8 @@ import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; |
|
|
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; |
|
|
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; |
|
|
import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper; |
|
|
import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper; |
|
|
import org.thingsboard.server.transport.lwm2m.server.adaptors.LwM2MJsonAdaptor; |
|
|
import org.thingsboard.server.transport.lwm2m.server.adaptors.LwM2MJsonAdaptor; |
|
|
|
|
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientState; |
|
|
|
|
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientStateException; |
|
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; |
|
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; |
|
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext; |
|
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext; |
|
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientProfile; |
|
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientProfile; |
|
|
@ -91,7 +92,6 @@ import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWN |
|
|
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATING; |
|
|
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATING; |
|
|
import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; |
|
|
import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper.getValueFromKvProto; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper.getValueFromKvProto; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.CLIENT_NOT_AUTHORIZED; |
|
|
|
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.DEVICE_ATTRIBUTES_REQUEST; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.DEVICE_ATTRIBUTES_REQUEST; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_ID; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_ID; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_RESULT_ID; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_RESULT_ID; |
|
|
@ -99,6 +99,7 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.L |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_INFO; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_INFO; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_TELEMETRY; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_TELEMETRY; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_VALUE; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_VALUE; |
|
|
|
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LW2M_WARN; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LWM2M_STRATEGY_2; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LWM2M_STRATEGY_2; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.DISCOVER; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.DISCOVER; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.EXECUTE; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LwM2mTypeOper.EXECUTE; |
|
|
@ -182,32 +183,38 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
*/ |
|
|
*/ |
|
|
public void onRegistered(Registration registration, Collection<Observation> previousObservations) { |
|
|
public void onRegistered(Registration registration, Collection<Observation> previousObservations) { |
|
|
registrationExecutor.submit(() -> { |
|
|
registrationExecutor.submit(() -> { |
|
|
|
|
|
LwM2mClient lwM2MClient = this.clientContext.getClientByEndpoint(registration.getEndpoint()); |
|
|
try { |
|
|
try { |
|
|
log.warn("[{}] [{{}] Client: create after Registration", registration.getEndpoint(), registration.getId()); |
|
|
log.warn("[{}] [{{}] Client: create after Registration", registration.getEndpoint(), registration.getId()); |
|
|
LwM2mClient lwM2MClient = this.clientContext.registerOrUpdate(registration); |
|
|
|
|
|
if (lwM2MClient != null) { |
|
|
if (lwM2MClient != null) { |
|
|
SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient); |
|
|
this.clientContext.register(lwM2MClient, registration); |
|
|
if (sessionInfo != null) { |
|
|
this.sendLogsToThingsboard(lwM2MClient, LOG_LW2M_INFO + ": Client registered with registration id: " + registration.getId()); |
|
|
transportService.registerAsyncSession(sessionInfo, new LwM2mSessionMsgListener(this, sessionInfo)); |
|
|
SessionInfoProto sessionInfo = lwM2MClient.getSession(); |
|
|
TransportProtos.TransportToDeviceActorMsg msg = TransportProtos.TransportToDeviceActorMsg.newBuilder() |
|
|
transportService.registerAsyncSession(sessionInfo, new LwM2mSessionMsgListener(this, sessionInfo)); |
|
|
.setSessionInfo(sessionInfo) |
|
|
TransportProtos.TransportToDeviceActorMsg msg = TransportProtos.TransportToDeviceActorMsg.newBuilder() |
|
|
.setSessionEvent(DefaultTransportService.getSessionEventMsg(SessionEvent.OPEN)) |
|
|
.setSessionInfo(sessionInfo) |
|
|
.setSubscribeToAttributes(TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().build()) |
|
|
.setSessionEvent(DefaultTransportService.getSessionEventMsg(SessionEvent.OPEN)) |
|
|
.setSubscribeToRPC(TransportProtos.SubscribeToRPCMsg.newBuilder().build()) |
|
|
.setSubscribeToAttributes(TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().build()) |
|
|
.build(); |
|
|
.setSubscribeToRPC(TransportProtos.SubscribeToRPCMsg.newBuilder().build()) |
|
|
transportService.process(msg, null); |
|
|
.build(); |
|
|
this.getInfoFirmwareUpdate(lwM2MClient, null); |
|
|
transportService.process(msg, null); |
|
|
this.getInfoSoftwareUpdate(lwM2MClient, null); |
|
|
this.getInfoFirmwareUpdate(lwM2MClient, null); |
|
|
this.initLwM2mFromClientValue(registration, lwM2MClient); |
|
|
this.getInfoSoftwareUpdate(lwM2MClient, null); |
|
|
this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client create after Registration", registration.getId()); |
|
|
this.initClientTelemetry(lwM2MClient); |
|
|
} else { |
|
|
|
|
|
log.error("Client: [{}] onRegistered [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
log.error("Client: [{}] onRegistered [{}] name [{}] lwM2MClient ", registration.getId(), registration.getEndpoint(), null); |
|
|
log.error("Client: [{}] onRegistered [{}] name [{}] lwM2MClient ", registration.getId(), registration.getEndpoint(), null); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (LwM2MClientStateException stateException) { |
|
|
|
|
|
if (LwM2MClientState.UNREGISTERED.equals(stateException.getState())) { |
|
|
|
|
|
log.info("[{}] retry registration due to race condition: [{}].", registration.getEndpoint(), stateException.getState()); |
|
|
|
|
|
// Race condition detected and the client was in progress of unregistration while new registration arrived. Let's try again.
|
|
|
|
|
|
onRegistered(registration, previousObservations); |
|
|
|
|
|
} else { |
|
|
|
|
|
this.sendLogsToThingsboard(lwM2MClient, LOG_LW2M_WARN + ": Client registration failed due to invalid state: " + stateException.getState()); |
|
|
} |
|
|
} |
|
|
} catch (Throwable t) { |
|
|
} catch (Throwable t) { |
|
|
log.error("[{}] endpoint [{}] error Unable registration.", registration.getEndpoint(), t); |
|
|
log.error("[{}] endpoint [{}] error Unable registration.", registration.getEndpoint(), t); |
|
|
|
|
|
this.sendLogsToThingsboard(lwM2MClient, LOG_LW2M_WARN + ": Client registration failed due to: " + t.getMessage()); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
@ -219,25 +226,26 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
*/ |
|
|
*/ |
|
|
public void updatedReg(Registration registration) { |
|
|
public void updatedReg(Registration registration) { |
|
|
updateRegistrationExecutor.submit(() -> { |
|
|
updateRegistrationExecutor.submit(() -> { |
|
|
|
|
|
LwM2mClient lwM2MClient = clientContext.getClientByEndpoint(registration.getEndpoint()); |
|
|
try { |
|
|
try { |
|
|
LwM2mClient client = clientContext.getOrRegister(registration); |
|
|
clientContext.updateRegistration(lwM2MClient, registration); |
|
|
if (client != null && client.getSession() != null) { |
|
|
TransportProtos.SessionInfoProto sessionInfo = lwM2MClient.getSession(); |
|
|
SessionInfoProto sessionInfo = client.getSession(); |
|
|
this.reportActivityAndRegister(sessionInfo); |
|
|
this.reportActivityAndRegister(sessionInfo); |
|
|
if (registration.usesQueueMode()) { |
|
|
if (registration.getBindingMode().useQueueMode()) { |
|
|
LwM2mQueuedRequest request; |
|
|
LwM2mQueuedRequest request; |
|
|
while ((request = lwM2MClient.getQueuedRequests().poll()) != null) { |
|
|
while ((request = client.getQueuedRequests().poll()) != null) { |
|
|
request.send(); |
|
|
request.send(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client update Registration", registration.getId()); |
|
|
} |
|
|
|
|
|
} catch (LwM2MClientStateException stateException) { |
|
|
|
|
|
if (LwM2MClientState.UNREGISTERED.equals(stateException.getState())) { |
|
|
|
|
|
log.info("[{}] update registration failed because client was already unregistered: [{}].", registration.getEndpoint(), stateException.getState()); |
|
|
} else { |
|
|
} else { |
|
|
log.error("Client: [{}] updatedReg [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null); |
|
|
log.info("[{}] update registration: [{}] {}.", registration.getEndpoint(), stateException.getState(), stateException.getMessage()); |
|
|
this.sendLogsToThingsboard(LOG_LW2M_ERROR + ": Client update Registration", registration.getId()); |
|
|
|
|
|
} |
|
|
} |
|
|
} catch (Throwable t) { |
|
|
} catch (Throwable t) { |
|
|
log.error("[{}] endpoint [{}] error Unable update registration.", registration.getEndpoint(), t); |
|
|
log.error("[{}] endpoint [{}] error Unable update registration.", registration.getEndpoint(), t); |
|
|
this.sendLogsToThingsboard(LOG_LW2M_ERROR + String.format(": Client update Registration, %s", t.getMessage()), registration.getId()); |
|
|
this.sendLogsToThingsboard(lwM2MClient, LOG_LW2M_ERROR + String.format(": Client update Registration, %s", t.getMessage())); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
@ -248,34 +256,32 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
*/ |
|
|
*/ |
|
|
public void unReg(Registration registration, Collection<Observation> observations) { |
|
|
public void unReg(Registration registration, Collection<Observation> observations) { |
|
|
unRegistrationExecutor.submit(() -> { |
|
|
unRegistrationExecutor.submit(() -> { |
|
|
|
|
|
LwM2mClient client = clientContext.getClientByEndpoint(registration.getEndpoint()); |
|
|
try { |
|
|
try { |
|
|
this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client unRegistration", registration.getId()); |
|
|
this.sendLogsToThingsboard(client, LOG_LW2M_INFO + ": Client unRegistration"); |
|
|
this.closeClientSession(registration); |
|
|
clientContext.unregister(client, registration); |
|
|
|
|
|
SessionInfoProto sessionInfo = client.getSession(); |
|
|
|
|
|
if (sessionInfo != null) { |
|
|
|
|
|
transportService.deregisterSession(sessionInfo); |
|
|
|
|
|
sessionStore.remove(registration.getEndpoint()); |
|
|
|
|
|
this.doCloseSession(sessionInfo); |
|
|
|
|
|
log.info("Client close session: [{}] unReg [{}] name [{}] profile ", registration.getId(), registration.getEndpoint(), sessionInfo.getDeviceType()); |
|
|
|
|
|
} else { |
|
|
|
|
|
log.error("Client close session: [{}] unReg [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (LwM2MClientStateException stateException) { |
|
|
|
|
|
log.info("[{}] delete registration: [{}] {}.", registration.getEndpoint(), stateException.getState(), stateException.getMessage()); |
|
|
} catch (Throwable t) { |
|
|
} catch (Throwable t) { |
|
|
log.error("[{}] endpoint [{}] error Unable un registration.", registration.getEndpoint(), t); |
|
|
log.error("[{}] endpoint [{}] error Unable un registration.", registration.getEndpoint(), t); |
|
|
this.sendLogsToThingsboard(LOG_LW2M_ERROR + String.format(": Client Unable un Registration, %s", t.getMessage()), registration.getId()); |
|
|
this.sendLogsToThingsboard(client, LOG_LW2M_ERROR + String.format(": Client Unable un Registration, %s", t.getMessage())); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void closeClientSession(Registration registration) { |
|
|
|
|
|
SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(registration); |
|
|
|
|
|
if (sessionInfo != null) { |
|
|
|
|
|
transportService.deregisterSession(sessionInfo); |
|
|
|
|
|
sessionStore.remove(registration.getEndpoint()); |
|
|
|
|
|
this.doCloseSession(sessionInfo); |
|
|
|
|
|
clientContext.removeClientByRegistrationId(registration.getId()); |
|
|
|
|
|
log.info("Client close session: [{}] unReg [{}] name [{}] profile ", registration.getId(), registration.getEndpoint(), sessionInfo.getDeviceType()); |
|
|
|
|
|
} else { |
|
|
|
|
|
log.error("Client close session: [{}] unReg [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onSleepingDev(Registration registration) { |
|
|
public void onSleepingDev(Registration registration) { |
|
|
log.info("[{}] [{}] Received endpoint Sleeping version event", registration.getId(), registration.getEndpoint()); |
|
|
log.info("[{}] [{}] Received endpoint Sleeping version event", registration.getId(), registration.getEndpoint()); |
|
|
this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client is sleeping!", registration.getId()); |
|
|
this.sendLogsToThingsboard(clientContext.getClientByEndpoint(registration.getEndpoint()), LOG_LW2M_INFO + ": Client is sleeping!"); |
|
|
|
|
|
|
|
|
//TODO: associate endpointId with device information.
|
|
|
//TODO: associate endpointId with device information.
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -285,8 +291,11 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
@Override |
|
|
@Override |
|
|
public void setCancelObservationsAll(Registration registration) { |
|
|
public void setCancelObservationsAll(Registration registration) { |
|
|
if (registration != null) { |
|
|
if (registration != null) { |
|
|
this.lwM2mTransportRequest.sendAllRequest(registration, null, OBSERVE_CANCEL_ALL, |
|
|
LwM2mClient client = clientContext.getClientByEndpoint(registration.getEndpoint()); |
|
|
null, null, this.config.getTimeout(), null); |
|
|
if (client != null && client.getRegistration() != null && client.getRegistration().getId().equals(registration.getId())) { |
|
|
|
|
|
this.lwM2mTransportRequest.sendAllRequest(client, null, OBSERVE_CANCEL_ALL, |
|
|
|
|
|
null, null, this.config.getTimeout(), null); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -300,7 +309,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
@Override |
|
|
@Override |
|
|
public void onUpdateValueAfterReadResponse(Registration registration, String path, ReadResponse response, Lwm2mClientRpcRequest rpcRequest) { |
|
|
public void onUpdateValueAfterReadResponse(Registration registration, String path, ReadResponse response, Lwm2mClientRpcRequest rpcRequest) { |
|
|
if (response.getContent() != null) { |
|
|
if (response.getContent() != null) { |
|
|
LwM2mClient lwM2MClient = clientContext.getOrRegister(registration); |
|
|
LwM2mClient lwM2MClient = clientContext.getClientByEndpoint(registration.getEndpoint()); |
|
|
ObjectModel objectModelVersion = lwM2MClient.getObjectModel(path, this.config.getModelProvider()); |
|
|
ObjectModel objectModelVersion = lwM2MClient.getObjectModel(path, this.config.getModelProvider()); |
|
|
if (objectModelVersion != null) { |
|
|
if (objectModelVersion != null) { |
|
|
if (response.getContent() instanceof LwM2mObject) { |
|
|
if (response.getContent() instanceof LwM2mObject) { |
|
|
@ -332,7 +341,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
} |
|
|
} |
|
|
String msg = String.format("%s: type operation %s path - %s value - %s", LOG_LW2M_INFO, |
|
|
String msg = String.format("%s: type operation %s path - %s value - %s", LOG_LW2M_INFO, |
|
|
READ, pathIdVer, value); |
|
|
READ, pathIdVer, value); |
|
|
this.sendLogsToThingsboard(msg, registration.getId()); |
|
|
this.sendLogsToThingsboard(lwM2MClient, msg); |
|
|
rpcRequest.setValueMsg(String.format("%s", value)); |
|
|
rpcRequest.setValueMsg(String.format("%s", value)); |
|
|
this.sentRpcResponse(rpcRequest, response.getCode().getName(), (String) value, LOG_LW2M_VALUE); |
|
|
this.sentRpcResponse(rpcRequest, response.getCode().getName(), (String) value, LOG_LW2M_VALUE); |
|
|
} |
|
|
} |
|
|
@ -350,9 +359,9 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public void onAttributeUpdate(AttributeUpdateNotificationMsg msg, TransportProtos.SessionInfoProto sessionInfo) { |
|
|
public void onAttributeUpdate(AttributeUpdateNotificationMsg msg, TransportProtos.SessionInfoProto sessionInfo) { |
|
|
LwM2mClient lwM2MClient = clientContext.getClient(sessionInfo); |
|
|
LwM2mClient lwM2MClient = clientContext.getClientBySessionInfo(sessionInfo); |
|
|
if (msg.getSharedUpdatedCount() > 0 && lwM2MClient != null) { |
|
|
if (msg.getSharedUpdatedCount() > 0 && lwM2MClient != null) { |
|
|
log.warn ("2) OnAttributeUpdate, SharedUpdatedList() [{}]", msg.getSharedUpdatedList()); |
|
|
log.warn("2) OnAttributeUpdate, SharedUpdatedList() [{}]", msg.getSharedUpdatedList()); |
|
|
msg.getSharedUpdatedList().forEach(tsKvProto -> { |
|
|
msg.getSharedUpdatedList().forEach(tsKvProto -> { |
|
|
String pathName = tsKvProto.getKv().getKey(); |
|
|
String pathName = tsKvProto.getKv().getKey(); |
|
|
String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, pathName); |
|
|
String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, pathName); |
|
|
@ -377,13 +386,13 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
log.error("Resource path - [{}] value - [{}] is not Writable and cannot be updated", pathIdVer, valueNew); |
|
|
log.error("Resource path - [{}] value - [{}] is not Writable and cannot be updated", pathIdVer, valueNew); |
|
|
String logMsg = String.format("%s: attributeUpdate: Resource path - %s value - %s is not Writable and cannot be updated", |
|
|
String logMsg = String.format("%s: attributeUpdate: Resource path - %s value - %s is not Writable and cannot be updated", |
|
|
LOG_LW2M_ERROR, pathIdVer, valueNew); |
|
|
LOG_LW2M_ERROR, pathIdVer, valueNew); |
|
|
this.sendLogsToThingsboard(logMsg, lwM2MClient.getRegistration().getId()); |
|
|
this.sendLogsToThingsboard(lwM2MClient, logMsg); |
|
|
} |
|
|
} |
|
|
} else if (!isFwSwWords(pathName)) { |
|
|
} else if (!isFwSwWords(pathName)) { |
|
|
log.error("Resource name name - [{}] value - [{}] is not present as attribute/telemetry in profile and cannot be updated", pathName, valueNew); |
|
|
log.error("Resource name name - [{}] value - [{}] is not present as attribute/telemetry in profile and cannot be updated", pathName, valueNew); |
|
|
String logMsg = String.format("%s: attributeUpdate: attribute name - %s value - %s is not present as attribute in profile and cannot be updated", |
|
|
String logMsg = String.format("%s: attributeUpdate: attribute name - %s value - %s is not present as attribute in profile and cannot be updated", |
|
|
LOG_LW2M_ERROR, pathName, valueNew); |
|
|
LOG_LW2M_ERROR, pathName, valueNew); |
|
|
this.sendLogsToThingsboard(logMsg, lwM2MClient.getRegistration().getId()); |
|
|
this.sendLogsToThingsboard(lwM2MClient, logMsg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
@ -396,9 +405,8 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
log.info("[{}] delete [{}] onAttributeUpdate", msg.getSharedDeletedList(), sessionInfo); |
|
|
log.info("[{}] delete [{}] onAttributeUpdate", msg.getSharedDeletedList(), sessionInfo); |
|
|
} |
|
|
} else if (lwM2MClient == null) { |
|
|
else if (lwM2MClient == null) { |
|
|
log.error("OnAttributeUpdate, lwM2MClient is null"); |
|
|
log.error ("OnAttributeUpdate, lwM2MClient is null"); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -408,12 +416,11 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public void onDeviceProfileUpdate(SessionInfoProto sessionInfo, DeviceProfile deviceProfile) { |
|
|
public void onDeviceProfileUpdate(SessionInfoProto sessionInfo, DeviceProfile deviceProfile) { |
|
|
Set<LwM2mClient> clients = clientContext.getLwM2mClients() |
|
|
List<LwM2mClient> clients = clientContext.getLwM2mClients() |
|
|
.stream().filter(e -> e.getProfileId().equals(deviceProfile.getUuidId())).collect(Collectors.toSet()); |
|
|
.stream().filter(e -> e.getProfileId().equals(deviceProfile.getUuidId())).collect(Collectors.toList()); |
|
|
clients.forEach(client -> client.onDeviceProfileUpdate(deviceProfile)); |
|
|
clients.forEach(client -> client.onDeviceProfileUpdate(deviceProfile)); |
|
|
Set<String> registrationIds = clients.stream().map(LwM2mClient::getRegistration).map(Registration::getId).collect(Collectors.toSet()); |
|
|
if (clients.size() > 0) { |
|
|
if (registrationIds.size() > 0) { |
|
|
this.onDeviceProfileUpdate(clients, deviceProfile); |
|
|
this.onDeviceProfileUpdate(registrationIds, deviceProfile); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -446,7 +453,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
public void onToDeviceRpcRequest(TransportProtos.ToDeviceRpcRequestMsg toDeviceRpcRequestMsg, SessionInfoProto sessionInfo) { |
|
|
public void onToDeviceRpcRequest(TransportProtos.ToDeviceRpcRequestMsg toDeviceRpcRequestMsg, SessionInfoProto sessionInfo) { |
|
|
// #1
|
|
|
// #1
|
|
|
this.checkRpcRequestTimeout(); |
|
|
this.checkRpcRequestTimeout(); |
|
|
log.warn ("4) toDeviceRpcRequestMsg: [{}], sessionUUID: [{}]", toDeviceRpcRequestMsg, new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB())); |
|
|
log.warn("4) toDeviceRpcRequestMsg: [{}], sessionUUID: [{}]", toDeviceRpcRequestMsg, new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB())); |
|
|
String bodyParams = StringUtils.trimToNull(toDeviceRpcRequestMsg.getParams()) != null ? toDeviceRpcRequestMsg.getParams() : "null"; |
|
|
String bodyParams = StringUtils.trimToNull(toDeviceRpcRequestMsg.getParams()) != null ? toDeviceRpcRequestMsg.getParams() : "null"; |
|
|
LwM2mTypeOper lwM2mTypeOper = setValidTypeOper(toDeviceRpcRequestMsg.getMethodName()); |
|
|
LwM2mTypeOper lwM2mTypeOper = setValidTypeOper(toDeviceRpcRequestMsg.getMethodName()); |
|
|
UUID requestUUID = new UUID(toDeviceRpcRequestMsg.getRequestIdMSB(), toDeviceRpcRequestMsg.getRequestIdLSB()); |
|
|
UUID requestUUID = new UUID(toDeviceRpcRequestMsg.getRequestIdMSB(), toDeviceRpcRequestMsg.getRequestIdLSB()); |
|
|
@ -454,13 +461,14 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
this.rpcSubscriptions.put(requestUUID, toDeviceRpcRequestMsg.getExpirationTime()); |
|
|
this.rpcSubscriptions.put(requestUUID, toDeviceRpcRequestMsg.getExpirationTime()); |
|
|
Lwm2mClientRpcRequest lwm2mClientRpcRequest = null; |
|
|
Lwm2mClientRpcRequest lwm2mClientRpcRequest = null; |
|
|
try { |
|
|
try { |
|
|
Registration registration = clientContext.getClient(sessionInfo).getRegistration(); |
|
|
LwM2mClient client = clientContext.getClientBySessionInfo(sessionInfo); |
|
|
|
|
|
Registration registration = client.getRegistration(); |
|
|
lwm2mClientRpcRequest = new Lwm2mClientRpcRequest(lwM2mTypeOper, bodyParams, toDeviceRpcRequestMsg.getRequestId(), sessionInfo, registration, this); |
|
|
lwm2mClientRpcRequest = new Lwm2mClientRpcRequest(lwM2mTypeOper, bodyParams, toDeviceRpcRequestMsg.getRequestId(), sessionInfo, registration, this); |
|
|
if (lwm2mClientRpcRequest.getErrorMsg() != null) { |
|
|
if (lwm2mClientRpcRequest.getErrorMsg() != null) { |
|
|
lwm2mClientRpcRequest.setResponseCode(BAD_REQUEST.name()); |
|
|
lwm2mClientRpcRequest.setResponseCode(BAD_REQUEST.name()); |
|
|
this.onToDeviceRpcResponse(lwm2mClientRpcRequest.getDeviceRpcResponseResultMsg(), sessionInfo); |
|
|
this.onToDeviceRpcResponse(lwm2mClientRpcRequest.getDeviceRpcResponseResultMsg(), sessionInfo); |
|
|
} else { |
|
|
} else { |
|
|
lwM2mTransportRequest.sendAllRequest(registration, lwm2mClientRpcRequest.getTargetIdVer(), lwm2mClientRpcRequest.getTypeOper(), |
|
|
lwM2mTransportRequest.sendAllRequest(client, lwm2mClientRpcRequest.getTargetIdVer(), lwm2mClientRpcRequest.getTypeOper(), |
|
|
null, |
|
|
null, |
|
|
lwm2mClientRpcRequest.getValue() == null ? lwm2mClientRpcRequest.getParams() : lwm2mClientRpcRequest.getValue(), |
|
|
lwm2mClientRpcRequest.getValue() == null ? lwm2mClientRpcRequest.getParams() : lwm2mClientRpcRequest.getValue(), |
|
|
this.config.getTimeout(), lwm2mClientRpcRequest); |
|
|
this.config.getTimeout(), lwm2mClientRpcRequest); |
|
|
@ -506,7 +514,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onToDeviceRpcResponse(TransportProtos.ToDeviceRpcResponseMsg toDeviceResponse, SessionInfoProto sessionInfo) { |
|
|
public void onToDeviceRpcResponse(TransportProtos.ToDeviceRpcResponseMsg toDeviceResponse, SessionInfoProto sessionInfo) { |
|
|
log.warn ("5) onToDeviceRpcResponse: [{}], sessionUUID: [{}]", toDeviceResponse, new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB())); |
|
|
log.warn("5) onToDeviceRpcResponse: [{}], sessionUUID: [{}]", toDeviceResponse, new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB())); |
|
|
transportService.process(sessionInfo, toDeviceResponse, null); |
|
|
transportService.process(sessionInfo, toDeviceResponse, null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -514,17 +522,6 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
log.info("[{}] toServerRpcResponse", toServerResponse); |
|
|
log.info("[{}] toServerRpcResponse", toServerResponse); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Trigger Server path = "/1/0/8" |
|
|
|
|
|
* <p> |
|
|
|
|
|
* Trigger bootStrap path = "/1/0/9" - have to implemented on client |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public void doTrigger(Registration registration, String path) { |
|
|
|
|
|
lwM2mTransportRequest.sendAllRequest(registration, path, EXECUTE, |
|
|
|
|
|
ContentFormat.TLV.getName(), null, this.config.getTimeout(), null); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Deregister session in transport |
|
|
* Deregister session in transport |
|
|
* |
|
|
* |
|
|
@ -558,7 +555,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
@Override |
|
|
@Override |
|
|
public void onAwakeDev(Registration registration) { |
|
|
public void onAwakeDev(Registration registration) { |
|
|
log.trace("[{}] [{}] Received endpoint Awake version event", registration.getId(), registration.getEndpoint()); |
|
|
log.trace("[{}] [{}] Received endpoint Awake version event", registration.getId(), registration.getEndpoint()); |
|
|
this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client is awake!", registration.getId()); |
|
|
this.sendLogsToThingsboard(clientContext.getClientByEndpoint(registration.getEndpoint()), LOG_LW2M_INFO + ": Client is awake!"); |
|
|
//TODO: associate endpointId with device information.
|
|
|
//TODO: associate endpointId with device information.
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -567,13 +564,17 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
* @param registrationId - Id of Registration LwM2M Client |
|
|
* @param registrationId - Id of Registration LwM2M Client |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public void sendLogsToThingsboard(String logMsg, String registrationId) { |
|
|
public void sendLogsToThingsboard(String registrationId, String logMsg) { |
|
|
SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(registrationId); |
|
|
sendLogsToThingsboard(clientContext.getClientByRegistrationId(registrationId), logMsg); |
|
|
if (logMsg != null && sessionInfo != null) { |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void sendLogsToThingsboard(LwM2mClient client, String logMsg) { |
|
|
|
|
|
if (logMsg != null && client != null && client.getSession() != null) { |
|
|
if (logMsg.length() > 1024) { |
|
|
if (logMsg.length() > 1024) { |
|
|
logMsg = logMsg.substring(0, 1024); |
|
|
logMsg = logMsg.substring(0, 1024); |
|
|
} |
|
|
} |
|
|
this.helper.sendParametersOnThingsboardTelemetry(this.helper.getKvStringtoThingsboard(LOG_LW2M_TELEMETRY, logMsg), sessionInfo); |
|
|
this.helper.sendParametersOnThingsboardTelemetry(this.helper.getKvStringtoThingsboard(LOG_LW2M_TELEMETRY, logMsg), client.getSession()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -586,24 +587,23 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
* - Read Request to the client after registration to read all resource values for all objects |
|
|
* - Read Request to the client after registration to read all resource values for all objects |
|
|
* - then Observe Request to the client marked as observe from the profile configuration. |
|
|
* - then Observe Request to the client marked as observe from the profile configuration. |
|
|
* |
|
|
* |
|
|
* @param registration - Registration LwM2M Client |
|
|
* @param lwM2MClient - object with All parameters off client |
|
|
* @param lwM2MClient - object with All parameters off client |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
private void initLwM2mFromClientValue(Registration registration, LwM2mClient lwM2MClient) { |
|
|
private void initClientTelemetry(LwM2mClient lwM2MClient) { |
|
|
LwM2mClientProfile lwM2MClientProfile = clientContext.getProfile(registration); |
|
|
LwM2mClientProfile lwM2MClientProfile = clientContext.getProfile(lwM2MClient.getProfileId()); |
|
|
Set<String> clientObjects = clientContext.getSupportedIdVerInClient(registration); |
|
|
Set<String> clientObjects = clientContext.getSupportedIdVerInClient(lwM2MClient); |
|
|
if (clientObjects != null && clientObjects.size() > 0) { |
|
|
if (clientObjects != null && clientObjects.size() > 0) { |
|
|
if (LWM2M_STRATEGY_2 == LwM2mTransportUtil.getClientOnlyObserveAfterConnect(lwM2MClientProfile)) { |
|
|
if (LWM2M_STRATEGY_2 == LwM2mTransportUtil.getClientOnlyObserveAfterConnect(lwM2MClientProfile)) { |
|
|
// #2
|
|
|
// #2
|
|
|
lwM2MClient.getPendingReadRequests().addAll(clientObjects); |
|
|
lwM2MClient.getPendingReadRequests().addAll(clientObjects); |
|
|
clientObjects.forEach(path -> lwM2mTransportRequest.sendAllRequest(registration, path, READ, ContentFormat.TLV.getName(), |
|
|
clientObjects.forEach(path -> lwM2mTransportRequest.sendAllRequest(lwM2MClient, path, READ, |
|
|
null, this.config.getTimeout(), null)); |
|
|
null, this.config.getTimeout(), null)); |
|
|
} |
|
|
} |
|
|
// #1
|
|
|
// #1
|
|
|
this.initReadAttrTelemetryObserveToClient(registration, lwM2MClient, READ, clientObjects); |
|
|
this.initReadAttrTelemetryObserveToClient(lwM2MClient, READ, clientObjects); |
|
|
this.initReadAttrTelemetryObserveToClient(registration, lwM2MClient, OBSERVE, clientObjects); |
|
|
this.initReadAttrTelemetryObserveToClient(lwM2MClient, OBSERVE, clientObjects); |
|
|
this.initReadAttrTelemetryObserveToClient(registration, lwM2MClient, WRITE_ATTRIBUTES, clientObjects); |
|
|
this.initReadAttrTelemetryObserveToClient(lwM2MClient, WRITE_ATTRIBUTES, clientObjects); |
|
|
this.initReadAttrTelemetryObserveToClient(registration, lwM2MClient, DISCOVER, clientObjects); |
|
|
this.initReadAttrTelemetryObserveToClient(lwM2MClient, DISCOVER, clientObjects); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -645,7 +645,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
* @param path - resource |
|
|
* @param path - resource |
|
|
*/ |
|
|
*/ |
|
|
private void updateResourcesValue(Registration registration, LwM2mResource lwM2mResource, String path) { |
|
|
private void updateResourcesValue(Registration registration, LwM2mResource lwM2mResource, String path) { |
|
|
LwM2mClient lwM2MClient = clientContext.getOrRegister(registration); |
|
|
LwM2mClient lwM2MClient = clientContext.getClientByEndpoint(registration.getEndpoint()); |
|
|
if (lwM2MClient.saveResourceValue(path, lwM2mResource, this.config.getModelProvider())) { |
|
|
if (lwM2MClient.saveResourceValue(path, lwM2mResource, this.config.getModelProvider())) { |
|
|
/** version != null |
|
|
/** version != null |
|
|
* set setClient_fw_info... = value |
|
|
* set setClient_fw_info... = value |
|
|
@ -740,15 +740,8 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
private void initReadAttrTelemetryObserveToClient(LwM2mClient lwM2MClient, LwM2mTypeOper typeOper, Set<String> clientObjects) { |
|
|
* Start observe/read: Attr/Telemetry |
|
|
LwM2mClientProfile lwM2MClientProfile = clientContext.getProfile(lwM2MClient.getProfileId()); |
|
|
* #1 - Analyze: path in resource profile == client resource |
|
|
|
|
|
* |
|
|
|
|
|
* @param registration - |
|
|
|
|
|
*/ |
|
|
|
|
|
private void initReadAttrTelemetryObserveToClient(Registration registration, LwM2mClient lwM2MClient, |
|
|
|
|
|
LwM2mTypeOper typeOper, Set<String> clientObjects) { |
|
|
|
|
|
LwM2mClientProfile lwM2MClientProfile = clientContext.getProfile(registration); |
|
|
|
|
|
Set<String> result = null; |
|
|
Set<String> result = null; |
|
|
ConcurrentHashMap<String, Object> params = null; |
|
|
ConcurrentHashMap<String, Object> params = null; |
|
|
if (READ.equals(typeOper)) { |
|
|
if (READ.equals(typeOper)) { |
|
|
@ -768,28 +761,42 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
params = this.getPathForWriteAttributes(lwM2MClientProfile.getPostAttributeLwm2mProfile()); |
|
|
params = this.getPathForWriteAttributes(lwM2MClientProfile.getPostAttributeLwm2mProfile()); |
|
|
result = params.keySet(); |
|
|
result = params.keySet(); |
|
|
} |
|
|
} |
|
|
if (result != null && !result.isEmpty()) { |
|
|
sendRequestsToClient(lwM2MClient, typeOper, clientObjects, result, params); |
|
|
// #1
|
|
|
} |
|
|
Set<String> pathSend = result.stream().filter(target -> { |
|
|
|
|
|
return target.split(LWM2M_SEPARATOR_PATH).length < 3 ? |
|
|
private void sendRequestsToClient(LwM2mClient lwM2MClient, LwM2mTypeOper operationType, Set<String> supportedObjectIds, Set<String> desiredObjectIds, ConcurrentHashMap<String, Object> params) { |
|
|
clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1]) : |
|
|
if (desiredObjectIds != null && !desiredObjectIds.isEmpty()) { |
|
|
clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1] + "/" + target.split(LWM2M_SEPARATOR_PATH)[2]); |
|
|
Set<String> targetObjectIds = desiredObjectIds.stream().filter(target -> isSupportedTargetId(supportedObjectIds, target) |
|
|
} |
|
|
|
|
|
).collect(Collectors.toUnmodifiableSet()); |
|
|
).collect(Collectors.toUnmodifiableSet()); |
|
|
if (!pathSend.isEmpty()) { |
|
|
if (!targetObjectIds.isEmpty()) { |
|
|
lwM2MClient.getPendingReadRequests().addAll(pathSend); |
|
|
//TODO: remove this side effect?
|
|
|
ConcurrentHashMap<String, Object> finalParams = params; |
|
|
lwM2MClient.getPendingReadRequests().addAll(targetObjectIds); |
|
|
pathSend.forEach(target -> { |
|
|
targetObjectIds.forEach(target -> { |
|
|
lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, ContentFormat.TLV.getName(), |
|
|
Object additionalParams = params != null ? params.get(target) : null; |
|
|
finalParams != null ? finalParams.get(target) : null, this.config.getTimeout(), null); |
|
|
lwM2mTransportRequest.sendAllRequest(lwM2MClient, target, operationType, additionalParams, this.config.getTimeout(), null); |
|
|
}); |
|
|
}); |
|
|
if (OBSERVE.equals(typeOper)) { |
|
|
if (OBSERVE.equals(operationType)) { |
|
|
lwM2MClient.initReadValue(this, null); |
|
|
lwM2MClient.initReadValue(this, null); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean isSupportedTargetId(Set<String> supportedIds, String targetId) { |
|
|
|
|
|
String[] targetIdParts = targetId.split(LWM2M_SEPARATOR_PATH); |
|
|
|
|
|
if (targetIdParts.length <= 1) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
String targetIdSearch = targetIdParts[0]; |
|
|
|
|
|
for (int i = 1; i < targetIdParts.length; i++) { |
|
|
|
|
|
targetIdSearch += "/" + targetIdParts[i]; |
|
|
|
|
|
if (supportedIds.contains(targetIdSearch)) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private ConcurrentHashMap<String, Object> getPathForWriteAttributes(JsonObject objectJson) { |
|
|
private ConcurrentHashMap<String, Object> getPathForWriteAttributes(JsonObject objectJson) { |
|
|
ConcurrentHashMap<String, Object> pathAttributes = new Gson().fromJson(objectJson.toString(), |
|
|
ConcurrentHashMap<String, Object> pathAttributes = new Gson().fromJson(objectJson.toString(), |
|
|
new TypeToken<ConcurrentHashMap<String, Object>>() { |
|
|
new TypeToken<ConcurrentHashMap<String, Object>>() { |
|
|
@ -798,7 +805,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void onDeviceUpdate(LwM2mClient lwM2MClient, Device device, Optional<DeviceProfile> deviceProfileOpt) { |
|
|
private void onDeviceUpdate(LwM2mClient lwM2MClient, Device device, Optional<DeviceProfile> deviceProfileOpt) { |
|
|
deviceProfileOpt.ifPresent(deviceProfile -> this.onDeviceProfileUpdate(Collections.singleton(lwM2MClient.getRegistration().getId()), deviceProfile)); |
|
|
deviceProfileOpt.ifPresent(deviceProfile -> this.onDeviceProfileUpdate(Collections.singletonList(lwM2MClient), deviceProfile)); |
|
|
lwM2MClient.onDeviceUpdate(device, deviceProfileOpt); |
|
|
lwM2MClient.onDeviceUpdate(device, deviceProfileOpt); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -843,7 +850,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private TransportProtos.KeyValueProto getKvToThingsboard(String pathIdVer, Registration registration) { |
|
|
private TransportProtos.KeyValueProto getKvToThingsboard(String pathIdVer, Registration registration) { |
|
|
LwM2mClient lwM2MClient = this.clientContext.getClientByRegistrationId(registration.getId()); |
|
|
LwM2mClient lwM2MClient = this.clientContext.getClientByEndpoint(registration.getEndpoint()); |
|
|
JsonObject names = clientContext.getProfiles().get(lwM2MClient.getProfileId()).getPostKeyNameProfile(); |
|
|
JsonObject names = clientContext.getProfiles().get(lwM2MClient.getProfileId()).getPostKeyNameProfile(); |
|
|
if (names != null && names.has(pathIdVer)) { |
|
|
if (names != null && names.has(pathIdVer)) { |
|
|
String resourceName = names.get(pathIdVer).getAsString(); |
|
|
String resourceName = names.get(pathIdVer).getAsString(); |
|
|
@ -858,7 +865,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
valueKvProto = new JsonObject(); |
|
|
valueKvProto = new JsonObject(); |
|
|
Object finalvalueKvProto = valueKvProto; |
|
|
Object finalvalueKvProto = valueKvProto; |
|
|
Gson gson = new GsonBuilder().create(); |
|
|
Gson gson = new GsonBuilder().create(); |
|
|
resourceValue.getValues().forEach((k, v) -> { |
|
|
resourceValue.getInstances().forEach((k, v) -> { |
|
|
Object val = this.converter.convertValue(v, currentType, expectedType, |
|
|
Object val = this.converter.convertValue(v, currentType, expectedType, |
|
|
new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer))); |
|
|
new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer))); |
|
|
JsonElement element = gson.toJsonTree(val, val.getClass()); |
|
|
JsonElement element = gson.toJsonTree(val, val.getClass()); |
|
|
@ -892,9 +899,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
ResourceModel.Type expectedType = this.helper.getResourceModelTypeEqualsKvProtoValueType(currentType, pathIdVer); |
|
|
ResourceModel.Type expectedType = this.helper.getResourceModelTypeEqualsKvProtoValueType(currentType, pathIdVer); |
|
|
return this.converter.convertValue(resourceValue.getValue(), currentType, expectedType, |
|
|
return this.converter.convertValue(resourceValue.getValue(), currentType, expectedType, |
|
|
new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer))); |
|
|
new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer))); |
|
|
} |
|
|
} else { |
|
|
|
|
|
|
|
|
else { |
|
|
|
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -955,10 +960,10 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
* #6.1 - update WriteAttribute |
|
|
* #6.1 - update WriteAttribute |
|
|
* #6.2 - del WriteAttribute |
|
|
* #6.2 - del WriteAttribute |
|
|
* |
|
|
* |
|
|
* @param registrationIds - |
|
|
* @param clients - |
|
|
* @param deviceProfile - |
|
|
* @param deviceProfile - |
|
|
*/ |
|
|
*/ |
|
|
private void onDeviceProfileUpdate(Set<String> registrationIds, DeviceProfile deviceProfile) { |
|
|
private void onDeviceProfileUpdate(List<LwM2mClient> clients, DeviceProfile deviceProfile) { |
|
|
LwM2mClientProfile lwM2MClientProfileOld = clientContext.getProfiles().get(deviceProfile.getUuidId()).clone(); |
|
|
LwM2mClientProfile lwM2MClientProfileOld = clientContext.getProfiles().get(deviceProfile.getUuidId()).clone(); |
|
|
if (clientContext.profileUpdate(deviceProfile) != null) { |
|
|
if (clientContext.profileUpdate(deviceProfile) != null) { |
|
|
// #1
|
|
|
// #1
|
|
|
@ -1009,15 +1014,14 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
|
|
|
|
|
|
// #3.4, #6
|
|
|
// #3.4, #6
|
|
|
if (!attributeLwm2mOld.equals(attributeLwm2mNew)) { |
|
|
if (!attributeLwm2mOld.equals(attributeLwm2mNew)) { |
|
|
this.getAnalyzerAttributeLwm2m(registrationIds, attributeLwm2mOld, attributeLwm2mNew); |
|
|
this.getAnalyzerAttributeLwm2m(clients, attributeLwm2mOld, attributeLwm2mNew); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// #4.1 add
|
|
|
// #4.1 add
|
|
|
if (sendAttrToThingsboard.getPathPostParametersAdd().size() > 0) { |
|
|
if (sendAttrToThingsboard.getPathPostParametersAdd().size() > 0) { |
|
|
// update value in Resources
|
|
|
// update value in Resources
|
|
|
registrationIds.forEach(registrationId -> { |
|
|
clients.forEach(client -> { |
|
|
Registration registration = clientContext.getRegistration(registrationId); |
|
|
this.readObserveFromProfile(client, sendAttrToThingsboard.getPathPostParametersAdd(), READ); |
|
|
this.readObserveFromProfile(registration, sendAttrToThingsboard.getPathPostParametersAdd(), READ); |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
// #4.2 del
|
|
|
// #4.2 del
|
|
|
@ -1041,15 +1045,15 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
// does not include oldObserve
|
|
|
// does not include oldObserve
|
|
|
ResultsAnalyzerParameters postObserveAnalyzer = this.getAnalyzerParameters(sendObserveToClientOld.getPathPostParametersAdd(), sendObserveToClientNew.getPathPostParametersAdd()); |
|
|
ResultsAnalyzerParameters postObserveAnalyzer = this.getAnalyzerParameters(sendObserveToClientOld.getPathPostParametersAdd(), sendObserveToClientNew.getPathPostParametersAdd()); |
|
|
// send Request observe to Client
|
|
|
// send Request observe to Client
|
|
|
registrationIds.forEach(registrationId -> { |
|
|
clients.forEach(client -> { |
|
|
Registration registration = clientContext.getRegistration(registrationId); |
|
|
Registration registration = client.getRegistration(); |
|
|
if (postObserveAnalyzer.getPathPostParametersAdd().size() > 0) { |
|
|
if (postObserveAnalyzer.getPathPostParametersAdd().size() > 0) { |
|
|
this.readObserveFromProfile(registration, postObserveAnalyzer.getPathPostParametersAdd(), OBSERVE); |
|
|
this.readObserveFromProfile(client, postObserveAnalyzer.getPathPostParametersAdd(), OBSERVE); |
|
|
} |
|
|
} |
|
|
// 5.3 del
|
|
|
// 5.3 del
|
|
|
// send Request cancel observe to Client
|
|
|
// send Request cancel observe to Client
|
|
|
if (postObserveAnalyzer.getPathPostParametersDel().size() > 0) { |
|
|
if (postObserveAnalyzer.getPathPostParametersDel().size() > 0) { |
|
|
this.cancelObserveFromProfile(registration, postObserveAnalyzer.getPathPostParametersDel()); |
|
|
this.cancelObserveFromProfile(client, postObserveAnalyzer.getPathPostParametersDel()); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
@ -1086,19 +1090,18 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
* Update Resource value after change RezAttrTelemetry in config Profile |
|
|
* Update Resource value after change RezAttrTelemetry in config Profile |
|
|
* send response Read to Client and add path to pathResAttrTelemetry in LwM2MClient.getAttrTelemetryObserveValue() |
|
|
* send response Read to Client and add path to pathResAttrTelemetry in LwM2MClient.getAttrTelemetryObserveValue() |
|
|
* |
|
|
* |
|
|
* @param registration - Registration LwM2M Client |
|
|
* @param targets - path Resources == [ "/2/0/0", "/2/0/1"] |
|
|
* @param targets - path Resources == [ "/2/0/0", "/2/0/1"] |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
private void readObserveFromProfile(Registration registration, Set<String> targets, LwM2mTypeOper typeOper) { |
|
|
private void readObserveFromProfile(LwM2mClient client, Set<String> targets, LwM2mTypeOper typeOper) { |
|
|
targets.forEach(target -> { |
|
|
targets.forEach(target -> { |
|
|
LwM2mPath pathIds = new LwM2mPath(convertPathFromIdVerToObjectId(target)); |
|
|
LwM2mPath pathIds = new LwM2mPath(convertPathFromIdVerToObjectId(target)); |
|
|
if (pathIds.isResource()) { |
|
|
if (pathIds.isResource()) { |
|
|
if (READ.equals(typeOper)) { |
|
|
if (READ.equals(typeOper)) { |
|
|
lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, |
|
|
lwM2mTransportRequest.sendAllRequest(client, target, typeOper, |
|
|
ContentFormat.TLV.getName(), null, this.config.getTimeout(), null); |
|
|
null, this.config.getTimeout(), null); |
|
|
} else if (OBSERVE.equals(typeOper)) { |
|
|
} else if (OBSERVE.equals(typeOper)) { |
|
|
lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, |
|
|
lwM2mTransportRequest.sendAllRequest(client, target, typeOper, |
|
|
null, null, this.config.getTimeout(), null); |
|
|
null, this.config.getTimeout(), null); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
@ -1124,7 +1127,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
* @param attributeLwm2mNew - |
|
|
* @param attributeLwm2mNew - |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
private void getAnalyzerAttributeLwm2m(Set<String> registrationIds, JsonObject attributeLwm2mOld, JsonObject attributeLwm2mNew) { |
|
|
private void getAnalyzerAttributeLwm2m(List<LwM2mClient> clients, JsonObject attributeLwm2mOld, JsonObject attributeLwm2mNew) { |
|
|
ResultsAnalyzerParameters analyzerParameters = new ResultsAnalyzerParameters(); |
|
|
ResultsAnalyzerParameters analyzerParameters = new ResultsAnalyzerParameters(); |
|
|
ConcurrentHashMap<String, Object> lwm2mAttributesOld = new Gson().fromJson(attributeLwm2mOld.toString(), |
|
|
ConcurrentHashMap<String, Object> lwm2mAttributesOld = new Gson().fromJson(attributeLwm2mOld.toString(), |
|
|
new TypeToken<ConcurrentHashMap<String, Object>>() { |
|
|
new TypeToken<ConcurrentHashMap<String, Object>>() { |
|
|
@ -1146,23 +1149,22 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
// #6
|
|
|
// #6
|
|
|
// #6.2
|
|
|
// #6.2
|
|
|
if (analyzerParameters.getPathPostParametersAdd().size() > 0) { |
|
|
if (analyzerParameters.getPathPostParametersAdd().size() > 0) { |
|
|
registrationIds.forEach(registrationId -> { |
|
|
clients.forEach(client -> { |
|
|
Registration registration = this.clientContext.getRegistration(registrationId); |
|
|
Set<String> clientObjects = clientContext.getSupportedIdVerInClient(client); |
|
|
Set<String> clientObjects = clientContext.getSupportedIdVerInClient(registration); |
|
|
|
|
|
Set<String> pathSend = analyzerParameters.getPathPostParametersAdd().stream().filter(target -> clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1])) |
|
|
Set<String> pathSend = analyzerParameters.getPathPostParametersAdd().stream().filter(target -> clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1])) |
|
|
.collect(Collectors.toUnmodifiableSet()); |
|
|
.collect(Collectors.toUnmodifiableSet()); |
|
|
if (!pathSend.isEmpty()) { |
|
|
if (!pathSend.isEmpty()) { |
|
|
ConcurrentHashMap<String, Object> finalParams = lwm2mAttributesNew; |
|
|
ConcurrentHashMap<String, Object> finalParams = lwm2mAttributesNew; |
|
|
pathSend.forEach(target -> lwM2mTransportRequest.sendAllRequest(registration, target, WRITE_ATTRIBUTES, ContentFormat.TLV.getName(), |
|
|
pathSend.forEach(target -> lwM2mTransportRequest.sendAllRequest(client, target, WRITE_ATTRIBUTES, |
|
|
finalParams.get(target), this.config.getTimeout(), null)); |
|
|
finalParams.get(target), this.config.getTimeout(), null)); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
// #6.2
|
|
|
// #6.2
|
|
|
if (analyzerParameters.getPathPostParametersDel().size() > 0) { |
|
|
if (analyzerParameters.getPathPostParametersDel().size() > 0) { |
|
|
registrationIds.forEach(registrationId -> { |
|
|
clients.forEach(client -> { |
|
|
Registration registration = this.clientContext.getRegistration(registrationId); |
|
|
Registration registration = client.getRegistration(); |
|
|
Set<String> clientObjects = clientContext.getSupportedIdVerInClient(registration); |
|
|
Set<String> clientObjects = clientContext.getSupportedIdVerInClient(client); |
|
|
Set<String> pathSend = analyzerParameters.getPathPostParametersDel().stream().filter(target -> clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1])) |
|
|
Set<String> pathSend = analyzerParameters.getPathPostParametersDel().stream().filter(target -> clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1])) |
|
|
.collect(Collectors.toUnmodifiableSet()); |
|
|
.collect(Collectors.toUnmodifiableSet()); |
|
|
if (!pathSend.isEmpty()) { |
|
|
if (!pathSend.isEmpty()) { |
|
|
@ -1170,8 +1172,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
Map<String, Object> params = (Map<String, Object>) lwm2mAttributesOld.get(target); |
|
|
Map<String, Object> params = (Map<String, Object>) lwm2mAttributesOld.get(target); |
|
|
params.clear(); |
|
|
params.clear(); |
|
|
params.put(OBJECT_VERSION, ""); |
|
|
params.put(OBJECT_VERSION, ""); |
|
|
lwM2mTransportRequest.sendAllRequest(registration, target, WRITE_ATTRIBUTES, ContentFormat.TLV.getName(), |
|
|
lwM2mTransportRequest.sendAllRequest(client, target, WRITE_ATTRIBUTES, params, this.config.getTimeout(), null); |
|
|
params, this.config.getTimeout(), null); |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
@ -1179,12 +1180,10 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void cancelObserveFromProfile(Registration registration, Set<String> paramAnallyzer) { |
|
|
private void cancelObserveFromProfile(LwM2mClient lwM2mClient, Set<String> paramAnallyzer) { |
|
|
LwM2mClient lwM2MClient = clientContext.getOrRegister(registration); |
|
|
|
|
|
paramAnallyzer.forEach(pathIdVer -> { |
|
|
paramAnallyzer.forEach(pathIdVer -> { |
|
|
if (this.getResourceValueFromLwM2MClient(lwM2MClient, pathIdVer) != null) { |
|
|
if (this.getResourceValueFromLwM2MClient(lwM2mClient, pathIdVer) != null) { |
|
|
lwM2mTransportRequest.sendAllRequest(registration, pathIdVer, OBSERVE_CANCEL, null, |
|
|
lwM2mTransportRequest.sendAllRequest(lwM2mClient, pathIdVer, OBSERVE_CANCEL, null, this.config.getTimeout(), null); |
|
|
null, this.config.getTimeout(), null); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
); |
|
|
); |
|
|
@ -1192,14 +1191,12 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
|
|
|
|
|
|
private void updateResourcesValueToClient(LwM2mClient lwM2MClient, Object valueOld, Object valueNew, String path) { |
|
|
private void updateResourcesValueToClient(LwM2mClient lwM2MClient, Object valueOld, Object valueNew, String path) { |
|
|
if (valueNew != null && (valueOld == null || !valueNew.toString().equals(valueOld.toString()))) { |
|
|
if (valueNew != null && (valueOld == null || !valueNew.toString().equals(valueOld.toString()))) { |
|
|
lwM2mTransportRequest.sendAllRequest(lwM2MClient.getRegistration(), path, WRITE_REPLACE, |
|
|
lwM2mTransportRequest.sendAllRequest(lwM2MClient, path, WRITE_REPLACE, valueNew, this.config.getTimeout(), null); |
|
|
ContentFormat.TLV.getName(), valueNew, |
|
|
|
|
|
this.config.getTimeout(), null); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
log.error("Failed update resource [{}] [{}]", path, valueNew); |
|
|
log.error("Failed update resource [{}] [{}]", path, valueNew); |
|
|
String logMsg = String.format("%s: Failed update resource path - %s value - %s. Value is not changed or bad", |
|
|
String logMsg = String.format("%s: Failed update resource path - %s value - %s. Value is not changed or bad", |
|
|
LOG_LW2M_ERROR, path, valueNew); |
|
|
LOG_LW2M_ERROR, path, valueNew); |
|
|
this.sendLogsToThingsboard(logMsg, lwM2MClient.getRegistration().getId()); |
|
|
this.sendLogsToThingsboard(lwM2MClient, logMsg); |
|
|
log.info("Failed update resource [{}] [{}]", path, valueNew); |
|
|
log.info("Failed update resource [{}] [{}]", path, valueNew); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -1221,7 +1218,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
*/ |
|
|
*/ |
|
|
public String getPresentPathIntoProfile(TransportProtos.SessionInfoProto sessionInfo, String name) { |
|
|
public String getPresentPathIntoProfile(TransportProtos.SessionInfoProto sessionInfo, String name) { |
|
|
LwM2mClientProfile profile = clientContext.getProfile(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB())); |
|
|
LwM2mClientProfile profile = clientContext.getProfile(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB())); |
|
|
LwM2mClient lwM2mClient = clientContext.getClient(sessionInfo); |
|
|
LwM2mClient lwM2mClient = clientContext.getClientBySessionInfo(sessionInfo); |
|
|
return profile.getPostKeyNameProfile().getAsJsonObject().entrySet().stream() |
|
|
return profile.getPostKeyNameProfile().getAsJsonObject().entrySet().stream() |
|
|
.filter(e -> e.getValue().getAsString().equals(name) && validateResourceInModel(lwM2mClient, e.getKey(), false)).findFirst().map(Map.Entry::getKey) |
|
|
.filter(e -> e.getValue().getAsString().equals(name) && validateResourceInModel(lwM2mClient, e.getKey(), false)).findFirst().map(Map.Entry::getKey) |
|
|
.orElse(null); |
|
|
.orElse(null); |
|
|
@ -1256,7 +1253,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
* @param sessionInfo |
|
|
* @param sessionInfo |
|
|
*/ |
|
|
*/ |
|
|
public void updateAttributeFromThingsboard(List<TransportProtos.TsKvProto> tsKvProtos, TransportProtos.SessionInfoProto sessionInfo) { |
|
|
public void updateAttributeFromThingsboard(List<TransportProtos.TsKvProto> tsKvProtos, TransportProtos.SessionInfoProto sessionInfo) { |
|
|
LwM2mClient lwM2MClient = clientContext.getClient(sessionInfo); |
|
|
LwM2mClient lwM2MClient = clientContext.getClientBySessionInfo(sessionInfo); |
|
|
if (lwM2MClient != null) { |
|
|
if (lwM2MClient != null) { |
|
|
log.warn("1) UpdateAttributeFromThingsboard, tsKvProtos [{}]", tsKvProtos); |
|
|
log.warn("1) UpdateAttributeFromThingsboard, tsKvProtos [{}]", tsKvProtos); |
|
|
tsKvProtos.forEach(tsKvProto -> { |
|
|
tsKvProtos.forEach(tsKvProto -> { |
|
|
@ -1275,8 +1272,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
this.updateResourcesValueToClient(lwM2MClient, this.getResourceValueFormatKv(lwM2MClient, pathIdVer), |
|
|
this.updateResourcesValueToClient(lwM2MClient, this.getResourceValueFormatKv(lwM2MClient, pathIdVer), |
|
|
getValueFromKvProto(tsKvProto.getKv()), pathIdVer); |
|
|
getValueFromKvProto(tsKvProto.getKv()), pathIdVer); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} else { |
|
|
else { |
|
|
|
|
|
log.error("UpdateAttributeFromThingsboard, lwM2MClient is null"); |
|
|
log.error("UpdateAttributeFromThingsboard, lwM2MClient is null"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -1285,14 +1281,9 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
* @param lwM2MClient - |
|
|
* @param lwM2MClient - |
|
|
* @return SessionInfoProto - |
|
|
* @return SessionInfoProto - |
|
|
*/ |
|
|
*/ |
|
|
private SessionInfoProto getSessionInfoOrCloseSession(LwM2mClient lwM2MClient) { |
|
|
private SessionInfoProto getSessionInfo(LwM2mClient lwM2MClient) { |
|
|
if (lwM2MClient != null) { |
|
|
if (lwM2MClient != null && lwM2MClient.getSession() != null) { |
|
|
SessionInfoProto sessionInfoProto = lwM2MClient.getSession(); |
|
|
return lwM2MClient.getSession(); |
|
|
if (sessionInfoProto == null) { |
|
|
|
|
|
log.info("[{}] [{}]", lwM2MClient.getEndpoint(), CLIENT_NOT_AUTHORIZED); |
|
|
|
|
|
this.closeClientSession(lwM2MClient.getRegistration()); |
|
|
|
|
|
} |
|
|
|
|
|
return sessionInfoProto; |
|
|
|
|
|
} |
|
|
} |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
@ -1302,15 +1293,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
* @return - sessionInfo after access connect client |
|
|
* @return - sessionInfo after access connect client |
|
|
*/ |
|
|
*/ |
|
|
public SessionInfoProto getSessionInfoOrCloseSession(Registration registration) { |
|
|
public SessionInfoProto getSessionInfoOrCloseSession(Registration registration) { |
|
|
return getSessionInfoOrCloseSession(clientContext.getOrRegister(registration)); |
|
|
return getSessionInfo(clientContext.getClientByEndpoint(registration.getEndpoint())); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @param registrationId - |
|
|
|
|
|
* @return - |
|
|
|
|
|
*/ |
|
|
|
|
|
private SessionInfoProto getSessionInfoOrCloseSession(String registrationId) { |
|
|
|
|
|
return getSessionInfoOrCloseSession(clientContext.getClientByRegistrationId(registrationId)); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -1340,7 +1323,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
* @param lwM2MClient - LwM2M Client |
|
|
* @param lwM2MClient - LwM2M Client |
|
|
*/ |
|
|
*/ |
|
|
public void putDelayedUpdateResourcesThingsboard(LwM2mClient lwM2MClient) { |
|
|
public void putDelayedUpdateResourcesThingsboard(LwM2mClient lwM2MClient) { |
|
|
SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient); |
|
|
SessionInfoProto sessionInfo = this.getSessionInfo(lwM2MClient); |
|
|
if (sessionInfo != null) { |
|
|
if (sessionInfo != null) { |
|
|
//#1.1
|
|
|
//#1.1
|
|
|
ConcurrentMap<String, String> keyNamesMap = this.getNamesFromProfileForSharedAttributes(lwM2MClient); |
|
|
ConcurrentMap<String, String> keyNamesMap = this.getNamesFromProfileForSharedAttributes(lwM2MClient); |
|
|
@ -1359,7 +1342,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
|
|
|
|
|
|
public void getInfoFirmwareUpdate(LwM2mClient lwM2MClient, Lwm2mClientRpcRequest rpcRequest) { |
|
|
public void getInfoFirmwareUpdate(LwM2mClient lwM2MClient, Lwm2mClientRpcRequest rpcRequest) { |
|
|
if (lwM2MClient.getRegistration().getSupportedVersion(FW_ID) != null) { |
|
|
if (lwM2MClient.getRegistration().getSupportedVersion(FW_ID) != null) { |
|
|
SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient); |
|
|
SessionInfoProto sessionInfo = this.getSessionInfo(lwM2MClient); |
|
|
if (sessionInfo != null) { |
|
|
if (sessionInfo != null) { |
|
|
DefaultLwM2MTransportMsgHandler handler = this; |
|
|
DefaultLwM2MTransportMsgHandler handler = this; |
|
|
this.transportService.process(sessionInfo, createOtaPackageRequestMsg(sessionInfo, OtaPackageType.FIRMWARE.name()), |
|
|
this.transportService.process(sessionInfo, createOtaPackageRequestMsg(sessionInfo, OtaPackageType.FIRMWARE.name()), |
|
|
@ -1368,16 +1351,15 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
public void onSuccess(TransportProtos.GetOtaPackageResponseMsg response) { |
|
|
public void onSuccess(TransportProtos.GetOtaPackageResponseMsg response) { |
|
|
if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus()) |
|
|
if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus()) |
|
|
&& response.getType().equals(OtaPackageType.FIRMWARE.name())) { |
|
|
&& response.getType().equals(OtaPackageType.FIRMWARE.name())) { |
|
|
log.warn ("7) firmware start with ver: [{}]", response.getVersion()); |
|
|
log.warn("7) firmware start with ver: [{}]", response.getVersion()); |
|
|
lwM2MClient.getFwUpdate().setRpcRequest(rpcRequest); |
|
|
lwM2MClient.getFwUpdate().setRpcRequest(rpcRequest); |
|
|
lwM2MClient.getFwUpdate().setCurrentVersion(response.getVersion()); |
|
|
lwM2MClient.getFwUpdate().setCurrentVersion(response.getVersion()); |
|
|
lwM2MClient.getFwUpdate().setCurrentTitle(response.getTitle()); |
|
|
lwM2MClient.getFwUpdate().setCurrentTitle(response.getTitle()); |
|
|
lwM2MClient.getFwUpdate().setCurrentId(new OtaPackageId(new UUID(response.getOtaPackageIdMSB(), response.getOtaPackageIdLSB())).getId()); |
|
|
lwM2MClient.getFwUpdate().setCurrentId(new OtaPackageId(new UUID(response.getOtaPackageIdMSB(), response.getOtaPackageIdLSB())).getId()); |
|
|
if (rpcRequest == null) { |
|
|
if (rpcRequest == null) { |
|
|
lwM2MClient.getFwUpdate().sendReadObserveInfo(lwM2mTransportRequest); |
|
|
lwM2MClient.getFwUpdate().sendReadObserveInfo(lwM2mTransportRequest); |
|
|
} |
|
|
} else { |
|
|
else { |
|
|
lwM2MClient.getFwUpdate().writeFwSwWare(handler, lwM2mTransportRequest); |
|
|
lwM2MClient.getFwUpdate().writeFwSwWare(handler, lwM2mTransportRequest); |
|
|
|
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
log.trace("OtaPackage [{}] [{}]", lwM2MClient.getDeviceName(), response.getResponseStatus().toString()); |
|
|
log.trace("OtaPackage [{}] [{}]", lwM2MClient.getDeviceName(), response.getResponseStatus().toString()); |
|
|
@ -1395,7 +1377,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
|
|
|
|
|
|
public void getInfoSoftwareUpdate(LwM2mClient lwM2MClient, Lwm2mClientRpcRequest rpcRequest) { |
|
|
public void getInfoSoftwareUpdate(LwM2mClient lwM2MClient, Lwm2mClientRpcRequest rpcRequest) { |
|
|
if (lwM2MClient.getRegistration().getSupportedVersion(SW_ID) != null) { |
|
|
if (lwM2MClient.getRegistration().getSupportedVersion(SW_ID) != null) { |
|
|
SessionInfoProto sessionInfo = this.getSessionInfoOrCloseSession(lwM2MClient); |
|
|
SessionInfoProto sessionInfo = this.getSessionInfo(lwM2MClient); |
|
|
if (sessionInfo != null) { |
|
|
if (sessionInfo != null) { |
|
|
DefaultLwM2MTransportMsgHandler handler = this; |
|
|
DefaultLwM2MTransportMsgHandler handler = this; |
|
|
transportService.process(sessionInfo, createOtaPackageRequestMsg(sessionInfo, OtaPackageType.SOFTWARE.name()), |
|
|
transportService.process(sessionInfo, createOtaPackageRequestMsg(sessionInfo, OtaPackageType.SOFTWARE.name()), |
|
|
@ -1411,9 +1393,8 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
lwM2MClient.getSwUpdate().sendReadObserveInfo(lwM2mTransportRequest); |
|
|
lwM2MClient.getSwUpdate().sendReadObserveInfo(lwM2mTransportRequest); |
|
|
if (rpcRequest == null) { |
|
|
if (rpcRequest == null) { |
|
|
lwM2MClient.getSwUpdate().sendReadObserveInfo(lwM2mTransportRequest); |
|
|
lwM2MClient.getSwUpdate().sendReadObserveInfo(lwM2mTransportRequest); |
|
|
} |
|
|
} else { |
|
|
else { |
|
|
lwM2MClient.getSwUpdate().writeFwSwWare(handler, lwM2mTransportRequest); |
|
|
lwM2MClient.getSwUpdate().writeFwSwWare(handler, lwM2mTransportRequest); |
|
|
|
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
log.trace("Software [{}] [{}]", lwM2MClient.getDeviceName(), response.getResponseStatus().toString()); |
|
|
log.trace("Software [{}] [{}]", lwM2MClient.getDeviceName(), response.getResponseStatus().toString()); |
|
|
|