2nd Gen Temperature Sensor
A quick showcase on how to interact with our 2nd generation temperature sensor.

Overview

With the introduction of our new 2nd Generation Wireless Temperature Sensor, we have added a new inter-heartbeat sampling mode that makes it possible to sample data points between periodic heartbeats. Like our 1st generation sensors, an event is generated every periodic heartbeat, but with the 2nd generation hardware, the event can contain up to 30 temperature samples. Increased sampling rate between heartbeats provides higher temporal resolution, with only a minor reduction in battery life.

Configuring Sample Rate

Details coming soon.

Event Anatomy

When the sensor is configured for inter-heartbeat sampling, additional samples are included with every temperature event as a list of timestamps and values. As shown in the Temperature Event documentation, the first element in the list is equal to the event timestamp and values, independent of configuration.
If more than 1 sample has been sampled during the period, the list is ordered for decreasing time, meaning that the oldest sample is located at the end. The total length of the list will depend on the configuration.

Concatenating Historic Events

Sensors with default configuration, one sample per heartbeat, can be indexed in the same way as sensors with an increased inter-heartbeat sampling rate. When fetching the event history, all the samples can be grouped by concatenating the samples list.
Python API
The following snippet shows how to unpack a list of historic temperature events fetched using our Python API. A full example can be found here.
1
samples = []
2
for event in events:
3
samples += event.data.samples
Copied!

Publishing Emulated Events

Temperature events from the 2nd Generation Wireless Temperature Sensor can be generated without access to physical sensors using the Emulator API.
DT Studio
Python API
In DT Studio, click API Integrations -> Emulator, then select or create a temperature sensor. When selecting Emulate sampling between heartbeats, the feature appears.
The publish_event() method is available under the Emulator resource of our Python API. The following snippet shows an overview, and a full implementation example can be found here.
1
dt.Emulator.publish_event(
2
device_id="<YOUR_DEVICE_ID>",
3
project_id="<YOUR_PROJECT_ID>",
4
data=dt.events.Temperature(
5
timestamp=datetime.utcnow(),
6
celsius=22.3,
7
samples=[
8
dt.events.TemperatureSample(
9
celsius=22.3,
10
timestamp=datetime.utcnow(),
11
),
12
dt.events.TemperatureSample(
13
celsius=22.8,
14
timestamp=datetime.utcnow()-timedelta(seconds=30),
15
),
16
dt.events.TemperatureSample(
17
celsius=23.3,
18
timestamp=datetime.utcnow()-timedelta(seconds=60),
19
),
20
],
21
)
22
)
Copied!

Sample Timestamp Accuracy

When a Cloud Connector receives an event, the updateTime field is measured. This is not directly possible for samples, which are sampled in between heartbeats. Instead, their timestamps, called sampleTime, is estimated by the cloud.
Currently, the implementation of this estimation assumes an ideally distributed interval according to the configuration. For instance, if the sensor is configured for 5 samples per heartbeat, each sample is distanced equally based on the previous heartbeat.
Last modified 1mo ago