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

The community will undergo maintenance on October 16th at 10:00 PM PDT and will be unavailable for up to one hour.

Methods for Data Storage Part 3

No ratings

 

 

Step 3: Streams (cont.)

Store to Stream

Now that the Stream, the Thing (and its Properties), and the Thing's Service are all in place, we can execute the Service (along with some Property changes) to demonstrate that the values are getting archived externally to the Stream.

  1. At the top, click Properties and Alerts.

    • Note the previously-created Index_Property and Value_Property.

      Stream27.png
     
  2. For Index_Property's Value column, click the "pencil" icon for Set value of property.

    Stream28.png
     
  3. In the slide-out on the right, enter 1.

    Stream29.png
     
  4. At the top-right, click the "Check" button for Set.

  5. For Value Property, click the "Pencil" icon for Set value of property.

    Stream30.png
     
  6. In the slide-out on the right, enter 10.

    Stream32.png
     
  7. At the top-right, click the "Check" button for Set.

  8. At the top, click Save.

    Stream33.png
     

With the Thing's Properties set to new values, you can now call your custom Service to store those values to the external Stream (along with an auto-generated timestamp).

  1. At the top, click Services.

    Stream34.png
     
  2. On the Add_Stream_Entry_Service line, click the "Play" button for Execute Service.

    Stream35.png
     
  3. At the bottom-right of the pop-up, click the Execute button.

    Stream36.png
     
  4. At the bottom-right, click the Done button.

    Stream37.png
     


Retrieve from Stream

To confirm that our Thing's custom Service is correctly logging our Property values, we'll now use a built-in Service of the Stream to retrieve the stored values.

This same QueryStreamEntriesWithData Service could alternately be used to populate various Mashup Widgets to view the data in a more convenient format.

  1. Return to the Test_Stream Entity.

    Steream38.png
     
  2. On the top, click Services.

    Stream39.png
     
  3. Scroll down and locate the QueryStreamEntriesWithData Service's Execute service button.

    Stream40.png
     
  4. At the bottom-right of the pop-up, click Execute.

    • Note that you should see a single entry, showing the Index_Field at 1, the Value_Field at 10, and a timestamp of when the information was pushed to the Stream.

      Stream41.png
     
  5. At the bottom-right, click Done.

To further confirm external storage to the Stream, you may repeat the previous steps to confirm additional Property Value Storage with timestamping.

Furthermore, you could create a Mashup utilizing either the Time-Series Chart or a Grid to display the data stored within the Stream.



Step 4: Data Tables

Just like with Streams, you also need a Data Shape to format a Data Table.

In this example, we'll actually use the exact same Data Shape we previously created for the Stream.

Create Data Table

Both Data Tables and Info Tables may be appropriate for your non-time-series mass data storage needs.

However, a Data Table is not tied to a Thing as an Info Table Property would be.

If your non-time-series information is coming from multiple different sources, then it would generally be appropriate to use a Data Table.

  1. On the ThingWorx Composer Browse tab, click Data Storage > Data Tables, + New.


    data65.png

  2. On the Choose Template pop-up, select DataTable, and click OK.
    data66.png
  3. In the Name field, enter Test_Data_Table

    data67.png

  4. If Project is not already set, search for and select PTCDefaultProject.

  5. In the Data Shape field, search for and select Test_Data_Shape.

    • This is the same Data Shape we previously created for the Stream. We're just reusing it for formatting the Data Table. 

  6. At the top, click Save.

    data68.png

Create Thing

Now that we have a Data Table, let's create a Thing with some Properties that we'll eventually log to the external Data Table.

  1. On the ThingWorx Composer Browse tab, click MODELING -> Things, + New.

    data70.png

  2. In the Name field, enter Data_Table_Test_Thing.

  3. If Project is not already set, search for and select PTCDefaultProject.

  4. In the Thing Template field, search for and select GenericThing.

    data71.png

  5. At the top, click Properties and Alerts.

    data72.png

  6. Click + Add.

  7. In the Name field, enter Index_Property.

  8. Change the Base Type to Integer.

  9. Check the Persistent checkbox.

    data73.png

  10. At the top, click the "Check with a +" button for Done and Add.

  11. In the Name field, enter Value_Property.

  12. Change the Base Type to Number.

  13. Check the Persistent checkbox.

    data74.png

  14. At the top-right, click the "Check" button for Done.

Create Service

We now have both a Data Table and a Thing with Properties that we want logged.

Now we need to create a Service which does the logging.

  1. At the top, click Services.

    data75.png

  2. Click + Add.

  3. In the Name field, enter Add_Data_Table_Entry_Service.

    data76.png

  4. Under New Service on the left, click the Snippets tab.

    data77.png

  5. In the Filter field, type data table.

    data78.png

  6. Expand the Stream, Blog, Data Table section.

    data79.png

    • A pop-up will open.

      Beside Add/Update Data Table, click the right arrow.

  7. data80.png

  8. In the Search Data Tables field, type test.

    data81.png

  9. Select Test_Data_Table.

    data82.png

    • Note that a section of Javascript code has now been added to the Script window.

      Click the green Insert Code Snippet button.

  10. data83.png

Modify Snippet

  1. On the 6th line of code, double-click undefined to select it.

  2. On the left, expand the Me/Entities tab.

  3. Under the Me/Entities tab, expand Properties.

    • Note that this is not the Properties and Alerts at the top of Composer

      data84.png
  4. Click the right arrow beside Value_Property.

    • Note that undefined has been replaced by me.Value_Property.

      data85.png
  5. On the 7th line of code, double-click the remaining undefined to select it.

  6. Click the right arrow beside Index_Property.

    • Note that the second undefined has been replaced by me.Index_Property.

    data86.png

     

  7. Click Done to stop editing the custom Service.

    data87.png

     

  8. At the top, click Save.

    data88.png

     

 


Click 
here to view Part 4 of this guide.

Version history
Last update:
‎Mar 07, 2023 08:37 AM
Updated by:
Labels (1)
Contributors