Sensor API provides an easy alternative to classic CoAP server code for adding sensors to Itron Networks using Milli. This page provides step-by-step instructions to use SAPI functions to add your sensor to a Milli-based solution.
Sensor URI and Observations
When you register a sensor, one parameter you must supply is the sensor type. SAPI will use the string you supply for sensor type as part of the CoAP URI that represents that sensor to the network. For example, suppose you are adding an Oxygen level sensor, and you use "O2" as the sensor type. The CoAP URI for the temperature sensor would be "snsr/arduino/O2", and a GET operation from a CoAP client to obtain the current Oxygen level value would be "GET snsr/arduino/O2?sens".
Once you initialize and register a sensor with SAPI, that sensor's URI can also be used to generate observations. If you are using MQTT bubble-up configuration with Milli, that sensor's URI must be supplied as part of the Milli's sysvar 35 configuration. For more information on Milli configuration for observeable resources, see our personalization overview here.
With SAPI you can also send ad-hoc observations from the device to MQTT. An example of when this might be useful is when the sensor reaches a critical threshold, or when an alarm needs to be sent to subscribers. SAPI supports unsolicited notifications using the function sapi_error_t sapi_push_notification(uint8_t sensor_id). The push notification will immediately send the specified sensor's current value over the network to any subscribers. Note that sensor_id is the integer value returned after a successful call to sapi_register_sensor!