Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

There are three types of Models that can be defined at the time of creating models for your IoT applications. The three models are:

  • DataModel
  • ThingModel
  • AppModel

See Models for details.

Model lifecycle consists of three steps

  • Definition - Models are defined either using TQLStudio Model Editor or any IDE of your choice. Modeling Language (Thing Definition Language) is essential to define models.
  • Deploy - As part of a deployable unit within TQLEngine's package file. Models definitions are made part of SffTqlFacet Facet type.
  • Query - Querying of model consists of CRUD as well as Subscription (and notification).

Model Instances

Once models are defined and deployed their schematic layout is persisted in Storage (TQL Cache) defined at the time of the deployment. Note that even though models are persisted in SQL type of storage that data is highly unstructured and stored in proprietary format.

Before Models can be queried using Find - Models must be initialized or populated with data. The result of model creation is called Model Instances.

For example: Here is the definition of a ThingModel - PhidgetSensorModel that combines PhidgetSensorFacet. 

Definition

PhidgetSensor Thing Model
<ThingFacet Name="PhidgetSensorFacet">
  <Integer Name="SensorValue" Update="auto" KnownBy="PhidgetSensorAction"/>
  <String Name="SensorURL" Default="phid://"/>
  <String Name="SensorInterfaceIndex"/>
  <String Name="SensorType"/>
  <String Name="SensorInterfaceType"/>
  <String Name="SensorValueFormat"/>
  <String Name="Simulated"/>
</ThingFacet>
<ThingModel Name="PhidgetSensorModel" Combines="PhidgetSensorFacet">
  <Sid Name="phidId"/>
</ThingModel>

Deploy and Create:

The instances of PhidgetSensorModel is created using Create TQL Query. 

Create PhidgetSensor ThingModel Instance
<Query>
  <Create>
    <PhidgetSensors>
      <SensorURL>phid://</SensorURL>
      <SensorType>Rotation</SensorType>
      <SensorInterfaceType>PhidgetInterfaceKit</SensorInterfaceType>
      <SensorValueFormat>Raw</SensorValueFormat>
      <SensorInterfaceIndex>0</SensorInterfaceIndex>
      <SensorValue value="$Null()" version="1"/>
      <Simulated>true</Simulated>
    </PhidgetSensors>
  </Create>
</Query>

The Result of Model Instance Creation is: 

Note that there is Status returned for every attribute that gets created.

Create PhidgetSensor ThingModel Instance Result
<Create Status="Success">
  <PhidgetSensors>
    <phidId>KNUBPHLOAAAAUAABA6EJCI75</phidId>
    <SensorValue Status="Success+Created:1:1457740291438;" Value="" Version="1"/>
    <SensorURL Status="Success+Created:1:1457740291442;" Value="phid://" Version="1"/>
    <SensorInterfaceIndex Status="Success+Created:1:1457740291443;" Value="0" Version="1"/>
    <SensorType Status="Success+Created:1:1457740291444;" Value="Rotation" Version="1"/>
    <SensorInterfaceType Status="Success+Created:1:1457740291444;" Value="PhidgetInterfaceKit" Version="1"/>
    <SensorValueFormat Status="Success+Created:1:1457740291445;" Value="Raw" Version="1"/>
    <Simulated Status="Success+Created:1:1457740291445;" Value="true" Version="1"/>
  </PhidgetSensors>
</Create>

Find Model Instances

After Model Instances are created, you can Read them using Find Query with constraints.

Find PhidgetSensor ThingModel Instance
<Query>
  <Find format="all">
    <PhidgetSensors>
      <SensorURL ne =""/>
    </PhidgetSensors>
  </Find>
</Query>

Find Query Result

Find PhidgetSensor ThingModel Instance
<Find Status="Success" Format="all">
  <Result>
    <PhidgetSensors QName="SimpleModel.MyModels.PhidgetSensors">
      <phidId>KNUBPHLOAAAAUAABA6EJCI75</phidId>
      <SensorValue Value="" Known="60" Version="1" Timestamp="1457740291438" DateTime="2016-03-11 15:51:31.438" QName="SimpleModel.MyModels.PhidgetSensors.SensorValue" FName="SensorValue"/>
      <SensorURL Value="phid://" Known="phid://" Version="1" Timestamp="1457740291442" DateTime="2016-03-11 15:51:31.442" QName="SimpleModel.MyModels.PhidgetSensors.SensorURL" FName="SensorURL"/>
      <SensorInterfaceType Value="PhidgetInterfaceKit" Known="PhidgetInterfaceKit" Version="1" Timestamp="1457740291444" DateTime="2016-03-11 15:51:31.444" QName="SimpleModel.MyModels.PhidgetSensors.SensorInterfaceType" FName="SensorInterfaceType"/>
      <Simulated Value="true" Known="true" Version="1" Timestamp="1457740291445" DateTime="2016-03-11 15:51:31.445" QName="SimpleModel.MyModels.PhidgetSensors.Simulated" FName="Simulated"/>
      <SensorInterfaceIndex Value="0" Known="0" Version="1" Timestamp="1457740291443" DateTime="2016-03-11 15:51:31.443" QName="SimpleModel.MyModels.PhidgetSensors.SensorInterfaceIndex" FName="SensorInterfaceIndex"/>
      <SensorType Value="Rotation" Known="Rotation" Version="1" Timestamp="1457740291444" DateTime="2016-03-11 15:51:31.444" QName="SimpleModel.MyModels.PhidgetSensors.SensorType" FName="SensorType"/>
      <SensorValueFormat Value="Raw" Known="Raw" Version="1" Timestamp="1457740291445" DateTime="2016-03-11 15:51:31.445" QName="SimpleModel.MyModels.PhidgetSensors.SensorValueFormat" FName="SensorValueFormat"/>
    </PhidgetSensors>
  </Result>
</Find>

Automatically generated System Attributes

System Attribute Name
Description
Persisted

Query

Constraint?

Version

Version number of the attribute. This number is automatically incremented each time the value changes.

No historical data is persisted. Only the last value is persisted.

Yes

No. You can request the value

using Format on <Find>

ValueThe value of the attribute is stored in "Value". This is specified by user at time of create/save queryYesYes
TimestampUnix epoch time at the time (in millisecond) of the attribute creation. For example: Timestamp value
1457663102004 is same as Fri, 11 Mar 2016 02:25:02 GMT

Note that this is only the "Create" timestamp. If attributes are updated their timestamp do not change.

YesNo
QName

Fully qualified name of the attribute. <NamSpace>.<Domain>.<ModelName>.<AttributeName>. For example

SimpleModel.MyModels.VendorInfo.vendorName given that VendorInfo is defined within

Namespace - SimpleModel, with Domain as MyModels and DataModel Name as VendorInfo

YesNo
Known

Applicable to ThingFacet/AppFacet. Known is the value that is set within the Action. Known can not be

set using Create / Update TQL Query by the user.

YesNo
FNameGiven name of the attribute name.YesNo
DatetimeFormatted data time value of the attribute creation. For example:
2016-03-10 18:25:02.004 Note that is is only the "Create" Datetime. If attributes are

updated their datetime value do not change.

YesNo
StatusThis is transient attribute returned as part of the result of TQL Create/Save, Update and Delete operationsNoNo.

 

 

  • No labels