fastiot_core_services.time_series package
Module for storing and retrieving time series data
This Service is intended for saving data and the requesting of historical data.
If you aren’t using a docker-compose file generated with your project, you must also set variables defined in
fastiot.env.env.InfluxDBEnv
to connect to the InfluxDB.
Some adjustments to this service can be done using fastiot_core_services.time_series.env.TimeSeriesConstants
.
By default, this module stores any message written under “Thing”. The data is stored in InfluxDB and has the format:
You can request the data with an fastiot.msg.hist.HistObjectReq
with topic things
. By default, it returns
the oldest 20 datasets of the last 30 days. When creating your own query, you must specify a time range.
The response will be returned as an fastiot.msg.hist.HistObjectResp
The Data stored in “values” has the format: [thing1, thing2]
where thing is formatted as a dictionary.
A short example:
from fastiot.util.object_helper import parse_object_list
from fastiot.msg import Thing, HistObjectReq, HistObjectResp
my_query = HistObjectReq() # Create a request/ query
result_dict: HistObjectResp = await self.broker_connection.request(my_query) # Send request to broker
result = parse_object_list(result_dict.values, Thing) # Parse returned dictionary to List[Thing]
If no data is found, the error code (fastiot.msg.hist.HistObjectResp.error_code
) is 1.
Submodules
fastiot_core_services.time_series.env module
- class fastiot_core_services.time_series.env.TimeSeriesConstants[source]
- property subscribe_subject: str
- FASTIOT_TIME_SERIES_SUBSCRIBE_SUBJECT
Set the subject to listen to. It defaults to
>
meaning everything belowThing
. For more details about how to specify (wildcard) subjects please refer to the nats.io documentation at https://docs.nats.io/nats-concepts/subjects If you want to listen to a specific topic you can changeFASTIOT_TIME_SERIES_SUBSCRIBE_SUBJECT
to your value, but you can only listen to subtopics of Things. So if you want to listen to Thing.machine_1 you changeFASTIOT_TIME_SERIES_SUBSCRIBE_SUBJECT
to “machine_1”. It is not possible to listen to “not_Thing.machine1”
- property request_subject: str
- FASTIOT_TIME_SERIES_REPLY_SUBJECT
Sets the subject the time series module will listen on for requests with
fastiot.msg.hist.HistObjectReq
. It defaults tothings
.If you have only one time series storage this default should be fine for you. Using this is especially helpfully when running multiple time series storages listening on different subjects defined with
FASTIOT_TIME_SERIES_SUBSCRIBE_SUBJECT
.