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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Streams and Parameters

victorgan
1-Visitor

Streams and Parameters

Hi,

I have a few questions I'm hoping to get some help with:

  1. Playing around with streams and would like to know how to retrieve database values from a table and store it into a stream. I suspect I would need some form of Timer Service to constantly query for values. I would then use those values in a chart between certain time ranges.

2. How would I pass values to a contained mashup that is dynamically bound?

Thanks.

16 REPLIES 16

Hi,

I'm still having trouble with these two questions. Are these possible to perform within ThingWorx?

Any help would be appreciated. Thanks.

Victor,

What is your reason for wanting to store this data into a Stream?

To answer your second question, you'll do the following:
  • Bind inputs to each Mashup Parameter.
  • Remove the Mashup you set in step 2 and repeat steps 2-4 for each Mashup.
  • Once you're done, remove the Mashup you set in step 2 and verify that the Mashup is still dynamically bound.
  • Setup Mashup Parameters for each Mashup you'll be displaying in the Contained Mashup widget.


Hi Adam,

Thanks, that worked for setting up parameters on a dynamically bound mashup.

For the stream, I want to set up a stream that queries and records values in a database at a set interval. In essence, if a database is not historizing the data points, be able to perform the historization within Thingworx. If there are other alternatives to the stream, please let me know.

While a database that historizes data would be preferable, it is certainly possible to do what you've described using a Stream. You can use a Timer-based Thing or Scheduler-based Thing to schedule an Event to fire at a particular interval and create a Subscription to the Event.

Hi Adam,

Still trying to wrap my head around it. I've created a stream (TestDBStream) and have associated a data shape to it (TestDBShape), which contains all my field definitions that I want. I have also created a timer (TestDBTimer), keeping the defaults and configuration rate of 60 seconds.

Where I am stuck is at the event/subscription. Were you saying I can create an event/subscription on the Timer or should this be done on my database thing? In any case, I attempted to create an event (TestDBRetrieveValues) on the timer and was in the process of adding a subscription to fire the event (TestDBRetrieveValues), but I'm not sure what else needs to be done.

Looking at the subscription on the timer, I feel the source should be my database thing and I was looking at the "Add Stream Entry" script, but not sure if I was going down the right path or what needed to be configured to have the timer retrieve values from the database and store it into the stream.

Any help would be appreciated. Thanks.

Victor,

TestDBTimer has it's own Event, Timer, which fires at the interval you set in the Configuration section. You'll want to create a Subscription to this Event. Since you'll be storing this data in a Stream, I would create a Subscription to the Timer's Event on the Stream and a Services on the Stream (which you'll call from the Subscription) to retrieve values from the database and add a Stream entry.

Hi Adam,

Thanks for the guidance. I have a better understanding conceptually. I've created a subscription on the stream to have the source be the TestDBTimer. I understand that when the timer hits the interval, it should trigger my service on the stream.

The service I am to create on the Stream to retrieve the values from the database, do you have a tutorial on the configuration parameters or what snippets I am to use? I created a service and went to the Entities tab to find my Database Thing and added a service from it. So it added a snippet: var result = Things["TestConnectSQL"].RetrieveTestInfoData(); Testing it throws an error of invalid service name.

And within my Timer Subscription on the stream, how do I configure the snippet to call my service on the stream? I went to the Me tab and added in the service I created, which added in a snippet: var result = me.TestDBRetrieveService();

Sorry for all the questions, new to this and trying to test out the capabilities.

Victor,

Make sure you have saved your RetrieveTestInfoData() Service and saved the Thing on which you created RetrieveTestInfoData(). Since Subscriptions execute asynchronously, you will not return anything from your Subscription. It would simply be – me.TestDBRetrieveService() – no need to assign the output (if any) to result.

Hi Adam,

Thanks for the info, I'll look into doing what you mentioned and let you know.

Thanks!

Hi Adam,

The stream is working now and picking up data. Thanks again for all your help!

rajgs
1-Visitor
(To:victorgan)

Hi Adam,

I have followed the steps mentioned by you.

TestDBTimer has it's own

Event

, Timer, which fires at the interval you set in the Configuration section. You'll want to create a

Subscription

 to this

Event

. Since you'll be storing this data in a

Stream

, I would create a

Subscription

 to the Timer's

Event

 on the

Stream

 and

 

a

Services

 on the

Stream

 (which you'll call from the

Subscription

) to retrieve values from the database and add a

Stream

 entry.

What is Add a Stream entry..?

How do I check the values in the stream?

When I call the Generic service "GetStreamData"  of Stream Thing, I get only the coloumn names and not the data.Please help.

 

adam11
7-Bedrock
(To:rajgs)

Hi Raj,

Victor wanted to query a database at a set interval and store the results in a Stream. Adding a Stream entry refers to the Services available on Streams for adding data (e.g., AddStreamEntries, AddStreamEntry). After you've added entries to the Stream, you can query the data by using Services like QueryStreamEntriesWithData.

rajgs
1-Visitor
(To:victorgan)

Hi Adam,

Thanks for the comments. I have followed the below steps and still data is not picked up in stream.

  1. I have created a subscription on the stream to TestDBTimer event with time 60 secs, and snippet: me.TestDBRetrieveService()
  2. stream service TestDBRetrieveService() code snippet:  var result = Things ["TestConnectSQL"].RetrieveTestInfoData()

 

 I am expecting to receive the data from DB and to be added to stream. But the data from DB is not picked up in the stream.

Note: RetrieveTestInfoData()  is working properly and returning a row of DB data. 

paic
12-Amethyst
(To:rajgs)

What does your actual code snippet look like that Adds the data to the Stream (besides the retrieval of your data)?

rajgs
1-Visitor
(To:victorgan)

Hi Adam & PaiC,

Thanks for pointing out. The stream is working now and picking up data. I want to remove all the entries in the Stream but  only  "DeleteStreamEntry" service is available. I am able to delete only one entry corresponding to streamEntryID.kindly let me know to remove all entries in the stream.

That can be done with PurgeStreamEntries.​ You will be asked for the time interval from which all entries will be removed.

Announcements


Top Tags