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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

MQTT Template configuration not inherited in Things

jborovský
1-Visitor

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

ACCEPTED SOLUTION

Accepted Solutions
drichter
15-Moonstone
(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
15-Moonstone
(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

        });

    }

Announcements


Top Tags