Sensors Skink
Demonstrates using the Skink environmental monitor backpack, with a web page displaying sensor readings.
- SDK directory:
apps/sensors/skink
API Features Demonstrated
Platforms
This app works on:
- AMW004 - Zentri Mackerel evaluation board
- AMW106 - Zentri Moray evaluation board
- AVN4343 - Avnet IoT Starter Kit
- NXP-SCCK - NXP Secure Cloud Connectivity Kit
Requirements and Prerequisites
This app requires a ZentriOS evaluation board. See the Platforms list above.
It also requires a Zentri Skink Environmental Sensor Backpack.
Resources
The initialization file skink.ini is packaged into the .zap
file downloaded to the device.
The html file resources/skink.html is downloaded to the device.
Description
Demonstrates using the Skink environmental monitor backpack, with a web page displaying sensor readings.
The web page uses WebSockets to obtain sensor data from the device.
Usage Instructions
Open a ZentriOS serial terminal to the device. See Getting Started, Opening a ZentriOS Terminal.
When the app starts, terminal output is similar to the following:
> Starting Skink Environmental Sensor Demo
IPv4 address: 10.10.10.1
HTTP and REST API server listening on port: 80
SoftAP 'Skink' started on channel 1
Connect with a Wi-Fi client to: Skink / password
Using a browser, go to http://skink.com
[90:18:7C:34:CB:97 associated]
> [Opened: 0]
> Thermometer stream listener registered, streaming data
Temp = 2477
Air stream listener registered, streaming data
CO2 = 777 [ppm]
tVOC = 0 [ppb]
Light stream listener registered, streaming data
LUX = 171
Hygrometer stream listener registered, streaming data
RH = 320
Temp = 2476
RH = 320
Temp = 2477
CO2 = 777 [ppm]
tVOC = 0 [ppb]
LUX = 171
RH = 320
...
Connect a Wi-Fi client to the device Soft AP with SSID Skink
as described, using the password password
, then open a browser on the client and navigate to http://skink.com
.
The skink web page is similar to the following:
Tap a sensor value to see a dynamic chart of the values over a period.
Implementation
zn_app_init
Loads the app settings with zn_load_app_settings to set up the HTTP Server and Soft AP.
Initializes the sensors with a call to initialize_sensors
.
Registers HTTP server stream callbacks for each of the four sensors with calls to zn_hs_stream_register_callback.
The sensors are handled with similar code, so we'll discuss only the air sensor as a representative example.
initialize_sensors
For each sensor this involves a call to sensor_init.
air_stream_callback
The stream callbacks for all sensors are similar:
- if
HS_STREAM_LISTEN
method: call zn_event_register_periodic to set up the periodic read eventHS_STREAM_LISTEN
method is received. - if
HS_STREAM_UNLISTEN
method: call zn_event_unregister - if
HS_STREAM_READ
method: read the sensor value with zn_hs_stream_read and then call zn_event_update_periodic to update the update period.
air_read_event_handler
The read handlers for all sensors are similar:
- call
get_sensor_data
with the sensor id to read the data - if successful, send the data with a call to the corresponding
send_<sensor>_data
function
send_air_sensor_data
Perform the appropriate unit conversions to the input data, then call the general send_data
to send the data.
send_data
Encode the data into a json buffer and call zn_hs_stream_write_listener to write to the appropriate stream.
get_sensor_data
The same function gets sensor data for all sensors, with sensors distinguished by the sensor id argument. This demonstrates the value of the sensor library abstraction layer.
Source
See: