I'm trying to create a tag group for some of my instruments to store metadata about the instruments, not the actual instrument data. I used ProviderConfiguration
and ManagedTagProvider
in GatewayContext
as shown below and was able to create the tags. However, when the Gateway was restarted, these tags disappeared. Is this the correct way to create them? Also, internally, we decided to store these tags in a database. We started testing with SQLite, which comes default with Ignition.
Question 1: Is it normal for the tags to disappear after a Gateway restart?
Question 2: Can these tags be stored and retrieved even after a Gateway restart?
Question 3: Is it better to store these tags in a database like SQL?
Question 4: Is there any example of how this can be achieved?
public class GatewayHook extends AbstractGatewayModuleHook {
private final Logger logger = LoggerFactory.getLogger(getClass());
private ManagedTagProvider deviceTagProvider;
private GatewayContext gatewayContext;
private final DeviceRegistryGatewayScript deviceRegistryGatewayScript = new DeviceRegistryGatewayScript();
@Override
public void setup(GatewayContext gatewayContext) {
logger.info("setup()");
this.gatewayContext = gatewayContext;
ProviderConfiguration configuration = new ProviderConfiguration("Test-11");
configuration.setAllowTagCustomization(true);
configuration.setPersistTags(false);
configuration.setPersistValues(false);
configuration.setAttribute(TagProviderMeta.FLAG_HAS_OPCBROWSE, false);
deviceTagProvider = gatewayContext.getTagManager().getOrCreateManagedProvider(configuration);
deviceRegistryGatewayScript.setDeviceTagProvider(deviceTagProvider);
deviceRegistryGatewayScript.setGatewayContext(gatewayContext);
}
this.deviceTagProvider.configureTag("Devices/instrument-1/" + deviceName + "/Device-ID", DataType.String);
this.deviceTagProvider.configureTag("Devices/instrument-1/" + deviceName + "/EndPoint", DataType.String);
this.deviceTagProvider.configureTag("Devices/instrument-1/" + deviceName + "/Floor", DataType.String);
// Actual values are updated here
this.deviceTagProvider.updateValue("Devices/instrument-1/" + deviceName + "/Device-ID", deviceID, QualityCode.Good);
this.deviceTagProvider.updateValue("Devices/instrument-1/" + deviceName + "/Endpoint", ipAddress+":"+port, QualityCode.Good);
this.deviceTagProvider.updateValue("Devices/instrument-1/" + deviceName + "/Floor", floor, QualityCode.Good);