cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

MQTT Template configuration not inherited in Things

jborovský
1-Newbie

MQTT Template configuration not inherited in Things

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

1 ACCEPTED SOLUTION

Accepted Solutions
drichter
14-Alexandrite
(To:jborovský)

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;

View solution in original post

4 REPLIES 4
CRArko
17-Peridot
(To:jborovský)

Hello, Jaroslav.

Could you export the template you're using and attach it here?

Thanks,

-- Craig A.

I could.

drichter
14-Alexandrite
(To:jborovský)

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

        });

    }

Top Tags