|
|
|
@ -24,10 +24,12 @@ import com.google.gson.JsonObject; |
|
|
|
import com.google.gson.reflect.TypeToken; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.eclipse.leshan.core.model.ResourceModel; |
|
|
|
import org.eclipse.leshan.core.node.LwM2mMultipleResource; |
|
|
|
import org.eclipse.leshan.core.node.LwM2mObject; |
|
|
|
import org.eclipse.leshan.core.node.LwM2mObjectInstance; |
|
|
|
import org.eclipse.leshan.core.node.LwM2mPath; |
|
|
|
import org.eclipse.leshan.core.node.LwM2mResource; |
|
|
|
import org.eclipse.leshan.core.node.LwM2mSingleResource; |
|
|
|
import org.eclipse.leshan.core.observation.Observation; |
|
|
|
import org.eclipse.leshan.core.request.ContentFormat; |
|
|
|
import org.eclipse.leshan.core.request.WriteRequest; |
|
|
|
@ -54,6 +56,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.SessionEvent; |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto; |
|
|
|
import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; |
|
|
|
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; |
|
|
|
import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper; |
|
|
|
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.LwM2mClientProfile; |
|
|
|
@ -92,7 +95,6 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandle |
|
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_INFO; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_VALUE; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LWM2M_STRATEGY_2; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.DISCOVER; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.EXECUTE; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.OBSERVE; |
|
|
|
@ -294,23 +296,31 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
|
@Override |
|
|
|
public void onUpdateValueAfterReadResponse(Registration registration, String path, ReadResponse response, Lwm2mClientRpcRequest rpcRequest) { |
|
|
|
if (response.getContent() != null) { |
|
|
|
Object value = null; |
|
|
|
if (response.getContent() instanceof LwM2mObject) { |
|
|
|
LwM2mObject lwM2mObject = (LwM2mObject) response.getContent(); |
|
|
|
if (rpcRequest != null) { |
|
|
|
value = lwM2mObject.toString(); |
|
|
|
} |
|
|
|
this.updateObjectResourceValue(registration, lwM2mObject, path); |
|
|
|
} else if (response.getContent() instanceof LwM2mObjectInstance) { |
|
|
|
LwM2mObjectInstance lwM2mObjectInstance = (LwM2mObjectInstance) response.getContent(); |
|
|
|
if (rpcRequest != null) { |
|
|
|
value = lwM2mObjectInstance.toString(); |
|
|
|
} |
|
|
|
this.updateObjectInstanceResourceValue(registration, lwM2mObjectInstance, path); |
|
|
|
} else if (response.getContent() instanceof LwM2mResource) { |
|
|
|
LwM2mResource lwM2mResource = (LwM2mResource) response.getContent(); |
|
|
|
if (rpcRequest != null) { |
|
|
|
Object valueResp = lwM2mResource.isMultiInstances() ? lwM2mResource.getValues() : lwM2mResource.getValue(); |
|
|
|
Object value = this.converter.convertValue(valueResp, lwM2mResource.getType(), ResourceModel.Type.STRING, |
|
|
|
new LwM2mPath(convertPathFromIdVerToObjectId(path))); |
|
|
|
rpcRequest.setValueMsg(String.format("%s", value)); |
|
|
|
this.sentRpcRequest(rpcRequest, response.getCode().getName(), (String) value, LOG_LW2M_VALUE); |
|
|
|
value = lwM2mResource.isMultiInstances() ? ((LwM2mMultipleResource) lwM2mResource).toString() : |
|
|
|
((LwM2mSingleResource) lwM2mResource).toString(); |
|
|
|
} |
|
|
|
this.updateResourcesValue(registration, lwM2mResource, path); |
|
|
|
} |
|
|
|
if (rpcRequest != null) { |
|
|
|
rpcRequest.setValueMsg(String.format("%s", value)); |
|
|
|
this.sentRpcRequest(rpcRequest, response.getCode().getName(), (String) value, LOG_LW2M_VALUE); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -616,7 +626,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
|
public void sendLogsToThingsboard(String logMsg, String registrationId) { |
|
|
|
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registrationId); |
|
|
|
if (logMsg != null && sessionInfo != null) { |
|
|
|
if(logMsg.length() > 1024){ |
|
|
|
if (logMsg.length() > 1024) { |
|
|
|
logMsg = logMsg.substring(0, 1024); |
|
|
|
} |
|
|
|
this.helper.sendParametersOnThingsboardTelemetry(this.helper.getKvLogyToThingsboard(logMsg), sessionInfo); |
|
|
|
@ -656,10 +666,10 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
|
/** |
|
|
|
* @param registration - |
|
|
|
* @param lwM2mObject - |
|
|
|
* @param path - |
|
|
|
* @param pathIdVer - |
|
|
|
*/ |
|
|
|
private void updateObjectResourceValue(Registration registration, LwM2mObject lwM2mObject, String path) { |
|
|
|
LwM2mPath pathIds = new LwM2mPath(path); |
|
|
|
private void updateObjectResourceValue(Registration registration, LwM2mObject lwM2mObject, String pathIdVer) { |
|
|
|
LwM2mPath pathIds = new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer)); |
|
|
|
lwM2mObject.getInstances().forEach((instanceId, instance) -> { |
|
|
|
String pathInstance = pathIds.toString() + "/" + instanceId; |
|
|
|
this.updateObjectInstanceResourceValue(registration, instance, pathInstance); |
|
|
|
@ -669,10 +679,10 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
|
/** |
|
|
|
* @param registration - |
|
|
|
* @param lwM2mObjectInstance - |
|
|
|
* @param path - |
|
|
|
* @param pathIdVer - |
|
|
|
*/ |
|
|
|
private void updateObjectInstanceResourceValue(Registration registration, LwM2mObjectInstance lwM2mObjectInstance, String path) { |
|
|
|
LwM2mPath pathIds = new LwM2mPath(path); |
|
|
|
private void updateObjectInstanceResourceValue(Registration registration, LwM2mObjectInstance lwM2mObjectInstance, String pathIdVer) { |
|
|
|
LwM2mPath pathIds = new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer)); |
|
|
|
lwM2mObjectInstance.getResources().forEach((resourceId, resource) -> { |
|
|
|
String pathRez = pathIds.toString() + "/" + resourceId; |
|
|
|
this.updateResourcesValue(registration, resource, pathRez); |
|
|
|
@ -782,8 +792,8 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
|
lwM2MClient.getPendingReadRequests().addAll(pathSend); |
|
|
|
ConcurrentHashMap<String, Object> finalParams = params; |
|
|
|
pathSend.forEach(target -> { |
|
|
|
lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, ContentFormat.TLV.getName(), |
|
|
|
finalParams != null ? finalParams.get(target) : null, this.config.getTimeout(), null); |
|
|
|
lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, ContentFormat.TLV.getName(), |
|
|
|
finalParams != null ? finalParams.get(target) : null, this.config.getTimeout(), null); |
|
|
|
}); |
|
|
|
if (OBSERVE.equals(typeOper)) { |
|
|
|
lwM2MClient.initReadValue(this, null); |
|
|
|
@ -932,10 +942,9 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
|
public void onWriteResponseOk(Registration registration, String path, WriteRequest request) { |
|
|
|
if (request.getNode() instanceof LwM2mResource) { |
|
|
|
this.updateResourcesValue(registration, ((LwM2mResource) request.getNode()), path); |
|
|
|
} |
|
|
|
else if (request.getNode() instanceof LwM2mObjectInstance) { |
|
|
|
} else if (request.getNode() instanceof LwM2mObjectInstance) { |
|
|
|
((LwM2mObjectInstance) request.getNode()).getResources().forEach((resId, resource) -> { |
|
|
|
this.updateResourcesValue(registration, resource, path+ "/" + resId); |
|
|
|
this.updateResourcesValue(registration, resource, path + "/" + resId); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@ -1421,7 +1430,6 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @param lwM2MClient - |
|
|
|
*/ |
|
|
|
public void updateFirmwareClient(LwM2mClient lwM2MClient) { |
|
|
|
|