Use a Quick-Start Platform to Accelerate Your Sensor-to-Cloud Connection
Contributed By DigiKey's North American Editors
2016-12-21
Sensors are the eyes and ears of the Internet of Things (IoT), providing the information that analytics and big data applications require to help users make intelligent decisions. While there are many ways to connect multiple wireless sensors to perform that analysis, connecting to the cloud remains challenging. This is particularly the case with regard to space, power, and cost, as well as provisioning and managing all the sensors while ensuring robust security.
To shorten the development cycle, there are development kits that combine sensor node development with cloud connectivity. Instead of having to make architectural decisions about how to integrate cloud services into an end-user experience – including what actions the systems will take and what will trigger a device's particular functionality – developers can use these kits right “out of the box” to get a sensor-enabled design up and running relatively quickly.
This article will introduce STMicroelectronics' STM32 Nucleo boards and X-NUCLEO expansion boards, which together integrate the necessary components to implement the specialized features of a chosen application. It will also show how with the FP-CLD-BLUEMIX1 expansion software package you can flash your Nucleo sensor node and connect Nucleo boards to the IBM Watson IoT Cloud Platform in a few simple steps.1
The Nucleo platform and the software
The STM32 Nucleo boards provide a flexible way for engineers to try out new concepts and build prototypes with the STMicroelectronics STM32 microcontrollers. The boards have extension headers that are common across all of the Nucleo boards, so it is easy to add extension modules.
Nucleo boards support Arduino as part of its open ecosystem approach, and do not require a separate probe as it integrates the ST-LINK/V2-1 debugger/programmer. The boards come with the STM32 software library, together with various packaged software examples.
Many different shields can be used, including Arduino. Boards using STMicroelectronics’ Morpho headers allow scalability for shields across the whole range of application types, including RF, industrial, and shields for home automation. Additionally, shields for Bluetooth LE, Wi-Fi, and audiovisual applications are available.
Library support covers the standard library for STM32, along with support for ARM®’s free online mbed, an IoT Device Platform that provides the operating system, tools and developer ecosystem, allowing designers to evaluate and get started with the Nucleo boards.
To help form the connection from sensor to cloud, STMicroelectronics has also made available the FP-CLD-BLUEMIX1, an IoT node expansion software package for STM32Cube that runs on the STM32 microcontroller and can be retrieved from STMicroelectronics’ website.2 The main aim of STM32Cube is to make the process of developing an application easier. To that end, it comprises the STM32CubeMX and the STM32Cube embedded software libraries (Figure 1).
Figure 1: FP-CLD-BLUEMIX1 provides complete middleware to build applications based on Wi-Fi connectivity and links STM32 Nucleo boards with cloud-based services. (Image: STMicroelectronics)
STM32CubeMX generates initialization C-code for STM32 MCUs from a graphical user interface. STM32MX also generates IDE-ready projects, provides a power-consumption calculator, and allows the direct import of STM32Cube embedded software libraries from st.com.
There is one STM32Cube Embedded Software package per series of STM32 products. This embedded software library comprises the hardware abstraction layer (HAL) and low-layer (LL) application programming interfaces (APIs) for the STM32 peripherals, as well as a set of middleware (RTOS, USB, TCP/IP, graphics, etc.) based on components that are either STMicroelectronics developed or open source. The initialization code, middleware components, HAL and LL APIs are compatible with all STM32 compilers.
For its part, the FP-CLD-BLUEMIX1 package extends STM32Cube by providing a board support package (BSP) for the Wi-Fi, NFC and sensor expansion boards. Its role is to enable connectivity to the IBM Bluemix Cloud to transmit sensor data, and also receive commands from Cloud applications. It essentially jump starts your end-to-end IoT development so that you can focus on differentiating your design.
Connecting the sensors
A software interface is provided to access the Nucleo board’s temperature and humidity sensor (HTS221), pressure sensor (LPS25HB), motion sensors (LIS3MDL and LSM6DS0) and to write and read the RFID/NFC tag. The X-NUCLEO-IKS01A1 incorporates all of these sensors (Figure 2).
Figure 2: The X-NUCLEO-IKS01A1 is a motion MEMS and environmental sensor evaluation board system. (Image: STMicroelectronics)
The IKS01A1 is compatible with the Arduino UNO R3 connector layout, and is designed around STMicroelectronics’ LSM6DS0 3-axis accelerometer + 3-axis gyroscope, the LIS3MDL 3-axis magnetometer, the HTS221 humidity and temperature sensor, and the LPS25HB pressure sensor.
It also includes a middleware package implementing the MQ Telemetry Transport (MQTT) protocol to facilitate interaction between the STM32 Nucleo boards and IBM’s Bluemix Cloud services. The software includes examples for visualizing sensor data and controlling the device via IBM Bluemix.
A sample application to experiment with connecting to the IBM Watson IoT platform is provided on top of the middleware stacks. It is used to prototype end-to-end IoT applications. After registering the STM32 Nucleo microsystem in the IBM Bluemix Cloud service it can be used for transmitting real-time sensor data. Thanks to the NFC dynamic tag, users also can automatically open a trial web page provided by IBM and visualize data generated by all the sensors on the STM32 Nucleo board.
To connect the STM32 Nucleo microsystem with IBM’s Bluemix cloud, STMicroelectronics ported an open-source implementation of the MQTT application-level network protocol. MQTT is a machine-to-machine (M2M) IoT connectivity protocol useful for connecting remote devices with a small code footprint, in particular where network bandwidth is limited. The messaging protocol is lightweight so it saves power, making it particularly suitable for sensor data telemetry and implementation in embedded systems. In FP-CLD-BLUEMIX1, MQTT is integrated into the STM32 package as a middleware library.
A sample application using the X-NUCLEO-IKS01A1, X-NUCLEO-IDW01M1 and XNUCLEO-NFC01A1 expansion boards with the NUCLEO-F401RE board is provided in the function pack. This application reads the data values from the temperature, humidity, pressure, accelerometer, magnetometer, and gyroscope sensors, and transmits these to IBM Bluemix via Wi-Fi.
The application is configured by default to run in Quickstart mode for data visualization only. However, it is easily modified to register and control the device in IBM Bluemix (requires an account on IBM Bluemix).
Registering with IBM Bluemix
By registering the STM32 Nucleo microsystem in the IBM Bluemix Cloud service you can use it to prototype end-to-end IoT applications, and begin transmitting real-time sensor data.
To start, sign in or create an account on Bluemix (full instructions can be found in Reference 1). During the registration procedure several properties and parameters must be provided as shown below:
Organization ID (i.e., “1w8a05”).
Device type (i.e.: “stm32_nucleo”).
UM2007 FP-CLD-BLUEMIX1 software description
DocID028875 Rev 2 13/23
Authentication Method (only “use-token-auth” supported).
Authentication token (i.e., “uUURNRbeQQaX+Fvi&8”).
Copy the device properties into the Config_MQTT_IBM function located in the source code file IBM_Bluemix_Config.c. This is in the Projects/Multi/Applications/MQTT_IBM/Src folder inside the FP-CLD-BLUEMIX1 software package.
The ibm_mode variable then needs to be set to “REGISTERED” as shown below (Code List):
Void Config_MQTT_IBM (MQTT_vars * mqtt_ibm_setup , uint8_t *macadd):
/* Default Configuration for QUICKSTART. REGISTERED mode requires account on Bluemix */
mqtt_ibm_setup->ibm_mode = REGISTERED
Device properties as provided in IBM Bluemix need then to be copied into the Config_MQTT_IBM function inside the source-code file named IBM_Bluemix_Config.c. This can be found inside the Projects/Multi/Applications/MQTT_IBM/Src folder.
About halfway down you will see:
Copy
/* REGISTERED DEVICE */
/* Need to be customized */
The fourth through eighth line will look like this when completed:
strcpy ((char*)mqtt_ibm_setup->username,”use-token-auth); //customize
strcpy ((char*)mqtt_ibm_setup->password,” uUURNRbeQQax+Fvit&8”);
strcpy ((char*)mqtt_ibm_setup->hostname,”1w8a05.messaging.internetofthings.ibmcloud.com);
strcpy ((char*)mqtt_ibm_setup->device_type, “stm32_nucleo”);
strcpy ((char*)mqtt_ibm_setup->org_id, “1w8a05”);
Code List: IBM device registration and property insertion requirements. Once registered, the STM32 Nucleo-based microsystem is able to send and receive information to and from IBM Watson IoT applications. (Source: STMicroelectronics)
The FP-CLD-BLUEMIX1 package sample application contains a default configuration to view sensor data on the IBM Quickstart webpage3 according to the MAC address of the device. The URL page is also written in the NFC tag. Once the STM32 Nucleo board is connected to a Wi-Fi access point, it automatically interacts with IBM Bluemix and starts transmitting sensor data. The MAC address of the Wi-Fi expansion board and the IBM Quickstart URL are printed in the serial terminal interface.
To view real-time sensor data, the Quickstart URL can be copied and pasted into a web browser. The web page can be more easily opened by bringing the device near to the NFC tag, assuming an NFC-enabled mobile device is available. For a visual indication of the connectivity status, the green LED2 on the STM32 Nucleo board is turned to “ON” once the Nucleo is connected to IBM Bluemix. It blinks each time a sample of sensor data is transmitted.
The FP-CLD-BLUEMIX1 package itself has an STM32 layer. This consists of a set of simple, generic, multi-instance APIs that interact with the upper-layer applications, libraries and stacks. These generic and extension APIs are based on a common framework. This allows any layers they build on, such as the middleware layer, to implement their functions without requiring specific hardware information for a given MCU. This structure improves library code reusability and guarantees easy portability across other devices.
Detailed technical information fully describing the API functions and parameters are available to the user in a compiled HTML file in the package’s “Documentation” folder
The main APIs used by the IBM sample are:
- ·void Config_MQTT_IBM(MQTT_vars * mqtt_ibm_setup , uint8_t * macadd); This configures the MQTT parameters for connection with IBM Cloud, given the MAC address for the Wi-Fi expansion board.
- int spwf_socket_create(Network* net, uint8_t * hostname, uint32_t port_number,uint8_t * protocol); This opens a socket given a hostname, port number and protocol type (TCP or TLS). It returns success or failure and the socket id within the network structure.
- ·void MQTTClient(Client* c, Network* network, unsigned intcommand_timeout_ms, unsigned char* buf, size_tbuf_size, unsigned char* readbuf, size_treadbuf_size); This configures the Client structure given the input parameters.
- int MQTTConnect(Client* c, MQTTPacket_connectData* options); This connects with the IBM MQTT broker given the parameters in Client and MQTTPacket_connect data structure. It returns success or failure.
- int MQTTSubscribe(Client* c, const char* topicFilter, enumQoSqos, messageHandlermessageHandler); This subscribes to the MQTT topic defined in data structure Client. It returns success or failure.
Conclusion
The growing demand for analytical data and the need to streamline how organizations gain access to it stresses the fact that wireless sensors and their associated MCUs need to connect to the cloud.
This article looked at a specific implementation option and how a recently released hardware development kit and associated software makes it easy to connect sensors to the cloud. From there, users can not only monitor the current state of objects and parameters of interest, but also use cloud services with a view toward predictive analysis.
References
- Explore IBM Watson Internet of Things
- FP-CLD-BLUEMIX1 STM32 ODE function pack for IoT node
- IBM Watson IoT Quickstart

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of DigiKey or official policies of DigiKey.