This is the 2nd blog post for the "IoT on Wheels Design Challenge".
STM32 Setup:
The boards in the STM32 kit have been arranged as shown below.
Download & Install USB Drivers & Firmware Update:
- First go to www.st.com/stm32nucleo. You will find a link to www.mbed.com. Click on it and select NUCLEO-L476RG figure.
- Then go to the bottom of the page and click on the first LINK for ST-LINK/V2 driver in the yellow patch.
- Now click on Download the latest ST-LINK/V2 drivers.
- Go to Get Software section and click Get Software button.
- Here you have to Login / Register to my.st.com. This is a necessary step to download the software. Here download the en.stsw_link009.zip file.
- Right click this zip file and select Properties.. There check the Unblock and click OK. This is necessary as this is a downloaded file. This action ensures that all files in the zip are available unrestricted.
- Now unzip the .zip and run dpinst_amd64.exe as my PC is a 64-bit system. No errors means it is done good.
- Now go to step (2) above and now click on the second LINK to upgrade Nuclero firmware and followed "Windows Upgrade Instructions" as follows:
- Downloaded en.stsw_link007.zip file, unblocked in its properties and unzipped it.
- Then run ST-LinkUpgrade.exe by double clicking on it in "Windows" directory of the unzipped directory.
- Now connect Nucleo board, assembled above, to a USB port.
- Click on the Device Connect button.
- Now that displays the current version of firmware. For me it showed V2.J25.M14STM32 Debug+Mass storage.
- Also shows Upgrading to V2.J29.M18.
- Now firmware is successfully upgraded.
Connection to Cloud:
I am planning to use cloud to store data and manage alerts. Currently I plan to use Azure IoT Hub for this purpose as I have already worked with it as part of me attending various Microsoft IoT workshops and training sessions. I also got Azure subscription as part of my MSDN subscription. That is the reason why I selected Azure as my cloud component. So I already had created an Azure IoT Hub and added this Nucleo as a device. The details of the cloud setup is as follows:
- Name of the Azure IoT Hub: esm-iot-hub
- Name of the Device Registered: P-NUCLEO-AZURE1-Test (This is for testing purpose only. The actual name will be set from the mobile app which will follow certain format. The format of the Device ID is yet to be decided.)
- Primary Key of this device is noted for embedding into the NUCLEO firmware.
Transmit Data to Cloud:
Download of Necessary Tools:
- Earlier registered to my.st.com. Now got the following software from this site.
- Downloaded the STM32 ST-Link Utility from this link. This facilitates upgrade of firmware in STM32 base board.
- Downloaded the example code FP-CLD-AZURE1 3.0.0 software. This forms the base code for my project as this has got modules to connect to Wi-Fi and Azure IoT Hub. This takes a lot of burden from my back on connecting the device to Azure.
- Earlier registered to my.st.com. Now got the following software from this site.
FP-CLD-AZURE1 3.0.0 software:
- The file FP-CLD-AZURE1 3.0 RC1.0.zip is downloaded, unblocked and unzipped to C:\ directory.
- This will be unzipped to C:\FP-CLD-AZURE1 3.0 RC1.0 directory.
Setting up System Workbench for STM32:
- Installed the workbench software.
- Then imported the STM32L4xx-Nucleo project into its workspace from the directory C:\FP-CLD-AZURE1 3.0 RC1.0\Azure\Projects\STM32L476RG-Nucleo\Applications\Azure_Sns_DM\SW4STM32\STM32L476RG-Nucleo.
- Important files for this project are:
- AzureClient_mqtt_DM_TM.c - Azure sample application.
- HWAdvanceFeatues.c - Advance features for sensors board.
- platform_STM32Cube.c - Platform dependent functions.
- azure1_config.h (in the Includes directory) - for setting Wi-Fi credentials & Azure connection string.
Modifications to Example Code:
- Set Wi-Fi Credentials: In azure1_config.h file, set the SSID and Password for the home Wi-Fi network in the following constants. This will be changed to a string variable later to connect to different networks.
- AZURE_DEFAULT_SSID
- AZURE_DEFAULT_SECKEY
- Set Azure Connection String: Set the following constant to the device connection string noted when registered it to Azure IoT Hub. This also will be changed to a string later to accommodate multiple devices.
- AZUREIOTHUBCONNECTIONSTRING
- Testing the Base Code Functionality:
- In SW4STM32 set the Wi-Fi credentials and Azure IoT Hub Connection String as described above. Also made some modifications for testing in AzureClient_mqtt_DM_TM.c file. These changes will be detailed in next blog once they are fixed.
- Then built the project from Project -> Build All menu option.
- Once the project is successfully built, deployed the code to STM32 base board by running CleanAzure1mbedTLS.bat in the directory C:\FP-CLD-AZURE1 3.0 RC1.0\Azure\Projects\STM32L476RG-Nucleo\Applications\Azure_Sns_DM\SW4STM32\STM32L476RG-Nucleo.
- Once the code is deployed to base board, it starts running automatically. So pressed the Blue Button on the base board to stop it running.
- Then started the Tera Term, set the port to work with and set the baud rate to 115200. Now the Tera Term is ready to receive from the base board.
- Now pressed the Black Button to reset the base board and once it starts running noticed the data is being sent to IoT Hub and getting the acknowledgement as shown in the screenshot below. You may notice the Temperature Threshold crossing also in the screenshot. But that logic is yet to be finalized.
- Set Wi-Fi Credentials: In azure1_config.h file, set the SSID and Password for the home Wi-Fi network in the following constants. This will be changed to a string variable later to connect to different networks.
Though all this was done a week ago, I couldn't blog it out due to work pressure and other engagements. In next blog I will show how I am capturing the Temperature alerts and also my plan for the mobile app.
If you find this blog is interesting, please do like it.