Difference between revisions of "STM32StepByStep:Step5 Build an IOT system"

[quality revision] [quality revision]
m
 

Build an IOT systemClock.png30min

Target description
This tutorial shows how to program and use the Bluetooth interface to perform data communication between the STM32L4 Discovery kit IoT node (B-L475E-IOT01A) and an Android application running on a mobile device.
After this tutorial, you will be able to build an IoT system, control it from your mobile monitoring sensors and collect data.

Prerequisites
You have gone through:

Hardware

  • STM32L4 Discovery kit IoT node[1] (B-L475E-IOT01A )
  • USB cable Type-A to Mini-B

Literature


The purpose of this section is to explain step-by-step how to reuse one of the applications that are part of the STM32CubeL4 MCU package to create a communication channel between the IoT board emulating a heart rate monitor and a mobile device on which the data is displayed via an Android application.

1 Import and convert the HeartRate project from the STM32Cube package[edit]

  • In STM32CubeIDE, import the HeartRate example located in: C:\Users\user_name\STM32Cube\Repository\STM32Cube_FW_L4_Vx.xx.x\Projects\B-L475E-IOT01A\Applications\BLE\HeartRate
  • The project must be converted and the following message is displayed:

Project Converter 3.png

  • Click on OK and a new message confirms the success of the conversion

Project Converter OK 2.png

  • Click on OK and the STM32CubeIDE workspace opens

Project Panel.png

2 Build and execute the HeartRate Project[edit]

  • Select the STM32L4_IOT_HR project
  • Click on the Build button Built Button.png to rebuild the project.
  • Click on the Debug button Debug Button.png arrow and select Debug Configurations… and make sure the Debug probe parameter is set to ST-LINK. Otherwise the code is not properly downloaded on the board.

Debug Panel.png

  • Click on the Debug button Debug Button.png to run the software.
  • STM32CubeIDE opens the Debug perspective. Click on the Resume button Resume Button.png to execute the code.

3 Install the Android application on a mobile device[edit]

To interact with the IoT board, an Android application has to be installed on a mobile device.
The STM32 BLE Profile application is a companion tool to show in a human readable form all notifications coming from Bluetooth Low Energy (BLE) devices implementing some peripheral profiles.
BLE Profile App.png

4 Connect to the IoT node[edit]

  • Go to Google Play store and install the “STM32 BLE Profiles” application on your mobile device.
  • Once installed, simply launch the STM32 BLE Profiles application. The application scans the network and displays a list of discovered BLE devices (Here the HeartRateSensor device).

BLE Scan.png

  • Establish a Bluetooth connection with the B-L475E-IOT1A board selecting the HR_L475_IoT device from the discovered devices list. It can take a while to get the connection established.
  • The following screenshot shows the successful pairing with a health thermometer sensor:

BLE HR.png

  • Once connected, select the Heart Rate profile among the BLE profiles proposed.

The application starts to display the heart rate data sent by the IoT connected device, which acts as a peripheral. In this example, the data is generated on the B-L475E-IOT1A board via a formula and does not reflect the data from a real sensor.
BLE Result.png
Now you are able to:

  • Build your own IoT system to get values from a peripheral device and display them on your mobile device
  • Regenerate a project from one of the various applications available in the STM32Cube package.

5 References[edit]



Previous step Arrow left.png



<big><big><big>'''Build an IOT system'''</big></big></big>[[File:Clock.png|40px|middle]]30min<br><br>
<big><big>'''Target description'''</big></big><br>

This tutorial shows how to program and use the Bluetooth interface to perform data communication between the STM32L4 Discovery kit IoT node (B-L475E-IOT01A) and an Android application running on a mobile device.<br>

After this tutorial, you will be able to build an IoT system, control it from your mobile monitoring sensors and collect data.<br>

<big><big>'''Prerequisites'''</big></big><br>

You have gone through:<br>

* [[STM32StepByStep:Step3 Introduction to the UART | Step3:  UART and new board introduction]]<br>

* [[STM32StepByStep:Step4 Sensors usage | Step4: Sensors usage with B-L475E-IOT01A]]<br> 

<big><big>'''Hardware'''</big></big><br>

