Sensor API (SAPI) provides an easy way to add sensors to an HDK (or any Milli-based project using the CoAP Server). Composed of a set of API calls that have been added to the Itron Reference CoAP Server, SAPI frees the developer from needing to know anything about CoAP.
SAPI is packaged for release as a standard Arduino application and composed of two parts
sapi_mshield: a replacement for the classic sensor code (mshield)
itron_coap_server: a new CoAP Server library
Sensor API makes it easy to enable the following features for your sensors:
Provide a response to a sensor CoAP GET request
Provide a respsone to a configuration CoAP GET request
Handle a configuration request PUT request to change a sensor's configuration
Generate periodic observation notifications to upstream systems
Generate ad-hoc observation notifications to upstream systems
The Sensor URI
Sensor API requires a specific URI and CoAP methods be used in developer client software and infrastructure:
Note that both the classifier part of the URI ("arduino" in the above table) and the query parameter names can be changed by the developer to support a custom API experience.
However, both the classifier part of the URI ("arduino" in the above table) and the query parameter names can be changed by the developer to support a custom API experience.
Sensor Application Flow
Sensor API follows the basic arduino application flow (setup and loop).
initialize the SAPI framework (and indirectly the CoAP Server)
register one (or more) sensor(s)
initialize one (or more) sensor(s)
Call the SAPI framework run method
Handle requests based on interrupt handlers
Sensor API Architecture
Sensor API (SAPI) includes two primary components, a CoAP Server Library that interacts with the Milli5 module and exposes your sensor data as CoAP resources to the network, and an application programming interface (API) that you invoke to register your sensors with SAPI and send data over the network. SAPI abstracts your application and sensor code from the details of Milli5, CoAP, and network interaction. SAPI runs on your application processor, and handles the details of communicating with the Milli5 module using HDLC over a UART interface. The diagram below represents the SAPI architecture, and also shows which solution components are provided by Itron SAPI (in yellow), and which are provided by the partner (in blue).
The code samples below show how SAPI is intialized, sensors are registered, and notifications are sent over the network from sensors. For more information, see the Adding Sensors with Sensor API page, or the Sensor API User's Guide.