Touch to Identify
An example of how to use the REST API with a simple script that identifies devices by touch.
Last updated
Was this helpful?
An example of how to use the REST API with a simple script that identifies devices by touch.
Last updated
Was this helpful?
A feature in DT Studio popular with our customers is the ability to locate a sensor by simply touching it. Like all functions in DT Studio, the implementation is based on our REST API. We will in this example show how simple it is to recreate using the stream endpoint.
Basic Auth For simplicity, we here use Basic Auth for authentication. We recommend replacing this with an for integrations more complex than local experimentation.
Service Account Credentials You must create and know the credentials of a Service Account. Any role will suffice.
Streaming Best Practices While this example is based on our other example for , it does not implement the same retry policy or other best practices as it is not the focus here. You are, however, free to combine the two examples for a more robust touch-event-listening loop.
The following points summarize the provided example code.
Sends a GET request to the REST API to initialize an event stream.
Keep the TCP connection open while receiving events.
When receiving a Touch Event, fetch and print the source device information.
Break the stream.
If you wish to run the code locally, make sure you have a working runtime environment.
The following packages are required by the example code and must be installed.
Add the following environment variables as they will be used to authenticate the API.
The following code snippet implements the touch-to-identify listening loop.
Once a touch event has been received, the device information is printed and stream terminated.
The latest version of our can be installed through pip.