* STM32L4 Discovery kit IoT node<ref>[https://www.st.com/en/evaluation-tools/b-l475e-iot01a.html  STM32L4 Discovery kit IoT node]</ref> (B-L475E-IOT01A )<br>

* USB cable Type-A to Mini-B
<big><big>'''Literature'''</big></big><br>

* [https://www.st.com/resource/en/user_manual/dm00347848.pdf UM2153] Discovery kit for IoT node, multi-channel communication with STM32L4<br>

* [https://www.st.com/content/ccc/resource/technical/document/user_manual/b3/37/62/19/ea/9f/48/4d/DM00169392.pdf/files/DM00169392.pdf/jcr:content/translations/en.DM00169392.pdf UM1873]  Getting started with the X-CUBE-BLE1 Bluetooth<sup>®</sup> Low Energy software expansion for STM32Cube4<br>

* [[File:pc_videol.png|middle|20px|link=https://www.youtube.com/watch?v=6eUqxjBL_wI]] [https://www.youtube.com/watch?v=6eUqxjBL_wI Getting starting with STM32L4 Discovery kit IoT node]<br>
<br>


The purpose of this section is to explain step-by-step how to reuse one of the applications that are  part of the STM32CubeL4 MCU package to create a communication channel between the IoT board emulating a heart rate monitor and a mobile device on which the data is displayed via an Android application. 

==Import and convert the HeartRate project from the STM32Cube package==
* In STM32CubeIDE, import the HeartRate example located in: '''''C:\Users\user_name\STM32Cube\Repository\STM32Cube_FW_L4_Vx.xx.x\Projects\B-L475E-IOT01A\Applications\BLE\HeartRate'''''
* The project must be converted and the following message is displayed:
[[File:Project_Converter_3.png|middle|300px]]<br>

* Click on OK and a new message confirms the success of the conversion
[[File:Project_Converter_OK_2.png|middle|300px]]<br>

* Click on OK and  the STM32CubeIDE workspace opens
[[File:Project_Panel.png|middle|400px]]<br>

==Build and execute the HeartRate Project==
* Select the STM32L4_IOT_HR project
* Click on the '''''Build''''' button [[File:Built_Button.png|20px|middle]] to rebuild the project.<br>

* Click on the '''''Debug''''' button [[File:Debug_Button.png|20px|middle]] arrow and select Debug Configurations… and make sure the Debug probe parameter is set to ST-LINK. Otherwise the code is not properly downloaded on the board.<br>

[[File:Debug_Panel.png|middle|600px]]<br>

* Click on the '''''Debug''''' button [[File:Debug_Button.png|20px|middle]] to run the software.<br>

* STM32CubeIDE opens the Debug perspective. Click on the '''''Resume''''' button [[File:Resume_Button.png|20px|middle]] to execute the code.<br>

==Install the Android application on a mobile device==
To interact with the IoT board, an Android application has to be installed on a mobile device. <br>

The '''''STM32 BLE Profile''''' application is a companion tool to show in a human readable form all notifications coming from Bluetooth Low Energy (BLE) devices implementing some peripheral profiles.<br>

[[File:BLE_Profile_App.png|middle|600px]]<br>

==Connect to the IoT node==
* Go to Google Play store and install the “STM32 BLE Profiles” application on your mobile device.
* Once installed, simply launch the STM32 BLE Profiles application. The application scans the network and displays a list of discovered BLE devices (Here the HeartRateSensor device).
[[File:BLE_Scan.png|middle|300px]]<br>

* Establish a Bluetooth connection with the B-L475E-IOT1A board selecting the HR_L475_IoT device from the discovered devices list. It can take a while to get the connection established.
* The following screenshot shows the successful pairing with a health thermometer sensor:
[[File:BLE_HR.png|middle|300px]]<br>

* Once connected, select  the Heart Rate profile among the BLE profiles proposed. 
The application starts to display the heart rate data sent by the IoT connected device, which acts as a peripheral. In this example, the data is generated on the B-L475E-IOT1A board via a formula and does not reflect the data from a real sensor.<br>

[[File:BLE_Result.png|middle|300px]]<br>

{{Highlight|Now you are able to:<br>

* Build your own IoT system to get values from a peripheral device and display them on your mobile device 
* Regenerate a project from one of the various applications available in the STM32Cube package.
}}

==References==<references />
<br><br>

{|class="st-table" style="margin: auto; text-align:center"
|style="border-style: hidden; background-color: white;width:200px; text-align:right"|'''[[STM32StepByStep:Step4 Sensors usage | Previous step]]'''
|style="border-style: hidden; background-color: white;width:100px; text-align:left"|[[File:Arrow left.png|20px|link=STM32StepByStep:Step4 Sensors usage]]
|}

{{PublicationRequestId | 16100 | 13.05.2020 | Philippe SAGE}}
{{ArticleBasedOnModel | Example STM32 Step by step article}}
<noinclude>

[[Category:STM32 step by step]]</noinclude>
Line 10: Line 10:
   
 
<big><big>'''Hardware'''</big></big><br>
 
<big><big>'''Hardware'''</big></big><br>
* [https://www.st.com/en/evaluation-tools/b-l475e-iot01a.html  STM32L4 Discovery kit IoT node] (B-L475E-IOT01A )<br>
+
* STM32L4 Discovery kit IoT node<ref>[https://www.st.com/en/evaluation-tools/b-l475e-iot01a.html  STM32L4 Discovery kit IoT node]</ref> (B-L475E-IOT01A )<br>
 
* USB cable Type-A to Mini-B
 
* USB cable Type-A to Mini-B
   
Line 54: Line 54:
 
* Regenerate a project from one of the various applications available in the STM32Cube package.
 
* Regenerate a project from one of the various applications available in the STM32Cube package.
 
}}
 
}}
  +
  +
==References==
  +
<references />
 
<br><br>
 
<br><br>
 
{|class="st-table" style="margin: auto; text-align:center"
 
{|class="st-table" style="margin: auto; text-align:center"