From 436463ac157b5f97636e9883b14141ffe71ec608 Mon Sep 17 00:00:00 2001 From: Nick Ponomar Date: Tue, 22 Mar 2022 10:54:05 +0100 Subject: [PATCH 1/6] Browan ms template --- lora-codec-browan/pom.xml | 110 ++++++++++++++++++ .../src/main/configuration/cumulocity.json | 13 +++ .../src/main/java/lora/Application.java | 29 +++++ .../java/lora/codec/browan/BrowanCodec.java | 24 ++++ .../codec/browan/decoder/BrowanDecoder.java | 23 ++++ .../codec/browan/encoder/BrowanEncoder.java | 24 ++++ .../src/main/resources/application.properties | 18 +++ .../src/main/resources/logback-spring.xml | 53 +++++++++ 8 files changed, 294 insertions(+) create mode 100644 lora-codec-browan/pom.xml create mode 100644 lora-codec-browan/src/main/configuration/cumulocity.json create mode 100644 lora-codec-browan/src/main/java/lora/Application.java create mode 100644 lora-codec-browan/src/main/java/lora/codec/browan/BrowanCodec.java create mode 100644 lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java create mode 100644 lora-codec-browan/src/main/java/lora/codec/browan/encoder/BrowanEncoder.java create mode 100644 lora-codec-browan/src/main/resources/application.properties create mode 100644 lora-codec-browan/src/main/resources/logback-spring.xml diff --git a/lora-codec-browan/pom.xml b/lora-codec-browan/pom.xml new file mode 100644 index 0000000000..5a7cdec5f3 --- /dev/null +++ b/lora-codec-browan/pom.xml @@ -0,0 +1,110 @@ + + + + 4.0.0 + + c8y.example + c8y-examples + ${revision}${changelist} + + lora-codec-browan + lora-codec-browan + http://maven.apache.org + + 2.3.3.RELEASE + lora-codec-browan + lora.Application + + + + + com.nsn.cumulocity.clients-java + microservice-dependencies + ${revision}${changelist} + pom + import + + + + + + com.nsn.cumulocity.clients-java + lpwan-custom-codec + ${c8y.version} + + + com.nsn.cumulocity.model + device-capability-model + ${c8y.version} + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-dependencies.version} + + ${main.class} + + + + + repackage + + + + + + com.nsn.cumulocity.clients-java + microservice-package-maven-plugin + ${c8y.version} + + + package + package + + package + + + ${microservice.name} + ${microservice.name} + UTF-8 + + + + + + + + + + cumulocity + default + http://download.cumulocity.com/maven/repository + + + + + public + http://download.cumulocity.com/maven/repository + + + diff --git a/lora-codec-browan/src/main/configuration/cumulocity.json b/lora-codec-browan/src/main/configuration/cumulocity.json new file mode 100644 index 0000000000..294b88af07 --- /dev/null +++ b/lora-codec-browan/src/main/configuration/cumulocity.json @@ -0,0 +1,13 @@ +{ + "apiVersion":"1", + "version":"@project.version@", + "contextPath": "lora-codec-browan", + "provider": { + "name":"Software AG" + }, + "isolation":"MULTI_TENANT", + "requiredRoles": [ + "ROLE_INVENTORY_ADMIN", + "ROLE_INVENTORY_READ" + ] +} \ No newline at end of file diff --git a/lora-codec-browan/src/main/java/lora/Application.java b/lora-codec-browan/src/main/java/lora/Application.java new file mode 100644 index 0000000000..c8e5079ff1 --- /dev/null +++ b/lora-codec-browan/src/main/java/lora/Application.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2012-2020 Cumulocity GmbH + * Copyright (c) 2022 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, + * and/or its subsidiaries and/or its affiliates and/or their licensors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package lora; + +import com.cumulocity.microservice.lpwan.codec.annotation.CodecMicroserviceApplication; +import org.springframework.boot.SpringApplication; + +@CodecMicroserviceApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} \ No newline at end of file diff --git a/lora-codec-browan/src/main/java/lora/codec/browan/BrowanCodec.java b/lora-codec-browan/src/main/java/lora/codec/browan/BrowanCodec.java new file mode 100644 index 0000000000..64bb67030f --- /dev/null +++ b/lora-codec-browan/src/main/java/lora/codec/browan/BrowanCodec.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2012-2020 Cumulocity GmbH + * Copyright (c) 2022 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, + * and/or its subsidiaries and/or its affiliates and/or their licensors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package lora.codec.browan; + +public class BrowanCodec { + + +} diff --git a/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java b/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java new file mode 100644 index 0000000000..0052c5aa56 --- /dev/null +++ b/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2012-2020 Cumulocity GmbH + * Copyright (c) 2022 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, + * and/or its subsidiaries and/or its affiliates and/or their licensors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package lora.codec.browan.decoder; + + +public class BrowanDecoder { +} diff --git a/lora-codec-browan/src/main/java/lora/codec/browan/encoder/BrowanEncoder.java b/lora-codec-browan/src/main/java/lora/codec/browan/encoder/BrowanEncoder.java new file mode 100644 index 0000000000..ee76e93f0b --- /dev/null +++ b/lora-codec-browan/src/main/java/lora/codec/browan/encoder/BrowanEncoder.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2012-2020 Cumulocity GmbH + * Copyright (c) 2022 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, + * and/or its subsidiaries and/or its affiliates and/or their licensors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package lora.codec.browan.encoder; + + +public class BrowanEncoder { + +} diff --git a/lora-codec-browan/src/main/resources/application.properties b/lora-codec-browan/src/main/resources/application.properties new file mode 100644 index 0000000000..b1497bff21 --- /dev/null +++ b/lora-codec-browan/src/main/resources/application.properties @@ -0,0 +1,18 @@ +# +# Copyright (c) 2012-2020 Cumulocity GmbH +# Copyright (c) 2022 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, +# and/or its subsidiaries and/or its affiliates and/or their licensors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +application.name=lora-codec-browan \ No newline at end of file diff --git a/lora-codec-browan/src/main/resources/logback-spring.xml b/lora-codec-browan/src/main/resources/logback-spring.xml new file mode 100644 index 0000000000..e0ad568c38 --- /dev/null +++ b/lora-codec-browan/src/main/resources/logback-spring.xml @@ -0,0 +1,53 @@ + + + + + + + + + ${LOG_FILE} + + + ${LOG_FILE}.%d{yyyy-MM-dd}.log + + + 30 + 1GB + + + ${FILE_LOG_PATTERN} + + + + + + + + + + + + + + + + \ No newline at end of file From 5e90ff320c1269edac888af7919160ef7f9dc0f7 Mon Sep 17 00:00:00 2001 From: Harald Meyer Date: Thu, 24 Mar 2022 17:15:31 +0100 Subject: [PATCH 2/6] first implementation --- .../java/lora/codec/browan/BrowanCodec.java | 39 +++++----- .../codec/browan/decoder/BrowanDecoder.java | 75 ++++++++++++++----- .../codec/browan/encoder/BrowanEncoder.java | 36 +++++---- pom.xml | 2 +- 4 files changed, 94 insertions(+), 58 deletions(-) diff --git a/lora-codec-browan/src/main/java/lora/codec/browan/BrowanCodec.java b/lora-codec-browan/src/main/java/lora/codec/browan/BrowanCodec.java index 64bb67030f..a5af402bdd 100644 --- a/lora-codec-browan/src/main/java/lora/codec/browan/BrowanCodec.java +++ b/lora-codec-browan/src/main/java/lora/codec/browan/BrowanCodec.java @@ -1,24 +1,25 @@ -/* - * Copyright (c) 2012-2020 Cumulocity GmbH - * Copyright (c) 2022 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, - * and/or its subsidiaries and/or its affiliates and/or their licensors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package lora.codec.browan; -public class BrowanCodec { +import java.util.Collections; +import java.util.Set; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +import org.springframework.stereotype.Component; + +import com.cumulocity.microservice.lpwan.codec.Codec; +import com.cumulocity.microservice.lpwan.codec.model.DeviceInfo; + +@Component +public class BrowanCodec implements Codec { + + @Override + public @NotNull @NotEmpty Set supportsDevices() { + + DeviceInfo airQualitySensor = new DeviceInfo("Browan", "TBHV110"); + return Collections.singleton(airQualitySensor); + } } diff --git a/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java b/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java index 0052c5aa56..1fb23f6f90 100644 --- a/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java +++ b/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java @@ -1,23 +1,60 @@ -/* - * Copyright (c) 2012-2020 Cumulocity GmbH - * Copyright (c) 2022 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, - * and/or its subsidiaries and/or its affiliates and/or their licensors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package lora.codec.browan.decoder; +import java.math.BigDecimal; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; + +import org.joda.time.DateTime; +import org.springframework.stereotype.Component; + +import com.cumulocity.microservice.customdecoders.api.exception.DecoderServiceException; +import com.cumulocity.microservice.customdecoders.api.model.DecoderResult; +import com.cumulocity.microservice.customdecoders.api.model.MeasurementDto; +import com.cumulocity.microservice.customdecoders.api.model.MeasurementValueDto; +import com.cumulocity.microservice.customdecoders.api.service.DecoderService; +import com.cumulocity.microservice.lpwan.codec.decoder.model.LpwanDecoderInputData; +import com.cumulocity.model.idtype.GId; +import com.google.common.io.BaseEncoding; + +@Component +public class BrowanDecoder implements DecoderService { + + @Override + public DecoderResult decode(String inputData, GId deviceId, Map args) throws DecoderServiceException { + LpwanDecoderInputData decoderInput = new LpwanDecoderInputData(inputData, deviceId, args); + ByteBuffer buffer = ByteBuffer.wrap(BaseEncoding.base16().decode(inputData.toUpperCase())); + DecoderResult result = new DecoderResult(); + + buffer.get(); + buffer.get(); + int pcbTemperature = Byte.toUnsignedInt(buffer.get()) - 32; + result.addMeasurement(measurement(decoderInput, "pcb_Temperature", "T", pcbTemperature, "C")); + int humidity = Byte.toUnsignedInt(buffer.get()); + result.addMeasurement(measurement(decoderInput, "c8y_Humidity", "H", humidity, "%")); + int co2 = Short.toUnsignedInt(buffer.getShort()); + result.addMeasurement(measurement(decoderInput, "CO2", "C", co2, "ppm")); + int voc = Short.toUnsignedInt(buffer.getShort()); + result.addMeasurement(measurement(decoderInput, "VOC", "V", voc, "ppm")); + int iaq = Short.toUnsignedInt(buffer.getShort()); + result.addMeasurement(measurement(decoderInput, "IAQ", "Q", iaq, "Q")); + int envTemperature = Byte.toUnsignedInt(buffer.get()) - 32; + result.addMeasurement(measurement(decoderInput, "c8y_Temperature", "T", envTemperature, "C")); + + return result; + } -public class BrowanDecoder { + private MeasurementDto measurement(LpwanDecoderInputData decoderInput, String fragmentName, String seriesName, long v, String unit) { + MeasurementDto m = new MeasurementDto(); + m.setType(fragmentName); + m.setSeries(fragmentName); + MeasurementValueDto value = new MeasurementValueDto(); + value.setSeriesName(seriesName); + value.setValue(BigDecimal.valueOf(v)); + value.setUnit(unit); + m.setValues(Collections.singletonList(value)); + m.setTime(new DateTime(decoderInput.getUpdateTime() != null?decoderInput.getUpdateTime() : System.currentTimeMillis())); + return m; + } } diff --git a/lora-codec-browan/src/main/java/lora/codec/browan/encoder/BrowanEncoder.java b/lora-codec-browan/src/main/java/lora/codec/browan/encoder/BrowanEncoder.java index ee76e93f0b..0628b3c73f 100644 --- a/lora-codec-browan/src/main/java/lora/codec/browan/encoder/BrowanEncoder.java +++ b/lora-codec-browan/src/main/java/lora/codec/browan/encoder/BrowanEncoder.java @@ -1,24 +1,22 @@ -/* - * Copyright (c) 2012-2020 Cumulocity GmbH - * Copyright (c) 2022 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, - * and/or its subsidiaries and/or its affiliates and/or their licensors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package lora.codec.browan.encoder; +import org.springframework.stereotype.Component; + +import com.cumulocity.microservice.customencoders.api.exception.EncoderServiceException; +import com.cumulocity.microservice.customencoders.api.model.EncoderInputData; +import com.cumulocity.microservice.customencoders.api.model.EncoderResult; +import com.cumulocity.microservice.customencoders.api.service.EncoderService; +import com.cumulocity.microservice.lpwan.codec.encoder.model.LpwanEncoderResult; + +@Component +public class BrowanEncoder implements EncoderService { -public class BrowanEncoder { + @Override + public EncoderResult encode(EncoderInputData arg0) throws EncoderServiceException { + LpwanEncoderResult encoderResult = new LpwanEncoderResult(); + encoderResult.setSuccess(false); + encoderResult.setMessage("Encoding Payload Failed"); + return encoderResult; + } } diff --git a/pom.xml b/pom.xml index f4ef99af83..e205aa35b7 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ 1013.108.0 - + -SNAPSHOT ${project.version} UTF-8 11 From 65202d3625d897c999d9c79666c46aae2d8c41dc Mon Sep 17 00:00:00 2001 From: Harald Meyer Date: Thu, 24 Mar 2022 17:24:16 +0100 Subject: [PATCH 3/6] little endian --- .../main/java/lora/codec/browan/decoder/BrowanDecoder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java b/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java index 1fb23f6f90..e3b09ff127 100644 --- a/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java +++ b/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java @@ -33,11 +33,11 @@ public DecoderResult decode(String inputData, GId deviceId, Map result.addMeasurement(measurement(decoderInput, "pcb_Temperature", "T", pcbTemperature, "C")); int humidity = Byte.toUnsignedInt(buffer.get()); result.addMeasurement(measurement(decoderInput, "c8y_Humidity", "H", humidity, "%")); - int co2 = Short.toUnsignedInt(buffer.getShort()); + int co2 = Short.toUnsignedInt(Short.reverseBytes(buffer.getShort())); result.addMeasurement(measurement(decoderInput, "CO2", "C", co2, "ppm")); - int voc = Short.toUnsignedInt(buffer.getShort()); + int voc = Short.toUnsignedInt(Short.reverseBytes(buffer.getShort())); result.addMeasurement(measurement(decoderInput, "VOC", "V", voc, "ppm")); - int iaq = Short.toUnsignedInt(buffer.getShort()); + int iaq = Short.toUnsignedInt(Short.reverseBytes(buffer.getShort())); result.addMeasurement(measurement(decoderInput, "IAQ", "Q", iaq, "Q")); int envTemperature = Byte.toUnsignedInt(buffer.get()) - 32; result.addMeasurement(measurement(decoderInput, "c8y_Temperature", "T", envTemperature, "C")); From 19487c3d6b42b15b1860b233593ba954d8da1674 Mon Sep 17 00:00:00 2001 From: Harald Meyer Date: Fri, 25 Mar 2022 07:35:11 +0100 Subject: [PATCH 4/6] added alarm handling --- .../codec/browan/decoder/BrowanDecoder.java | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java b/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java index e3b09ff127..5a172c254b 100644 --- a/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java +++ b/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java @@ -2,7 +2,6 @@ import java.math.BigDecimal; import java.nio.ByteBuffer; -import java.util.ArrayList; import java.util.Collections; import java.util.Map; @@ -15,7 +14,10 @@ import com.cumulocity.microservice.customdecoders.api.model.MeasurementValueDto; import com.cumulocity.microservice.customdecoders.api.service.DecoderService; import com.cumulocity.microservice.lpwan.codec.decoder.model.LpwanDecoderInputData; +import com.cumulocity.model.event.CumulocitySeverities; import com.cumulocity.model.idtype.GId; +import com.cumulocity.rest.representation.alarm.AlarmRepresentation; +import com.cumulocity.rest.representation.inventory.ManagedObjects; import com.google.common.io.BaseEncoding; @Component @@ -27,20 +29,30 @@ public DecoderResult decode(String inputData, GId deviceId, Map ByteBuffer buffer = ByteBuffer.wrap(BaseEncoding.base16().decode(inputData.toUpperCase())); DecoderResult result = new DecoderResult(); - buffer.get(); - buffer.get(); - int pcbTemperature = Byte.toUnsignedInt(buffer.get()) - 32; - result.addMeasurement(measurement(decoderInput, "pcb_Temperature", "T", pcbTemperature, "C")); - int humidity = Byte.toUnsignedInt(buffer.get()); - result.addMeasurement(measurement(decoderInput, "c8y_Humidity", "H", humidity, "%")); - int co2 = Short.toUnsignedInt(Short.reverseBytes(buffer.getShort())); - result.addMeasurement(measurement(decoderInput, "CO2", "C", co2, "ppm")); - int voc = Short.toUnsignedInt(Short.reverseBytes(buffer.getShort())); - result.addMeasurement(measurement(decoderInput, "VOC", "V", voc, "ppm")); - int iaq = Short.toUnsignedInt(Short.reverseBytes(buffer.getShort())); - result.addMeasurement(measurement(decoderInput, "IAQ", "Q", iaq, "Q")); - int envTemperature = Byte.toUnsignedInt(buffer.get()) - 32; - result.addMeasurement(measurement(decoderInput, "c8y_Temperature", "T", envTemperature, "C")); + if(decoderInput.getFport() == 103) { + buffer.get(); + buffer.get(); + int pcbTemperature = Byte.toUnsignedInt(buffer.get()) - 32; + result.addMeasurement(measurement(decoderInput, "pcb_Temperature", "T", pcbTemperature, "C")); + int humidity = Byte.toUnsignedInt(buffer.get()); + result.addMeasurement(measurement(decoderInput, "c8y_Humidity", "H", humidity, "%")); + int co2 = Short.toUnsignedInt(Short.reverseBytes(buffer.getShort())); + result.addMeasurement(measurement(decoderInput, "CO2", "C", co2, "ppm")); + int voc = Short.toUnsignedInt(Short.reverseBytes(buffer.getShort())); + result.addMeasurement(measurement(decoderInput, "VOC", "V", voc, "ppm")); + int iaq = Short.toUnsignedInt(Short.reverseBytes(buffer.getShort())); + result.addMeasurement(measurement(decoderInput, "IAQ", "Q", iaq, "Q")); + int envTemperature = Byte.toUnsignedInt(buffer.get()) - 32; + result.addMeasurement(measurement(decoderInput, "c8y_Temperature", "T", envTemperature, "C")); + } else { + AlarmRepresentation alarm = new AlarmRepresentation(); + alarm.setSource(ManagedObjects.asManagedObject(deviceId)); + alarm.setType("DecoderError"); + alarm.setSeverity(CumulocitySeverities.CRITICAL.name()); + alarm.setText(String.format("Unknown port: %s", decoderInput.getFport())); + alarm.setDateTime(DateTime.now()); + result.addAlarm(alarm, true); + } return result; } From 004736ef459540c921f00803aaa435e3526ed06a Mon Sep 17 00:00:00 2001 From: Harald Meyer Date: Fri, 25 Mar 2022 07:42:03 +0100 Subject: [PATCH 5/6] air quality warning --- .../codec/browan/decoder/BrowanDecoder.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java b/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java index 5a172c254b..4dbf26c929 100644 --- a/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java +++ b/lora-codec-browan/src/main/java/lora/codec/browan/decoder/BrowanDecoder.java @@ -43,20 +43,29 @@ public DecoderResult decode(String inputData, GId deviceId, Map int iaq = Short.toUnsignedInt(Short.reverseBytes(buffer.getShort())); result.addMeasurement(measurement(decoderInput, "IAQ", "Q", iaq, "Q")); int envTemperature = Byte.toUnsignedInt(buffer.get()) - 32; - result.addMeasurement(measurement(decoderInput, "c8y_Temperature", "T", envTemperature, "C")); + result.addMeasurement(measurement(decoderInput, "c8y_Temperature", "T", envTemperature, "C")); + + if(iaq > 100) { + result.addAlarm(alarm(deviceId, "AirQualityWarning", CumulocitySeverities.WARNING, + String.format("Air quality indicator > 100. Actual value: %d. Please open window", iaq)), true); + } } else { - AlarmRepresentation alarm = new AlarmRepresentation(); - alarm.setSource(ManagedObjects.asManagedObject(deviceId)); - alarm.setType("DecoderError"); - alarm.setSeverity(CumulocitySeverities.CRITICAL.name()); - alarm.setText(String.format("Unknown port: %s", decoderInput.getFport())); - alarm.setDateTime(DateTime.now()); - result.addAlarm(alarm, true); + result.addAlarm(alarm(deviceId, "DecoderError", CumulocitySeverities.CRITICAL, String.format("Unknown port: %s", decoderInput.getFport())), true); } return result; } + private AlarmRepresentation alarm(GId deviceId, String alarmType, CumulocitySeverities severity, String alarmText) { + AlarmRepresentation alarm = new AlarmRepresentation(); + alarm.setSource(ManagedObjects.asManagedObject(deviceId)); + alarm.setType(alarmType); + alarm.setSeverity(severity.name()); + alarm.setText(alarmText); + alarm.setDateTime(DateTime.now()); + return alarm; + } + private MeasurementDto measurement(LpwanDecoderInputData decoderInput, String fragmentName, String seriesName, long v, String unit) { MeasurementDto m = new MeasurementDto(); m.setType(fragmentName); From 4c5ea1ad46c9095441e6c53d92a866d27f302c33 Mon Sep 17 00:00:00 2001 From: Harald Meyer Date: Fri, 22 Apr 2022 16:19:36 +0200 Subject: [PATCH 6/6] increased perm memory to avoid OOME --- lora-codec-browan/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lora-codec-browan/pom.xml b/lora-codec-browan/pom.xml index 5a7cdec5f3..17c96b2b6a 100644 --- a/lora-codec-browan/pom.xml +++ b/lora-codec-browan/pom.xml @@ -87,6 +87,10 @@ ${microservice.name} ${microservice.name} UTF-8 + + 92m + 172m +