Reputation: 21
I am using Thingworx Platform for IoT. I have connected Thingworx and SQL. I have created 2 database SQL services of the type query and command. Also I have created two tables named Temperature
and Humidity
.
I am getting Temperature
and Humidity
values in Thingworx platform. But I am unable to send it to the database, can anyone help? How can I call the properties in the command service?
Database.Conf sql Command code
insert into INFO(Temperature)
values ([[]]);
Thing-Test Subscription Code
var params={Temp:me.Temp_Prop,Hum:me.Hum_Prop};
var result=Things["DatabaseConf"].InsertRecords(params);
Upvotes: 0
Views: 569
Reputation: 363
You need an additionnal service of type javascript where you can retrieve the properties, using me.property and invoke the sql services. You can add input parameters to the sql services and use them like this: [[inputParameter]]. In your example that should look like:
insert into INFO(Temperature)
values ([[temp]],[[Hum]]);
If you use the arrow on the right of your input parameter, ThingWorx will write it for you in the proper way already.
Upvotes: 0
Reputation: 61
When you create a service in ThingWorx you can select the type: "query" is a valid option when you have to insert or retrieve values from a database. You can test the query on SQl and copy/paste into the service. Check if the thing that connects you to the DataBase has the property "isConnected" equal to True. Maybe you should also think about how to trigger the Insert service, you can use ValueChange triggers or a Periodic Trigger.
Upvotes: 0