NOTE: In this Blog series, I go over the implementation of an Azure IoT application that is running on the Avnet LTE Starter Kit, running eLinux. All source is provided/accessible so I hope it will provide you a starting point should you want to modify/extend it for your own use. It is written in at an advanced C++/C level and utilizes concepts such as singleton classes and class member function referencing/calls. The Microsoft Azure IoT embedded C SDK is utilized for Azure interaction.
Overview
Having recently connected several devices to Microsoft’s Azure IoT Hub, I wanted to take a standalone device (something that only required a battery to power it) and implement it as a data collection device sending telemetry data to Azure. I also wanted to be able to send messages from Azure back to the device and have it perform actions based on those messages. With those general requirements in mind, I decided to use the Avnet LTE IoT Starter KitAvnet LTE IoT Starter Kit with an LTE IoT Breakout CarrierLTE IoT Breakout Carrier.
The LTE IoT Starter Kit is a small System-On-Module (SOM) that contains:
- A Wistron NeWeb Corporation (WNC) M18QWG global LTE Cat-4 modem module
- An ST LIS2DW12 (3-axis accelerometer)
- An Ambient Light Sensor
- A Temperature Sensor
I added the LTE IoT Breakout Carrier, so I could add additional sensors by adding MikroElektronika Click Boards. In the example program, I support the Barometer Click and the Temp&Humidity Click. I check for these boards during power up and if they are present, modify the messages sent to include their data (or omit it if they are not present).
The M18QWG (I refer to as the M18Qx to be inclusive of the M18QWG [global RF support] and the M182FG-1 [North America RF support]) is based on a Qualcomm MDM9207. The MDM9207 is a quad core Cortex-A7; three of the cores are running firmware related to the Modem and its management, and one core is running embedded Linux (eLinux) and is available for user applications. This mode of operation is referred to as Host Mode because the eLinux is running in a standalone mode thus allowing for applications to run without the need for an external processor connected to the device. The eLinux console interacts with a user via ADB using the USB port. To develop applications, a WNC SDK with HW link-libraries are provided in a WNC SDK.
To briefly overview the software operation, it sends telemetry messages repeatedly to Azure and monitors for in-coming messages. When in-coming messages are received, the requested actions are performed. The default telemetry message is sent every 10 seconds and looks like:
{ "ObjectName":"Avnet M18x LTE SOM Azure IoT Client", "ObjectType":"SensorData", "Version":"1.0", "ReportingDevice":"M18QWG/M18Q2FG-1", "DeviceICCID":"xxxxxxxxxxxxxxxxxxxxx", "DeviceIMEI":"xxxxxxxxxxxxxxx", "ADC_value":0.04, "last GPS fix":"Mon 2018-10-22 12:17:54", "lat":xx.xx, "long":xx.xx, "Temperature":82.29, "Board Moved":0, "Board Position":10, "Report Period":10, "TOD":"Mon 2018-10-22 12:17:55 UTC", "Barometer":1020.20, "Humidity":62.4 }
The first 4 items in this message are constant data (defined at compile time), but the remaining data is all dynamically obtained:
- The ICCID and IMEI is read during startup and saved. The ICCID is obtained from the SIM card you are using,
- The IMEI is provided by the M18Qx HW itself (it is unique for each device).
- The ADC_value is read from the light sensor when the message is sent
- The ‘last GPS fix’ is the time that the Lat/Long data was obtained
- The Lat and Long is the GPS Latitude and Longitude that the M18Qx GPS provides.
- The Temperature is read from the LIS2DW12 sensor each time a message is sent
- The ‘Board Moved’ is a simple binary 1/0 that indicates that during the last reporting period, the M18Qx board has (1) or has-not (0) physically moved.
- The ‘Board Position’ indicates the orientation of the board using the LIS2DW12 sensor. Possible positions are (Face is the top of the Board containing the M18Qx):
- The Report Period is the interval being used for sending the standard telemetry message in seconds (the default is 10)
- TOD is the Time Of Day that the message is being sent
The last two elements are only sent if the Barometer and/or Temperature&Humidity Clicks are present:
- If the Barometer Click is present, the barometric pressure (in mb) is sent.
- If the Temperature&Humidity Click is present, the Humidity (in %) is sent.
The messages/commands you can send from Azure to the device are:
Message/Command | Description |
REPORT-SENSORS | Reply with a list of available sensor |
SET-PERIOD x | sets the reporting period for standard telemetry messages to x |
GET-DEV-INFO | lists the information about this M18Qx device |
GET-LOCATION | sends the current latitude/longitude location |
GET-TEMP | sends the current temperature at the boards location |
GET-POS | sends the positional information about the board |
GET-ENV | sends environmental information about the boards location |
LED-ON-MAGENTA | turns the boards LED to Magenta, always on |
LED-BLINK-MAGENTA | turns the boards LED to Magenta, blinking |
LED-OFF | turns off the boards LED |
The example software application is implemented in both C and C++. To the greatest extent possible, I wanted to to provide objects that could be easily re-used. For example, I have used the LIS2DW12 sensor class on several projects by simply providing the I2C interface and interrupt pin definitions. It has allowed me to all the necessary control functionality for managing the sensor itself--all this without having to re-implement the underlying registers/bits manipulation. In the end, it helps quickly put a system together without having to re-implement a bunch of stuff multiple times.
The series of blogs related to this effort is:
Blog #1 Prerequisites (Azure IoT account)
Blog #4 SOM Architectural Elements
Blog #5 Modem Abstraction Layer (MAL)
I hope to provide you some insight into an IoT solution as well as a working example on using Microsoft Azure. It is easy to read about Technology concepts and principles, but seeing its implementation has always helped me, I hope that it helps you also.