Timeseries Data
Timeseries Data
You can update Asset / Data Stream data values on the Kelvin Cloud from the Kelvin SmartApp™.
Structure
Define Data Stream Names
In order to publish an output Data Message, the first requirement is to add the intended Data Stream names to the outputs to the app.yaml as follows:
app:
type: kelvin
kelvin:
outputs:
- data_type: number
name: motor_temperature_fahrenheit
- data_type: boolean
name: motor_error
- data_type: string
name: motor_error_description
- data_type: object
name: gps_data
Define Asset Names
The Asset name can only be related to any Assets associated with the Kelvin SmartApp™ workload.
Note
Any attempt to write to Assets not associated with the Kelvin SmartApp™ workload will be dropped and an error recorded in the logs.
Timeseries Data Messages
Output (Number/Boolean/String/Object) Objects support the following attribute:
| Attribute | Required | Description |
|---|---|---|
payload |
required | Number, Boolean, String or object value, depending on the data_type |
You need to create and publish each output Data Message according to the Asset / Data Stream's data_type.
from kelvin.message import Number
from kelvin.krn import KRNAssetDataStream
(...)
# Create and Publish a Number
await app.publish(
Number(resource=KRNAssetDataStream(asset, "motor_temperature_fahrenheit"), payload=97.3)
)
from kelvin.message import Boolean
from kelvin.krn import KRNAssetDataStream
(...)
# Create and Publish a Boolean
await app.publish(
Boolean(resource=KRNAssetDataStream(asset, "motor_error"), payload=True)
)
from kelvin.message import String
from kelvin.krn import KRNAssetDataStream
(...)
# Create and Publish a String
await app.publish(
String(resource=KRNAssetDataStream(asset, "motor_error_description"), payload="Temperature is too high")
)
For objects, the payload is an arbitrary dict with any given dict structure.
from kelvin.message import String
from kelvin.krn import KRNAssetDataStream
(...)
# Create and Publish an Object
gpsd_dict = {
"latitude": 90,
"longitude": 100
}
await app.publish(
Message(
type=KMessageTypeData(primitive="object", icd="gps"),
resource=KRNAssetDataStream(asset, datastream),
payload=gps_dict,
)
)
