Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Hi,
I am trying to create several MQTT Things( connection+subscriber +publisher) and I would like to be able to add new MQTT Things in javascript.
I ve created a MQTT Template (from MQTT) with connection to network server etc., properties, and automatic mapping from topic.
While in Template view, I can click create Thing in top right, then the configuration appears in the new Thing as well(desired).
But when creating or cloning Thing in javascript, the configurationis is not copied.
I use Thingworx 7.1.
Any ideas how to solve it or explanations?
Thank you in advance.
Jaroslav
Solved! Go to Solution.
I had the same problem. You must copy the config from mqtt to your new thing.
Create script:
// create thing
// enable thing
// restart thing
// copy the mappingtable to the new thing
var mappingTable = me.CopyMappingTable();
var params = {
configurationTable: mappingTable,
persistent: true,
tableName: "Mappings"
};
Things[Name].SetMultiRowConfigurationTable(params);
// copy the connectioninfotable to the new thing
var connectionInfoTable = me.CopyConnectionInfo();
var params = {
configurationTable: connectionInfoTable,
persistent: true,
tableName: "ConnectionInfo"
};
Things[Name].SetMultiRowConfigurationTable(params);
// restart thing again
CopyMappingTable-Service:
// return "Mappings"-table
var params = {
tableName: "Mappings"
};
// result: INFOTABLE
var connectionInfoTable = me.GetConfigurationTable(params);
result = connectionInfoTable;
CopyConnectionInfo-Service:
// return "Infotable"-table
var params = {
tableName: "ConnectionInfo"
};
// result: INFOTABLE
var mappingTable = me.GetConfigurationTable(params);
result = mappingTable;
Hello, Jaroslav.
Could you export the template you're using and attach it here?
Thanks,
-- Craig A.
I had the same problem. You must copy the config from mqtt to your new thing.
Create script:
// create thing
// enable thing
// restart thing
// copy the mappingtable to the new thing
var mappingTable = me.CopyMappingTable();
var params = {
configurationTable: mappingTable,
persistent: true,
tableName: "Mappings"
};
Things[Name].SetMultiRowConfigurationTable(params);
// copy the connectioninfotable to the new thing
var connectionInfoTable = me.CopyConnectionInfo();
var params = {
configurationTable: connectionInfoTable,
persistent: true,
tableName: "ConnectionInfo"
};
Things[Name].SetMultiRowConfigurationTable(params);
// restart thing again
CopyMappingTable-Service:
// return "Mappings"-table
var params = {
tableName: "Mappings"
};
// result: INFOTABLE
var connectionInfoTable = me.GetConfigurationTable(params);
result = connectionInfoTable;
CopyConnectionInfo-Service:
// return "Infotable"-table
var params = {
tableName: "ConnectionInfo"
};
// result: INFOTABLE
var mappingTable = me.GetConfigurationTable(params);
result = mappingTable;
Thank you for your help. Thats what I needed.
Just adding my more concise version.
Get config tables from A template to B thing
var tables = ThingTemplates.GetConfigurationTables();
var len=tables.rows.length;
for(var i=0;i<len;i++){
var row=tables.rows;
Things.SetMultiRowConfigurationTable({
configurationTable: ThingTemplates.GetConfigurationTable({tableName: row.name}),
persistent: true,
tableName: row.name
});
}