Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Allow LoRaWAN asset attributes to ingest full JSON arrays (#2713)

rainerhitz286397283a69
diff --git a/agent/src/main/java/org/openremote/agent/protocol/lorawan/AbstractLoRaWANProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/lorawan/AbstractLoRaWANProtocol.java
index a66127f0e..68f86000d 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/lorawan/AbstractLoRaWANProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/lorawan/AbstractLoRaWANProtocol.java
@@ -264,7 +264,7 @@ public abstract class AbstractLoRaWANProtocol<S extends AbstractLoRaWANProtocol<
return false;
}
getAgentConfigJsonPath(attribute).ifPresent(
- jsonPath -> agentLink.setValueFilters(new ValueFilter[] {new JsonPathFilter(jsonPath, true, false)})
+ jsonPath -> agentLink.setValueFilters(new ValueFilter[] {new JsonPathFilter(jsonPath, false, false)})
);
getAgentConfigRegex(attribute).ifPresent(
pattern -> agentLink.setValueFilters(new ValueFilter[] {new RegexValueFilter(pattern, false, false, 1, 0)})
diff --git a/setup/src/integration/java/org/openremote/setup/integration/model/asset/ChirpStackTestAsset.java b/setup/src/integration/java/org/openremote/setup/integration/model/asset/ChirpStackTestAsset.java
index 2833e8487..82de36202 100644
--- a/setup/src/integration/java/org/openremote/setup/integration/model/asset/ChirpStackTestAsset.java
+++ b/setup/src/integration/java/org/openremote/setup/integration/model/asset/ChirpStackTestAsset.java
@@ -53,6 +53,15 @@ public class ChirpStackTestAsset extends Asset<ChirpStackTestAsset> {
));
}})
);
+ public static final AttributeDescriptor<String> ERRORS = new AttributeDescriptor<>("errors", ValueType.TEXT,
+ new MetaItem<>(MetaItemType.READ_ONLY),
+ new MetaItem<>(MetaItemType.AGENT_LINK_CONFIG, new ValueType.ObjectMap() {{
+ putAll(Map.of(
+ "uplinkPort", 2,
+ "valueFilterJsonPath", "$.object.Errors"
+ ));
+ }})
+ );
public static final AttributeDescriptor<Boolean> SWITCH = new AttributeDescriptor<>("switch", ValueType.BOOLEAN,
new MetaItem<>(MetaItemType.AGENT_LINK_CONFIG, new ValueType.ObjectMap() {{
putAll(Map.of(
diff --git a/setup/src/integration/java/org/openremote/setup/integration/model/asset/TheThingsStackTestAsset.java b/setup/src/integration/java/org/openremote/setup/integration/model/asset/TheThingsStackTestAsset.java
index 14144af9a..b6a1621ca 100644
--- a/setup/src/integration/java/org/openremote/setup/integration/model/asset/TheThingsStackTestAsset.java
+++ b/setup/src/integration/java/org/openremote/setup/integration/model/asset/TheThingsStackTestAsset.java
@@ -53,6 +53,15 @@ public class TheThingsStackTestAsset extends Asset<TheThingsStackTestAsset> {
));
}})
);
+ public static final AttributeDescriptor<String> ERRORS = new AttributeDescriptor<>("errors", ValueType.TEXT,
+ new MetaItem<>(MetaItemType.READ_ONLY),
+ new MetaItem<>(MetaItemType.AGENT_LINK_CONFIG, new ValueType.ObjectMap() {{
+ putAll(Map.of(
+ "uplinkPort", 2,
+ "valueFilterJsonPath", "$.uplink_message.decoded_payload.Errors"
+ ));
+ }})
+ );
public static final AttributeDescriptor<Boolean> SWITCH = new AttributeDescriptor<>("switch", ValueType.BOOLEAN,
new MetaItem<>(MetaItemType.AGENT_LINK_CONFIG, new ValueType.ObjectMap() {{
putAll(Map.of(
diff --git a/test/src/test/groovy/org/openremote/test/protocol/lorawan/chirpstack/ChirpStackTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/lorawan/chirpstack/ChirpStackTest.groovy
index 143bdbf59..d5d6b3ae5 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/lorawan/chirpstack/ChirpStackTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/lorawan/chirpstack/ChirpStackTest.groovy
@@ -45,6 +45,7 @@ import org.openremote.agent.protocol.lorawan.chirpstack.ChirpStackProtocol
import org.openremote.manager.agent.AgentService
import org.openremote.manager.asset.AssetProcessingService
import org.openremote.manager.asset.AssetStorageService
+import org.openremote.model.asset.Asset
import org.openremote.model.asset.AssetTreeNode
import org.openremote.model.asset.agent.Agent
import org.openremote.model.asset.agent.AgentResource
@@ -52,6 +53,7 @@ import org.openremote.model.asset.agent.ConnectionStatus
import org.openremote.model.attribute.AttributeEvent
import org.openremote.model.file.FileInfo
import org.openremote.model.query.AssetQuery
+import org.openremote.model.value.AttributeDescriptor
import org.openremote.test.ManagerContainerTrait
import spock.lang.Shared
import spock.lang.Specification
@@ -215,7 +217,8 @@ class ChirpStackTest extends Specification implements ManagerContainerTrait {
fPort: UPLINK_PORT,
object: [
Temperature: TEMPERATURE_VALUE,
- Humidity: HUMIDITY_VALUE
+ Humidity: HUMIDITY_VALUE,
+ Errors: ["error1", "error2"]
]
]
mqttClient.publishWith()
@@ -226,8 +229,12 @@ class ChirpStackTest extends Specification implements ManagerContainerTrait {
then: "asset attribute values should be updated"
conditions.eventually {
def asset = assetStorageService.find(new AssetQuery().attributeValue(ATTRIBUTE_NAME_DEV_EUI, DEV_EUI_1.toUpperCase()))
- assert asset.getAttribute(TEMPERATURE).flatMap {it.value}.map {it == TEMPERATURE_VALUE}.orElse(false)
- assert asset.getAttribute(RELATIVE_HUMIDITY).flatMap {it.value}.map {it == HUMIDITY_VALUE}.orElse(false)
+ assertAttribute(asset, TEMPERATURE, TEMPERATURE_VALUE)
+ assertAttribute(asset, RELATIVE_HUMIDITY, HUMIDITY_VALUE)
+ assertAttribute(asset, ERRORS) { value ->
+ assert value.startsWith("[") && value.endsWith("]")
+ assert value.contains("error1") && value.contains("error2")
+ }
}
when: "an asset attribute value is written"
@@ -325,7 +332,8 @@ class ChirpStackTest extends Specification implements ManagerContainerTrait {
fPort: UPLINK_PORT,
object: [
Temperature: TEMPERATURE_VALUE,
- Humidity: HUMIDITY_VALUE
+ Humidity: HUMIDITY_VALUE,
+ Errors: ["error1", "error2"]
]
]
mqttClient.publishWith()
@@ -336,8 +344,12 @@ class ChirpStackTest extends Specification implements ManagerContainerTrait {
then: "asset attribute values should be updated"
conditions.eventually {
def asset = assetStorageService.find(new AssetQuery().attributeValue(ATTRIBUTE_NAME_DEV_EUI, DEV_EUI_1.toUpperCase()))
- assert asset.getAttribute(TEMPERATURE).flatMap {it.value}.map {it == TEMPERATURE_VALUE}.orElse(false)
- assert asset.getAttribute(RELATIVE_HUMIDITY).flatMap {it.value}.map {it == HUMIDITY_VALUE}.orElse(false)
+ assertAttribute(asset, TEMPERATURE, TEMPERATURE_VALUE)
+ assertAttribute(asset, RELATIVE_HUMIDITY, HUMIDITY_VALUE)
+ assertAttribute(asset, ERRORS) { value ->
+ assert value.startsWith("[") && value.endsWith("]")
+ assert value.contains("error1") && value.contains("error2")
+ }
}
when: "an asset attribute value is written"
@@ -363,6 +375,26 @@ class ChirpStackTest extends Specification implements ManagerContainerTrait {
}
}
+ <T> void assertAttribute(Asset asset, AttributeDescriptor<T> descriptor, T expectedValue) {
+ def attrOpt = asset.getAttribute(descriptor)
+ assert attrOpt.isPresent() : "Attribute ${descriptor} is missing"
+
+ def valueOpt = attrOpt.get().value
+ assert valueOpt.isPresent() : "Value for attribute ${descriptor} is missing (it's empty)"
+
+ assert valueOpt.get() == expectedValue : "Expected ${expectedValue} but found ${valueOpt.get()}"
+ }
+
+ <T> void assertAttribute(Asset asset, AttributeDescriptor<T> descriptor, Closure validation) {
+ def attrOpt = asset.getAttribute(descriptor)
+ assert attrOpt.isPresent() : "Attribute ${descriptor} is missing"
+
+ def valueOpt = attrOpt.get().value
+ assert valueOpt.isPresent() : "Value for attribute ${descriptor} is missing (it's empty)"
+
+ validation(valueOpt.get())
+ }
+
static class ChirpStackGrpcServer {
private final int port
private io.grpc.Server server
diff --git a/test/src/test/groovy/org/openremote/test/protocol/lorawan/tts/TheThingsStackTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/lorawan/tts/TheThingsStackTest.groovy
index 6cf13b658..56aaaaad7 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/lorawan/tts/TheThingsStackTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/lorawan/tts/TheThingsStackTest.groovy
@@ -42,6 +42,7 @@ import org.openremote.agent.protocol.lorawan.tts.TheThingsStackProtocol
import org.openremote.manager.agent.AgentService
import org.openremote.manager.asset.AssetProcessingService
import org.openremote.manager.asset.AssetStorageService
+import org.openremote.model.asset.Asset
import org.openremote.model.asset.AssetTreeNode
import org.openremote.model.asset.agent.Agent
import org.openremote.model.asset.agent.AgentResource
@@ -49,6 +50,7 @@ import org.openremote.model.asset.agent.ConnectionStatus
import org.openremote.model.attribute.AttributeEvent
import org.openremote.model.file.FileInfo
import org.openremote.model.query.AssetQuery
+import org.openremote.model.value.AttributeDescriptor
import org.openremote.test.ManagerContainerTrait
import spock.lang.Shared
import spock.lang.Specification
@@ -239,7 +241,8 @@ class TheThingsStackTest extends Specification implements ManagerContainerTrait
f_port: UPLINK_PORT,
decoded_payload: [
Temperature: TEMPERATURE_VALUE,
- Humidity: HUMIDITY_VALUE
+ Humidity: HUMIDITY_VALUE,
+ Errors: ["error1", "error2"]
]
]
]
@@ -251,8 +254,12 @@ class TheThingsStackTest extends Specification implements ManagerContainerTrait
then: "asset attribute values should be updated"
conditions.eventually {
def asset = assetStorageService.find(new AssetQuery().attributeValue(ATTRIBUTE_NAME_DEV_EUI, DEV_EUI_1.toUpperCase()))
- assert asset.getAttribute(TEMPERATURE).flatMap {it.value}.map {it == TEMPERATURE_VALUE}.orElse(false)
- assert asset.getAttribute(RELATIVE_HUMIDITY).flatMap {it.value}.map {it == HUMIDITY_VALUE}.orElse(false)
+ assertAttribute(asset, TEMPERATURE, TEMPERATURE_VALUE)
+ assertAttribute(asset, RELATIVE_HUMIDITY, HUMIDITY_VALUE)
+ assertAttribute(asset, ERRORS) { value ->
+ assert value.startsWith("[") && value.endsWith("]")
+ assert value.contains("error1") && value.contains("error2")
+ }
}
when: "an asset attribute value is written"
@@ -353,7 +360,8 @@ class TheThingsStackTest extends Specification implements ManagerContainerTrait
f_port: UPLINK_PORT,
decoded_payload: [
Temperature: TEMPERATURE_VALUE,
- Humidity: HUMIDITY_VALUE
+ Humidity: HUMIDITY_VALUE,
+ Errors: ["error1", "error2"]
]
]
]
@@ -365,8 +373,12 @@ class TheThingsStackTest extends Specification implements ManagerContainerTrait
then: "asset attribute values should be updated"
conditions.eventually {
def asset = assetStorageService.find(new AssetQuery().attributeValue(ATTRIBUTE_NAME_DEV_EUI, DEV_EUI_1.toUpperCase()))
- assert asset.getAttribute(TEMPERATURE).flatMap {it.value}.map {it == TEMPERATURE_VALUE}.orElse(false)
- assert asset.getAttribute(RELATIVE_HUMIDITY).flatMap {it.value}.map {it == HUMIDITY_VALUE}.orElse(false)
+ assertAttribute(asset, TEMPERATURE, TEMPERATURE_VALUE)
+ assertAttribute(asset, RELATIVE_HUMIDITY, HUMIDITY_VALUE)
+ assertAttribute(asset, ERRORS) { value ->
+ assert value.startsWith("[") && value.endsWith("]")
+ assert value.contains("error1") && value.contains("error2")
+ }
}
when: "an asset attribute value is written"
@@ -391,6 +403,26 @@ class TheThingsStackTest extends Specification implements ManagerContainerTrait
}
}
+ <T> void assertAttribute(Asset asset, AttributeDescriptor<T> descriptor, T expectedValue) {
+ def attrOpt = asset.getAttribute(descriptor)
+ assert attrOpt.isPresent() : "Attribute ${descriptor} is missing"
+
+ def valueOpt = attrOpt.get().value
+ assert valueOpt.isPresent() : "Value for attribute ${descriptor} is missing (it's empty)"
+
+ assert valueOpt.get() == expectedValue : "Expected ${expectedValue} but found ${valueOpt.get()}"
+ }
+
+ <T> void assertAttribute(Asset asset, AttributeDescriptor<T> descriptor, Closure validation) {
+ def attrOpt = asset.getAttribute(descriptor)
+ assert attrOpt.isPresent() : "Attribute ${descriptor} is missing"
+
+ def valueOpt = attrOpt.get().value
+ assert valueOpt.isPresent() : "Value for attribute ${descriptor} is missing (it's empty)"
+
+ validation(valueOpt.get())
+ }
+
static class TheThingsStackGrpcServer {
final int port
final EventsService eventsService