Lwm2m: add logLwm2m to start bootstrap
This commit is contained in:
parent
2fcc48555c
commit
4bf0af9e78
@ -30,15 +30,21 @@ import org.eclipse.leshan.server.security.SecurityInfo;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.thingsboard.server.common.transport.TransportService;
|
||||||
|
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||||
import org.thingsboard.server.transport.lwm2m.secure.LwM2MGetSecurityInfo;
|
import org.thingsboard.server.transport.lwm2m.secure.LwM2MGetSecurityInfo;
|
||||||
import org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode;
|
import org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode;
|
||||||
import org.thingsboard.server.transport.lwm2m.secure.ReadResultSecurityStore;
|
import org.thingsboard.server.transport.lwm2m.secure.ReadResultSecurityStore;
|
||||||
|
import org.thingsboard.server.transport.lwm2m.server.LwM2MSessionMsgListener;
|
||||||
|
import org.thingsboard.server.transport.lwm2m.server.LwM2MTransportContextServer;
|
||||||
|
import org.thingsboard.server.transport.lwm2m.server.LwM2MTransportHandler;
|
||||||
import org.thingsboard.server.transport.lwm2m.utils.TypeServer;
|
import org.thingsboard.server.transport.lwm2m.utils.TypeServer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.thingsboard.server.transport.lwm2m.server.LwM2MTransportHandler.*;
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2MTransportHandler.*;
|
||||||
|
|
||||||
@ -52,6 +58,11 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
|
|||||||
@Autowired
|
@Autowired
|
||||||
LwM2MGetSecurityInfo lwM2MGetSecurityInfo;
|
LwM2MGetSecurityInfo lwM2MGetSecurityInfo;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public LwM2MTransportContextServer context;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public LwM2MBootstrapSecurityStore(EditableBootstrapConfigStore bootstrapConfigStore) {
|
public LwM2MBootstrapSecurityStore(EditableBootstrapConfigStore bootstrapConfigStore) {
|
||||||
this.bootstrapConfigStore = bootstrapConfigStore;
|
this.bootstrapConfigStore = bootstrapConfigStore;
|
||||||
}
|
}
|
||||||
@ -147,16 +158,21 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
|
|||||||
lwM2MBootstrapConfig.servers = mapper.readValue(bootstrapObject.get(SERVERS).toString(), LwM2MBootstrapServers.class);
|
lwM2MBootstrapConfig.servers = mapper.readValue(bootstrapObject.get(SERVERS).toString(), LwM2MBootstrapServers.class);
|
||||||
LwM2MServerBootstrap profileServerBootstrap = mapper.readValue(bootstrapObject.get(BOOTSTRAP_SERVER).toString(), LwM2MServerBootstrap.class);
|
LwM2MServerBootstrap profileServerBootstrap = mapper.readValue(bootstrapObject.get(BOOTSTRAP_SERVER).toString(), LwM2MServerBootstrap.class);
|
||||||
LwM2MServerBootstrap profileLwm2mServer = mapper.readValue(bootstrapObject.get(LWM2M_SERVER).toString(), LwM2MServerBootstrap.class);
|
LwM2MServerBootstrap profileLwm2mServer = mapper.readValue(bootstrapObject.get(LWM2M_SERVER).toString(), LwM2MServerBootstrap.class);
|
||||||
|
UUID sessionUUiD = UUID.randomUUID();
|
||||||
|
TransportProtos.SessionInfoProto sessionInfo = context.getValidateSessionInfo(store.getMsg(), sessionUUiD.getMostSignificantBits(), sessionUUiD.getLeastSignificantBits());
|
||||||
|
context.getTransportService().registerAsyncSession(sessionInfo, new LwM2MSessionMsgListener(null, sessionInfo));
|
||||||
if (getValidatedSecurityMode(lwM2MBootstrapConfig.bootstrapServer, profileServerBootstrap, lwM2MBootstrapConfig.lwm2mServer, profileLwm2mServer)) {
|
if (getValidatedSecurityMode(lwM2MBootstrapConfig.bootstrapServer, profileServerBootstrap, lwM2MBootstrapConfig.lwm2mServer, profileLwm2mServer)) {
|
||||||
lwM2MBootstrapConfig.bootstrapServer = new LwM2MServerBootstrap(lwM2MBootstrapConfig.bootstrapServer, profileServerBootstrap);
|
lwM2MBootstrapConfig.bootstrapServer = new LwM2MServerBootstrap(lwM2MBootstrapConfig.bootstrapServer, profileServerBootstrap);
|
||||||
lwM2MBootstrapConfig.lwm2mServer = new LwM2MServerBootstrap(lwM2MBootstrapConfig.lwm2mServer, profileLwm2mServer);
|
lwM2MBootstrapConfig.lwm2mServer = new LwM2MServerBootstrap(lwM2MBootstrapConfig.lwm2mServer, profileLwm2mServer);
|
||||||
|
String logMsg = String.format(LOG_LW2M_INFO + ": getParametersBootstrap: %s Access connect client with bootstrap server.", store.getEndPoint());
|
||||||
|
context.sentParametersOnThingsboard(context.getTelemetryMsgObject(logMsg), LwM2MTransportHandler.DEVICE_TELEMETRY_TOPIC, sessionInfo);
|
||||||
return lwM2MBootstrapConfig;
|
return lwM2MBootstrapConfig;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.error(" [{}] Different values SecurityMode between of client and profile.", store.getEndPoint());
|
log.error(" [{}] Different values SecurityMode between of client and profile.", store.getEndPoint());
|
||||||
log.error(LOG_LW2M_ERROR + " getParametersBootstrap: [{}] Different values SecurityMode between of client and profile.", store.getEndPoint());
|
log.error(LOG_LW2M_ERROR + " getParametersBootstrap: [{}] Different values SecurityMode between of client and profile.", store.getEndPoint());
|
||||||
String logMsg = String.format(LOG_LW2M_ERROR + " getParametersBootstrap: %s Different values SecurityMode between of client and profile.", store.getEndPoint());
|
String logMsg = String.format(LOG_LW2M_ERROR + ": getParametersBootstrap: %s Different values SecurityMode between of client and profile.", store.getEndPoint());
|
||||||
// sentLogsToThingsboard(logMsg, store.getEndPoint());
|
context.sentParametersOnThingsboard(context.getTelemetryMsgObject(logMsg), LwM2MTransportHandler.DEVICE_TELEMETRY_TOPIC, sessionInfo);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
@ -165,6 +181,7 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bootstrap security have to sync between (bootstrapServer in credential and bootstrapServer in profile)
|
* Bootstrap security have to sync between (bootstrapServer in credential and bootstrapServer in profile)
|
||||||
* and (lwm2mServer in credential and lwm2mServer in profile
|
* and (lwm2mServer in credential and lwm2mServer in profile
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public class LwM2MSessionMsgListener implements GenericFutureListener<Future<? s
|
|||||||
private LwM2MTransportService service;
|
private LwM2MTransportService service;
|
||||||
private TransportProtos.SessionInfoProto sessionInfo;
|
private TransportProtos.SessionInfoProto sessionInfo;
|
||||||
|
|
||||||
LwM2MSessionMsgListener(LwM2MTransportService service, TransportProtos.SessionInfoProto sessionInfo) {
|
public LwM2MSessionMsgListener(LwM2MTransportService service, TransportProtos.SessionInfoProto sessionInfo) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.sessionInfo = sessionInfo;
|
this.sessionInfo = sessionInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,15 +30,29 @@ package org.thingsboard.server.transport.lwm2m.server;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.thingsboard.server.common.transport.TransportContext;
|
import org.thingsboard.server.common.transport.TransportContext;
|
||||||
|
import org.thingsboard.server.common.transport.TransportService;
|
||||||
|
import org.thingsboard.server.common.transport.TransportServiceCallback;
|
||||||
|
import org.thingsboard.server.common.transport.adaptor.AdaptorException;
|
||||||
import org.thingsboard.server.common.transport.lwm2m.LwM2MTransportConfigServer;
|
import org.thingsboard.server.common.transport.lwm2m.LwM2MTransportConfigServer;
|
||||||
|
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||||
|
import org.thingsboard.server.transport.lwm2m.server.adaptors.LwM2MJsonAdaptor;
|
||||||
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2MClient;
|
||||||
|
import org.thingsboard.server.transport.lwm2m.server.secure.LwM2mInMemorySecurityStore;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2MTransportHandler.CLIENT_NOT_AUTHORIZED;
|
||||||
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2MTransportHandler.LOG_LW2M_TELEMETRY;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || ('${service.type:null}'=='monolith' && '${transport.lwm2m.enabled}'=='true')")
|
@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || ('${service.type:null}'=='monolith' && '${transport.lwm2m.enabled}'=='true')")
|
||||||
@ -49,12 +63,84 @@ public class LwM2MTransportContextServer extends TransportContext {
|
|||||||
@Autowired
|
@Autowired
|
||||||
LwM2MTransportConfigServer lwM2MTransportConfigServer;
|
LwM2MTransportConfigServer lwM2MTransportConfigServer;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TransportService transportService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LwM2MJsonAdaptor adaptor;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
LwM2mInMemorySecurityStore lwM2mInMemorySecurityStore;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
this.ctxServer = lwM2MTransportConfigServer;
|
this.ctxServer = lwM2MTransportConfigServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LwM2MTransportConfigServer getCtxServer () {
|
public LwM2MTransportConfigServer getCtxServer() {
|
||||||
return this.ctxServer;
|
return this.ctxServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sent to Thingsboard Attribute || Telemetry
|
||||||
|
*
|
||||||
|
* @param msg - JsonObject: [{name: value}]
|
||||||
|
* @return - dummy
|
||||||
|
*/
|
||||||
|
private <T> TransportServiceCallback<Void> getPubAckCallbackSentAttrTelemetry(final T msg) {
|
||||||
|
return new TransportServiceCallback<Void>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Void dummy) {
|
||||||
|
log.trace("Success to publish msg: {}, dummy: {}", msg, dummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
log.trace("[{}] Failed to publish msg: {}", msg, e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sentParametersOnThingsboard(JsonElement msg, String topicName, TransportProtos.SessionInfoProto sessionInfo) {
|
||||||
|
try {
|
||||||
|
if (topicName.equals(LwM2MTransportHandler.DEVICE_ATTRIBUTES_TOPIC)) {
|
||||||
|
TransportProtos.PostAttributeMsg postAttributeMsg = adaptor.convertToPostAttributes(msg);
|
||||||
|
TransportServiceCallback call = this.getPubAckCallbackSentAttrTelemetry(postAttributeMsg);
|
||||||
|
transportService.process(sessionInfo, postAttributeMsg, this.getPubAckCallbackSentAttrTelemetry(call));
|
||||||
|
} else if (topicName.equals(LwM2MTransportHandler.DEVICE_TELEMETRY_TOPIC)) {
|
||||||
|
TransportProtos.PostTelemetryMsg postTelemetryMsg = adaptor.convertToPostTelemetry(msg);
|
||||||
|
TransportServiceCallback call = this.getPubAckCallbackSentAttrTelemetry(postTelemetryMsg);
|
||||||
|
transportService.process(sessionInfo, postTelemetryMsg, this.getPubAckCallbackSentAttrTelemetry(call));
|
||||||
|
}
|
||||||
|
} catch (AdaptorException e) {
|
||||||
|
log.error("[{}] Failed to process publish msg [{}]", topicName, e);
|
||||||
|
log.info("[{}] Closing current session due to invalid publish", topicName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonObject getTelemetryMsgObject(String logMsg) {
|
||||||
|
JsonObject telemetries = new JsonObject();
|
||||||
|
telemetries.addProperty(LOG_LW2M_TELEMETRY, logMsg);
|
||||||
|
return telemetries;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return - sessionInfo after access connect client
|
||||||
|
*/
|
||||||
|
public TransportProtos.SessionInfoProto getValidateSessionInfo(TransportProtos.ValidateDeviceCredentialsResponseMsg msg, long mostSignificantBits, long leastSignificantBits) {
|
||||||
|
return TransportProtos.SessionInfoProto.newBuilder()
|
||||||
|
.setNodeId(this.getNodeId())
|
||||||
|
.setSessionIdMSB(mostSignificantBits)
|
||||||
|
.setSessionIdLSB(leastSignificantBits)
|
||||||
|
.setDeviceIdMSB(msg.getDeviceInfo().getDeviceIdMSB())
|
||||||
|
.setDeviceIdLSB(msg.getDeviceInfo().getDeviceIdLSB())
|
||||||
|
.setTenantIdMSB(msg.getDeviceInfo().getTenantIdMSB())
|
||||||
|
.setTenantIdLSB(msg.getDeviceInfo().getTenantIdLSB())
|
||||||
|
.setDeviceName(msg.getDeviceInfo().getDeviceName())
|
||||||
|
.setDeviceType(msg.getDeviceInfo().getDeviceType())
|
||||||
|
.setDeviceProfileIdLSB(msg.getDeviceInfo().getDeviceProfileIdLSB())
|
||||||
|
.setDeviceProfileIdMSB(msg.getDeviceInfo().getDeviceProfileIdMSB())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,12 +16,10 @@
|
|||||||
package org.thingsboard.server.transport.lwm2m.server;
|
package org.thingsboard.server.transport.lwm2m.server;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.*;
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import com.google.gson.JsonSyntaxException;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.qpid.proton.engine.Session;
|
||||||
import org.eclipse.californium.core.network.config.NetworkConfig;
|
import org.eclipse.californium.core.network.config.NetworkConfig;
|
||||||
import org.eclipse.leshan.core.model.ResourceModel;
|
import org.eclipse.leshan.core.model.ResourceModel;
|
||||||
import org.eclipse.leshan.core.node.LwM2mNode;
|
import org.eclipse.leshan.core.node.LwM2mNode;
|
||||||
@ -39,6 +37,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.thingsboard.server.common.data.DeviceProfile;
|
import org.thingsboard.server.common.data.DeviceProfile;
|
||||||
import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration;
|
import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration;
|
||||||
|
import org.thingsboard.server.common.transport.TransportService;
|
||||||
|
import org.thingsboard.server.common.transport.TransportServiceCallback;
|
||||||
|
import org.thingsboard.server.common.transport.adaptor.AdaptorException;
|
||||||
|
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||||
|
import org.thingsboard.server.transport.lwm2m.server.adaptors.LwM2MJsonAdaptor;
|
||||||
import org.thingsboard.server.transport.lwm2m.server.client.AttrTelemetryObserveValue;
|
import org.thingsboard.server.transport.lwm2m.server.client.AttrTelemetryObserveValue;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
@ -115,7 +118,6 @@ public class LwM2MTransportHandler{
|
|||||||
@Autowired
|
@Autowired
|
||||||
private LwM2MTransportService service;
|
private LwM2MTransportService service;
|
||||||
|
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
LwM2mServerListener lwM2mServerListener = new LwM2mServerListener(lhServerCert, service);
|
LwM2mServerListener lwM2mServerListener = new LwM2mServerListener(lhServerCert, service);
|
||||||
|
|||||||
@ -229,7 +229,7 @@ public class LwM2MTransportRequest {
|
|||||||
if (isSuccess(((Response)response.getCoapResponse()).getCode())) {
|
if (isSuccess(((Response)response.getCoapResponse()).getCode())) {
|
||||||
this.handleResponse(registration, request.getPath().toString(), response, request, lwM2MClient);
|
this.handleResponse(registration, request.getPath().toString(), response, request, lwM2MClient);
|
||||||
if (request instanceof WriteRequest && ((WriteRequest) request).isReplaceRequest()) {
|
if (request instanceof WriteRequest && ((WriteRequest) request).isReplaceRequest()) {
|
||||||
String msg = String.format(LOG_LW2M_INFO + " sendRequest Replace: CoapCde - %s Lwm2m code - %d name - %s Resource path - %s value - %s SendRequest to Client",
|
String msg = String.format(LOG_LW2M_INFO + ": sendRequest Replace: CoapCde - %s Lwm2m code - %d name - %s Resource path - %s value - %s SendRequest to Client",
|
||||||
((Response)response.getCoapResponse()).getCode(), response.getCode().getCode(), response.getCode().getName(), request.getPath().toString(),
|
((Response)response.getCoapResponse()).getCode(), response.getCode().getCode(), response.getCode().getName(), request.getPath().toString(),
|
||||||
((LwM2mSingleResource)((WriteRequest) request).getNode()).getValue().toString());
|
((LwM2mSingleResource)((WriteRequest) request).getNode()).getValue().toString());
|
||||||
service.sentLogsToThingsboard(msg, registration.getId());
|
service.sentLogsToThingsboard(msg, registration.getId());
|
||||||
@ -237,13 +237,13 @@ public class LwM2MTransportRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String msg = String.format(LOG_LW2M_ERROR + " sendRequest: CoapCde - %s Lwm2m code - %d name - %s Resource path - %s SendRequest to Client",
|
String msg = String.format(LOG_LW2M_ERROR + ": sendRequest: CoapCde - %s Lwm2m code - %d name - %s Resource path - %s SendRequest to Client",
|
||||||
((Response)response.getCoapResponse()).getCode(), response.getCode().getCode(), response.getCode().getName(), request.getPath().toString());
|
((Response)response.getCoapResponse()).getCode(), response.getCode().getCode(), response.getCode().getName(), request.getPath().toString());
|
||||||
service.sentLogsToThingsboard(msg, registration.getId());
|
service.sentLogsToThingsboard(msg, registration.getId());
|
||||||
log.error("[{}] - [{}] [{}] error SendRequest", ((Response)response.getCoapResponse()).getCode(), response.getCode(), request.getPath().toString());
|
log.error("[{}] - [{}] [{}] error SendRequest", ((Response)response.getCoapResponse()).getCode(), response.getCode(), request.getPath().toString());
|
||||||
}
|
}
|
||||||
}, e -> {
|
}, e -> {
|
||||||
String msg = String.format(LOG_LW2M_ERROR + " sendRequest: Resource path - %s msg error - %s SendRequest to Client",
|
String msg = String.format(LOG_LW2M_ERROR + ": sendRequest: Resource path - %s msg error - %s SendRequest to Client",
|
||||||
request.getPath().toString(), e.toString());
|
request.getPath().toString(), e.toString());
|
||||||
service.sentLogsToThingsboard(msg, registration.getId());
|
service.sentLogsToThingsboard(msg, registration.getId());
|
||||||
log.error("[{}] - [{}] error SendRequest", request.getPath().toString(), e.toString());
|
log.error("[{}] - [{}] error SendRequest", request.getPath().toString(), e.toString());
|
||||||
|
|||||||
@ -85,8 +85,8 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2MTransportHandle
|
|||||||
@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true' ) || ('${service.type:null}'=='monolith' && '${transport.lwm2m.enabled}'=='true')")
|
@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true' ) || ('${service.type:null}'=='monolith' && '${transport.lwm2m.enabled}'=='true')")
|
||||||
public class LwM2MTransportService {
|
public class LwM2MTransportService {
|
||||||
|
|
||||||
@Autowired
|
// @Autowired
|
||||||
private LwM2MJsonAdaptor adaptor;
|
// private LwM2MJsonAdaptor adaptor;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TransportService transportService;
|
private TransportService transportService;
|
||||||
@ -265,7 +265,7 @@ public class LwM2MTransportService {
|
|||||||
} else {
|
} else {
|
||||||
sessionInfo = SessionInfoProto.newBuilder()
|
sessionInfo = SessionInfoProto.newBuilder()
|
||||||
.setNodeId(this.context.getNodeId())
|
.setNodeId(this.context.getNodeId())
|
||||||
.setSessionIdMSB(lwM2MClient.getSessionUuid().getMostSignificantBits())
|
.setSessionIdMSB(lwM2MClient.getSessionUuid().getMostSignificantBits() )
|
||||||
.setSessionIdLSB(lwM2MClient.getSessionUuid().getLeastSignificantBits())
|
.setSessionIdLSB(lwM2MClient.getSessionUuid().getLeastSignificantBits())
|
||||||
.setDeviceIdMSB(msg.getDeviceInfo().getDeviceIdMSB())
|
.setDeviceIdMSB(msg.getDeviceInfo().getDeviceIdMSB())
|
||||||
.setDeviceIdLSB(msg.getDeviceInfo().getDeviceIdLSB())
|
.setDeviceIdLSB(msg.getDeviceInfo().getDeviceIdLSB())
|
||||||
@ -315,7 +315,7 @@ public class LwM2MTransportService {
|
|||||||
*/
|
*/
|
||||||
private void updateAttrTelemetry(Registration registration, boolean start, Set<String> paths) {
|
private void updateAttrTelemetry(Registration registration, boolean start, Set<String> paths) {
|
||||||
JsonObject attributes = new JsonObject();
|
JsonObject attributes = new JsonObject();
|
||||||
JsonObject telemetrys = new JsonObject();
|
JsonObject telemetries = new JsonObject();
|
||||||
if (start) {
|
if (start) {
|
||||||
// #1.1
|
// #1.1
|
||||||
JsonObject attributeClient = this.getAttributeClient(registration);
|
JsonObject attributeClient = this.getAttributeClient(registration);
|
||||||
@ -327,7 +327,7 @@ public class LwM2MTransportService {
|
|||||||
}
|
}
|
||||||
// #1.2
|
// #1.2
|
||||||
CountDownLatch cancelLatch = new CountDownLatch(1);
|
CountDownLatch cancelLatch = new CountDownLatch(1);
|
||||||
this.getParametersFromProfile(attributes, telemetrys, registration, paths);
|
this.getParametersFromProfile(attributes, telemetries, registration, paths);
|
||||||
cancelLatch.countDown();
|
cancelLatch.countDown();
|
||||||
try {
|
try {
|
||||||
cancelLatch.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
|
cancelLatch.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
|
||||||
@ -336,8 +336,8 @@ public class LwM2MTransportService {
|
|||||||
}
|
}
|
||||||
if (attributes.getAsJsonObject().entrySet().size() > 0)
|
if (attributes.getAsJsonObject().entrySet().size() > 0)
|
||||||
this.updateParametersOnThingsboard(attributes, DEVICE_ATTRIBUTES_TOPIC, registration.getId());
|
this.updateParametersOnThingsboard(attributes, DEVICE_ATTRIBUTES_TOPIC, registration.getId());
|
||||||
if (telemetrys.getAsJsonObject().entrySet().size() > 0)
|
if (telemetries.getAsJsonObject().entrySet().size() > 0)
|
||||||
this.updateParametersOnThingsboard(telemetrys, DEVICE_TELEMETRY_TOPIC, registration.getId());
|
this.updateParametersOnThingsboard(telemetries, DEVICE_TELEMETRY_TOPIC, registration.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -432,20 +432,22 @@ public class LwM2MTransportService {
|
|||||||
public void updateParametersOnThingsboard(JsonElement msg, String topicName, String registrationId) {
|
public void updateParametersOnThingsboard(JsonElement msg, String topicName, String registrationId) {
|
||||||
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registrationId);
|
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registrationId);
|
||||||
if (sessionInfo != null) {
|
if (sessionInfo != null) {
|
||||||
try {
|
context.sentParametersOnThingsboard(msg, topicName, sessionInfo);
|
||||||
if (topicName.equals(LwM2MTransportHandler.DEVICE_ATTRIBUTES_TOPIC)) {
|
// try {
|
||||||
PostAttributeMsg postAttributeMsg = adaptor.convertToPostAttributes(msg);
|
// if (topicName.equals(LwM2MTransportHandler.DEVICE_ATTRIBUTES_TOPIC)) {
|
||||||
TransportServiceCallback call = this.getPubAckCallbackSentAttrTelemetry(-1, postAttributeMsg);
|
//
|
||||||
transportService.process(sessionInfo, postAttributeMsg, call);
|
//// PostAttributeMsg postAttributeMsg = adaptor.convertToPostAttributes(msg);
|
||||||
} else if (topicName.equals(LwM2MTransportHandler.DEVICE_TELEMETRY_TOPIC)) {
|
//// TransportServiceCallback call = this.getPubAckCallbackSentAttrTelemetry(-1, postAttributeMsg);
|
||||||
PostTelemetryMsg postTelemetryMsg = adaptor.convertToPostTelemetry(msg);
|
//// transportService.process(sessionInfo, postAttributeMsg, call);
|
||||||
TransportServiceCallback call = this.getPubAckCallbackSentAttrTelemetry(-1, postTelemetryMsg);
|
// } else if (topicName.equals(LwM2MTransportHandler.DEVICE_TELEMETRY_TOPIC)) {
|
||||||
transportService.process(sessionInfo, postTelemetryMsg, this.getPubAckCallbackSentAttrTelemetry(-1, call));
|
// PostTelemetryMsg postTelemetryMsg = adaptor.convertToPostTelemetry(msg);
|
||||||
}
|
// TransportServiceCallback call = this.getPubAckCallbackSentAttrTelemetry(-1, postTelemetryMsg);
|
||||||
} catch (AdaptorException e) {
|
// transportService.process(sessionInfo, postTelemetryMsg, this.getPubAckCallbackSentAttrTelemetry(-1, call));
|
||||||
log.error("[{}] Failed to process publish msg [{}]", topicName, e);
|
// }
|
||||||
log.info("[{}] Closing current session due to invalid publish", topicName);
|
// } catch (AdaptorException e) {
|
||||||
}
|
// log.error("[{}] Failed to process publish msg [{}]", topicName, e);
|
||||||
|
// log.info("[{}] Closing current session due to invalid publish", topicName);
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
log.error("Client: [{}] updateParametersOnThingsboard [{}] sessionInfo ", registrationId, sessionInfo);
|
log.error("Client: [{}] updateParametersOnThingsboard [{}] sessionInfo ", registrationId, sessionInfo);
|
||||||
}
|
}
|
||||||
@ -669,7 +671,7 @@ public class LwM2MTransportService {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.error(LOG_LW2M_ERROR + ": Resource path - [{}] value - [{}] is not Writable and cannot be updated", path, value);
|
log.error(LOG_LW2M_ERROR + ": Resource path - [{}] value - [{}] is not Writable and cannot be updated", path, value);
|
||||||
String logMsg = String.format(LOG_LW2M_ERROR + " attributeUpdate: Resource path - %s value - %s is not Writable and cannot be updated", path, value);
|
String logMsg = String.format(LOG_LW2M_ERROR + ": attributeUpdate: Resource path - %s value - %s is not Writable and cannot be updated", path, value);
|
||||||
this.sentLogsToThingsboard(logMsg, lwM2MClient.getRegistration().getId());
|
this.sentLogsToThingsboard(logMsg, lwM2MClient.getRegistration().getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -990,9 +992,9 @@ public class LwM2MTransportService {
|
|||||||
|
|
||||||
public void sentLogsToThingsboard(String msg, String registrationId) {
|
public void sentLogsToThingsboard(String msg, String registrationId) {
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
JsonObject telemetrys = new JsonObject();
|
JsonObject telemetries = new JsonObject();
|
||||||
telemetrys.addProperty(LOG_LW2M_TELEMETRY, msg);
|
telemetries.addProperty(LOG_LW2M_TELEMETRY, msg);
|
||||||
this.updateParametersOnThingsboard(telemetrys, LwM2MTransportHandler.DEVICE_TELEMETRY_TOPIC, registrationId);
|
this.updateParametersOnThingsboard(telemetries, LwM2MTransportHandler.DEVICE_TELEMETRY_TOPIC, registrationId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user