Skip to main content
6-Contributor
February 6, 2024
Solved

how to listen a thing property value change ?

  • February 6, 2024
  • 1 reply
  • 945 views

hello,can i please ask how to listen on a thing property value change and coding in this thing service  to save new value  to db?

Best answer by Rocko

You would use a thing subscription for this. There is a tab called subscription in the Thing View in Composer. You can add a subscription there listening to the DataChange Event of a property of a thing. In the subscription, you can write code to perform, or call another service. Note the subscription has to be active to execute.

The property value is automatically saved to the DB, if the property has the "persist" flag. If you also want to record previous entries, you need to set the "log" flag on the property and provide a value stream in the thing configuration (on tab General Information).

 

If you want to write the value additionally to an external DB, you can run a SQL Command service from a DatabaseThing to do the INSERT in your subscription.

 

References:

https://community.ptc.com/t5/IoT-Tips/Thing-Subscription/ta-p/817695

https://community.ptc.com/t5/IoT-Tips/Implement-Services-Events-and-Subscriptions-Guide-Part-1/ta-p/837216#toc-hId-1134107572

https://support.ptc.com/help/thingworx/platform/r9/en/#page/ThingWorx/Help/ModelandDataBestPractices/UsingJDBCasthePersistenceProvider.html

 

1 reply

Rocko
Rocko19-TanzaniteAnswer
19-Tanzanite
February 6, 2024

You would use a thing subscription for this. There is a tab called subscription in the Thing View in Composer. You can add a subscription there listening to the DataChange Event of a property of a thing. In the subscription, you can write code to perform, or call another service. Note the subscription has to be active to execute.

The property value is automatically saved to the DB, if the property has the "persist" flag. If you also want to record previous entries, you need to set the "log" flag on the property and provide a value stream in the thing configuration (on tab General Information).

 

If you want to write the value additionally to an external DB, you can run a SQL Command service from a DatabaseThing to do the INSERT in your subscription.

 

References:

https://community.ptc.com/t5/IoT-Tips/Thing-Subscription/ta-p/817695

https://community.ptc.com/t5/IoT-Tips/Implement-Services-Events-and-Subscriptions-Guide-Part-1/ta-p/837216#toc-hId-1134107572

https://support.ptc.com/help/thingworx/platform/r9/en/#page/ThingWorx/Help/ModelandDataBestPractices/UsingJDBCasthePersistenceProvider.html

 

6-Contributor
February 6, 2024

ok,thank you!