Local Configuration
To bootstrap the configuration of an Edge Thing Shape without any interaction with the ThingWorx Platform, you can use the “local configuration” process. This scenario occurs between the period that the edge process is started and the moment that the Edge Thing Template binds with ThingWorx Platform and queries it for an updated configuration.
Each ETS has the option to override the initialConfiguration() function. If it is overridden, then no configuration file is provided. Instead, it is created, using the infotable that the method reproduces. If this function has not been overridden, it returns a null configuration that is not persisted and prevents the functions from being called. This mechanism allows you to define a configuration while developing the ETS. You can then generate and persist the configuration to disk when making it part of an EdgeThingTemplate. Here is an example of an ETS with the initialConfiguration() overridden and the file that it generated on disk when persisted:
@ThingworxDataShapeDefinitions(dataShapes = {
@ThingworxDataShapeDefinition(name = "DemoConfiguration",fields={
@ThingworxFieldDefinition(name = "timeout",baseType = "NUMBER"),
@ThingworxFieldDefinition(name = "connectionString",baseType = "STRING")
})
})
public class ConfigurationDemoThingShape extends EdgeThingShape {
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(ConfigurationDemoThingShape.class);
public ConfigurationDemoThingShape(EdgeThingTemplate thingInstance, String identifier, boolean usesNamespace) {
super(thingInstance, identifier, usesNamespace);
}
@Override
public InfoTable initialConfiguration(){
ValueCollection defaults = new ValueCollection();
defaults.put("timeout",new NumberPrimitive(42));
defaults.put("connectionString",new StringPrimitive("http://a.sample.connection?param1=1&param2=2"));
InfoTable it = new InfoTable();
it.addRow(defaults);
it.setDataShape(getDataShapeDefinition("DemoConfiguration"));
return it;
}
}
The code above generates the following configuration file on disk:
{
"rows": [{
"connectionString": "http://a.sample.connection?param1=1&param2=2",
"timeout": 42
}],
"dataShape": {"fieldDefinitions": {
"connectionString": {
"name": "connectionString",
"aspects": {},
"description": "",
"baseType": "STRING",
"ordinal": 0
},
"timeout": {
"name": "timeout",
"aspects": {},
"description": "",
"baseType": "NUMBER",
"ordinal": 0
}
}}
}
The configuration file will be passed to all future calls to onConfigure() when the ETS starts. In addition, having a persisted file on disk enables you to modify the configuration of this ETS by just editing a file. No additional code changes are required.