Skip to content

Commit

Permalink
Store Payload Configuration Option
Browse files Browse the repository at this point in the history
Add option to store payloads of devices as TeltonikaDataHandler
  • Loading branch information
pankalog committed Jan 17, 2024
1 parent 3936194 commit 0f84d2c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,11 @@ public void onPublish(RemotingConnection connection, Topic topic, ByteBuf body)
}

//TODO: If specified in configuration, store payloads
if(false){
Attribute<String> payloadAttribute = new Attribute<>("payload", ValueType.TEXT, payloadContent);
if(getConfig().getStorePayloads().getValue().orElseThrow()){
TeltonikaDataPayload payload = new ObjectMapper().readValue(payloadContent, TeltonikaDataPayload.class);
Attribute<TeltonikaDataPayload> payloadAttribute = new Attribute<>("payload", CustomValueTypes.TELTONIKA_PAYLOAD, payload);
payloadAttribute.addMeta(new MetaItem<>(MetaItemType.STORE_DATA_POINTS, true));
payloadAttribute.setTimestamp(attributes.get(CarAsset.LAST_CONTACT).orElseThrow().getValue().orElseThrow().getTime());
attributes.add(payloadAttribute);
}

Expand Down Expand Up @@ -683,6 +685,7 @@ private void initializeConfigurationAssets(){
rootConfig.setDefaultModelNumber("FMC003");
rootConfig.setCommandTopic("sendToDevice");
rootConfig.setResponseTopic("response");
rootConfig.setStorePayloads(false);

fmc003.setModelNumber("FMC003");
ObjectMapper mapper = new ObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TeltonikaConfigurationAsset extends Asset<TeltonikaConfigurationAss
public static final AttributeDescriptor<String[]> WHITELIST = new AttributeDescriptor<>("deviceIMEIWhitelist", ValueType.TEXT.asArray()).withOptional(true);
public static final AttributeDescriptor<Boolean> ENABLED = new AttributeDescriptor<>("Enabled", ValueType.BOOLEAN);
public static final AttributeDescriptor<Boolean> CHECK_FOR_IMEI = new AttributeDescriptor<>("CheckForValidIMEI", ValueType.BOOLEAN);
public static final AttributeDescriptor<Boolean> STORE_PAYLOADS = new AttributeDescriptor<>("StorePayloads", ValueType.BOOLEAN);
public static final AttributeDescriptor<String> DEFAULT_MODEL_NUMBER = new AttributeDescriptor<>("defaultModelNumber", ValueType.TEXT);
public static final AttributeDescriptor<String> COMMAND = new AttributeDescriptor<>("command", ValueType.TEXT);
public static final AttributeDescriptor<String> RESPONSE = new AttributeDescriptor<>("response", ValueType.TEXT)
Expand Down Expand Up @@ -63,4 +64,8 @@ public TeltonikaConfigurationAsset setResponseTopic(String value){
return this;
}

public TeltonikaConfigurationAsset setStorePayloads(Boolean value) {
getAttributes().getOrCreate(STORE_PAYLOADS).setValue(value);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,8 @@ public Attribute<String> getCommandAttribute(){
public Attribute<String> getResponseAttribute(){
return getMasterAsset().getAttribute(TeltonikaConfigurationAsset.RESPONSE).get();
}

public Attribute<Boolean> getStorePayloads(){
return getMasterAsset().getAttribute(TeltonikaConfigurationAsset.STORE_PAYLOADS).get();
}
}

0 comments on commit 0f84d2c

Please sign in to comment.