Management and Data Reporting for Electronic Temperature Sensors - Developer Guide
Contents
Management and Data Reporting for Electronic Temperature Sensors - Developer Guide
Associate a Sensor with a Task
Sorting, Filtering, and Pagination
Display full event record for a Task ID
Overview
The Management for Electronic Temperature Sensor APIs provide the ability to configure Sensors for use. This includes Enrolling Sensors, creating Tasks, Configuring Sensors, adding Sensors to Tasks, associating Assets IDs with tasks and stopping Tasks.
The Data Reporting for Electronic Temperature Sensor APIs are designed to provide data for after Task reports. Every Sensor reading and monitored Event that occurred the use of the Sensor assigned Tasks are recorded and stored for 7 years. These APIs allow you to view that history. Useful for reconciliation and final disposition determinations. This set of APIs are designed to provide data that can be used to create post-Task reports.
The log request is a raw request to the long-term data storage system. Every temperature reading captured by the Sensor is listed as a separate event. This means that every Sensor can have many thousands of Events associated with it. The system also captures other major events in the use of the Sensor. The APIs provide means of filtering and paginating this data.
Audience
This guide is for developers of applications that integrate data from the Zebra Sensor.
Workflow
The table below describes the steps needed to achieve a simple use case for using Zebra Temperature Sensors.
Step |
API |
Comments |
|
POST /devices/sensor-enrollments |
Use the serial number on the Sensor. |
|
POST /environmental/tasks |
Configure the temperature recording thresholds and start method. Repeat for each Task. |
|
POST /environmental/tasks/{taskId)/sensors |
Use the Task ID returned when the Task was created. Repeat for each sensor. |
|
GET /devices/environmental-sensors |
Optional filters are available. |
|
POST /environmental/tasks/{taskId}/stop |
Stop recording temperatures. |
|
GET /environmental/tasks/{taskId} |
Use the Task ID returned when the Task was created. |
|
GET /environmental/tasks |
Optional filters are available. |
|
GET /environmental/tasks/{taskId}/alarms |
Use the Task ID returned when the Task was created. |
|
GET /data/environmental/tasks/{taskId}/log |
Data may not be immediately available. |
Getting Started
API Authentication
Access to all Zebra APIs need to be authenticated. There are several methods available for Authentication with Zebra APIs. Once you have been granted access to the Electronic Temperature Sensor APIs, you will find a client key on [JJ1] your App page of the Zebra Developer Portal. It is very important that you keep this key safe and secure from your code, repositories, or others. Do not give or share your full key with anyone.
Simple Key
Most of the APIs can be authenticated by just providing the client key in the headers under the ‘apikey’ parameter. This is ONLY recommended for initial testing and Proof of Concept work. This is the most insecure method and should never be used outside of the developer’s control[JJ2] .
- Copy the ‘Consumer Key’ by clicking the button.
- To verify, Go to the Api page that you want to work with and,
- Click the Authorize button
- Paste the client key into the box labeled the ApiKeyAuth text box and click ‘Authorize’.
Note: This key is sometimes referred to by several names: App key, API key, consumer key, or client key. They all refer to the same thing. We will refer to it as a client key in this document.
OAuth – Client Credentials – not available for early access
An OAuth bearer token can be created by providing the client key and client secret. You will find a client key and secret on the App page of the Zebra Developer Portal. All Zebra Bearer tokens last for one hour but can be refreshed using the previous token. Client Credentials grant type should only be used from a client app’s server, never directly from a client app directly as this may provide open access to client keys.
Generate token: https://developer.zebra.com/apis/oauth-client-credentials#/Client%20Credentials%20Grant%20Type/Generate%20Access%20Token%20Client%20Credentials [JJ2] [JJ3]
To verify, call the API above and get a token. If the token returns with ‘abc123’, then the value you provide to the Authorization
OAuth – Authorization Code – not available for early access
The primary method for creating a Bearer token specific to customers, is the Authorization Code grant type. This is the standard 3-legged OAuth used in many web applications. It is considered one of the most secure methods of getting a token. All Zebra Bearer tokens last for one hour but can be refreshed using the previous token.
Authorization code grant type is a multi-step process. First you redirect to the IDP login and provide a redirect URI. After the customer logs in, the IDP will send the authorization code to the client app URI. Authorization codes last for 10 seconds. The client app calls the token API with the code to get a bearer token.
Generate Token: https://developer.zebra.com/apis/oauth-authorization-code-0
Enroll Devices
Pre-Requisites
- A ZB200 bridge
- Access to an ethernet port and ethernet cable
- One or more ZS300 temperature Sensors
- An apikey
Procedure
- Navigate to the Zebra Developer portal
- Login to the portal.
- Navigate to the Management for Electronic Temperature Sensors API page.
- Click the green Authorize button and enter your apikey.
- Click Close.
- Expand the POST /devices/sensor-enrollments method.
- Click the Try it out button.
- Enter the serial number of the ZS300 temperature sensor in the JSON body (replacing the word string).
See the image for the location of the serial number.
- Click the Execute button.
A successful response displays with the HTTP Status Code 200.
The response body is an empty JSON body.
The device is scheduled to be enrolled.
- Hold down the button on the front of the sensor until the amber LED blinks.
After about 1 or 2 minutes the device is enrolled.
Post-Requisites:
Proceed with Listing the Sensors.
List the Sensors
Pre-Requisites
- At least one Sensor has been Enrolled.
Procedure
- Navigate to the Management for Electronic Temperature Sensors API page.
- Click the green Authorize button and enter your apikey.
- Click Close.
- Expand the GET /devices/environmental-sensors method.
- Click the Try it out out button.
- Enter 0 in the page parameter.
- Enter 1 in the size parameter.
If you have more than one Sensor enrolled, enter a larger size parameter.
- Enter the serial number of the Sensor in the text filter parameter.
- Click Execute.
If successful, a response body with an HTTP Status Code of 200 is returned.
A JSON body is included in the response which contains details of the currently enrolled Sensor.
- {
- "sensors": [
- {
- "id": "83f87911-2184-4f26-91c5-83f87911c1b4",
- "mac_address": "01757E1A0001",
- "serial_number": "ABC123456789",
- "model": "ZS300-10001-0001",
- "manufacturer": "Zebra Technologies",
- "hardware_revision": "2",
- "firmware_revision": "D01.0.0.712",
- "battery_level": 99,
- "name": "ZS300_DLJ222902256",
- "status": "SENSOR_STATUS_STOPPED",
- "alarm_count": 0,
- "first_seen": "2022-11-04T19:42:27.168719Z",
- "certificate_url": "https://storage.googleapis.com/spg-zpc-p-envirovue-certs/certificates/Z…",
- "most_recent": {
- "task_id": "abe2c7d0-a8f8-4017-8958-abe2c7d0204f",
- "sensor_task_id": "202ac1cf-3b29-463d-964b-202ac1cf2092",
- "sensor_task_status": "SENSOR_TASK_STATUS_COMPLETED"
- },
- "requested": {},
- "certificate_type": "CERTIFICATE_TYPE_CONFORMANCE"
- }
- ],
- "page_response": {
- "total_elements": "1",
- "size": 1,
- "total_pages": 1
- }
- }
Post-Requisites
- Save the ID of the Sensor for the next step.
Associate a Sensor with a Task
Pre-Requisite
- The ID of an enrolled Sensor is available
Procedure
- Navigate to the Management for Electronic Temperature Sensors API page.
- Click the green Authorize button and enter your apikey.
- Click Close.
- Expand the POST /environmental/tasks method.
- Click the Try it out button.
- Enter the sample JSON in the Request Object box.
- {
- "task_from_details": {
- "task_details": {
- "name": "My Task 1",
- "interval_seconds": 15,
- "loop_reads": true,
- "start_immediately": {},
- "sensor_type": "SENSOR_TYPE_TEMPERATURE",
- "alarm_low_temp": 15,
- "alarm_high_temp": 30,
- "low_duration_seconds": 30,
- "high_duration_seconds": 30
- }
- }
- }
- Click Execute.
A successful response with an HTTP Status Code of 200 is returned.
The task ID is returned in the response body.
- {
- "id": "abe2c7d0-a8f8-4017-8958-abe2c7d0204f"
- }
- Expand the POST /environmental/tasks/{taskId}/sensors method.
- Click the Try it out button.
- Enter the task ID just returned in the taskId path parameter field.
- Enter the sensor ID that was returned from Listing the Sensors in the sensor ID array in the Request Object box.
- Click Execute.
A response is returned with an HTTP Status code of 200.
A JSON object with the sensor_id and sensor_task_id association is returned as shown below.
- {
- "associated_sensors": [
- {
- "sensor_id": "83f87911-2184-4f26-91c5-83f87911c1b4",
- "sensor_task_id": "abe2c7d0-a8f8-4017-8958-abe2c7d0204f"
- }
- ]
- }
Sorting, Filtering, and Pagination
Pagination for the Data Reporting for Electronic Temperature Sensors
The Sense-Events services use token-based pagination due to the potentially very large number of results. The default page size is 100. The way this works is you request the first page of content and optionally request a size (number of sense events) to return. Responses will also include a token for the next page. Use this token in the next request, optionally with a size, to get the next set of event data.
How To:
Perform a Sample Task
Pre-Requisites
- One or more Sensors have been Enrolled.
- A Task has been created.
- One or more Sensors have associated with a Task.
Procedure
- Repeat the List the Sensors procedure.
- Note the status field of the Sensor is SENSOR_STATUS_STOPPED.
- Press the button on the Sensor and hold for ten seconds until the LED blinks orange.
After the sensor LED blinks green, the Task has started.
Note: If theSsensor LED does not blink green, move the Sensor is closer to the bridge.
If you repeat the List the Sensors procedure again, the status changes to SENSOR_STATUS_ACTIVE.
- Allow the Task to run for at least several minutes.
- Move the Sensor around to different temperature conditions.
- After several minutes, stop the Task by expanding the POST /environmental/tasks/{taskId}/stop
- Click the Try it out button.
- Enter the taskId in the path parameter.
- Click Execute.
A response is returned with an HTTP Status Code of 200.
The task is scheduled to stop.
When all sensors associated with the task are within range of the bridge, then the task is stopped.
- {
- "task": {
- "id": "abe2c7d0-a8f8-4017-8958-abe2c7d0204f",
- "sensor_count": "1",
- "status": "TASK_STATUS_STOP_PENDING",
- "sensor_task_status_overview": {
- "stop_pending": "1"
- },
- "started": "2022-11-04T20:22:33.303659Z",
- "taskDetails": {
- "name": "Ryan Task 1",
- "created": "2022-11-04T20:10:06.083344Z",
- "updated": "2022-11-04T20:30:10.762285Z",
- "interval_minutes": 0,
- "interval_seconds": 15,
- "loop_reads": true,
- "start_immediately": {},
- "sensor_type": "SENSOR_TYPE_TEMPERATURE",
- "alarm_low_temp": 15,
- "alarm_high_temp": 30,
- "low_duration_seconds": 30,
- "high_duration_seconds": 30
- },
- "alarm_count": "0"
- }
- }
- Repeat List the Sensors procedure to verify that:
- The status field has returned to the SENSOR_STATUS_STOPPED status.
- The sensor task status is SENSOR_TASK_STATUS_COMPLETED.
Display full event record for a Task ID
This use case is to enable developers to create detailed reports based on the full set of data from a task. The API for this is the Data Reporting for Electronic Temperature Sensors. You first need to get an authorization token using one of the authorization methods above.
Using the Developer Portal Interactive Documentation
- Get your client key from the App page See Authentication- Simple Key
- Go to the Documentation page on the Developer Portal. https://developer.zebra.com/apis/analytics-and-reporting-temperature
- Click the Authorize button.
- Paste the client key into the box labeled the ApiKeyAuth text box and click ‘Authorize’.
- Select the /tasks/{taskId}/sense-events endpoint to drop down the documentation.
- Click ‘Try it out’
- Enter a Task ID
- Click ‘Execute’
- Verify the data response is similar to the response below.
- {
- [
- "type": "beacon",
- "event": {
- "id": "6359fcb8-96a0-461c-90b1-07dbb002c063",
- "timestamp": 1633359112806,
- "deviceId": "bridge-id_or_phone-id",
- "data": {
- "format": "beacon",
- "id": "sensormac",
- "value": "-2.06",
- "rssi": -51
- },
- "analytics": {
- "recordedTimestamp": 1633359112806,
- "resourceId": "bridge-id_or_phone-id",
- "tenant": "my_tenant",
- "timestamp": 1633359112806,
- "meta": "{\"taskId\":\"067e2b5e-0f70-4010-8245-28361008cca4\"}"
- },
- "decode": {
- "temperature": {
- "alert": true,
- "deviation": 0.3,
- "format": "celsius",
- "taskId": "task id",
- "sample": -2.06
- }
- }
- }
- ]
- }
Using an API test tool
- Now go to your favorite API test tool. The example below is using Postman, but other tools can be used as well.
- Download the Yaml file from the Developer Portal
- Import the Yaml file as a test suite
- Modify the taskID to be a valid task you created. Unclick the startTime and endTime.
- Go to the Headers tab and enter the Key ‘apikey’ and Value ‘your api key from step 1'.
- Click Send
- Verify the Response is the same as the response you received in step 9.
- Modify the startTime and endTime dates as desired to filter the results within a time range.
Application Integration
- In Postman, click the Code menu and select the language for your application.
- You can now copy and paste this into your application code for complete integration.