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.

STM32 Kit Boards Arrangement

  • Download & Install USB Drivers & Firmware Update:

    1. First go to www.st.com/stm32nucleo. You will find a link to www.mbed.com. Click on it and select NUCLEO-L476RG figure.
    2. Then go to the bottom of the page and click on the first LINK for ST-LINK/V2 driver in the yellow patch.
    3. Now click on Download the latest ST-LINK/V2 drivers.
    4. Go to Get Software section and click Get Software button.
    5. 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.
    6. 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.
    7. Now unzip the .zip and run dpinst_amd64.exe as my PC is a 64-bit system. No errors means it is done good.
    8. Now go to step (2) above and now click on the second LINK to upgrade Nuclero firmware and followed "Windows Upgrade Instructions" as follows:
      1. Downloaded en.stsw_link007.zip file, unblocked in its properties and unzipped it.
      2. Then run ST-LinkUpgrade.exe by double clicking on it in "Windows" directory of the unzipped directory.
      3. Now connect Nucleo board, assembled above, to a USB port.
      4. Click on the Device Connect button.
      5. Now that displays the current version of firmware. For me it showed V2.J25.M14STM32 Debug+Mass storage.
      6. Also shows Upgrading to V2.J29.M18.
      7. 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:

  1. Download of Necessary Tools:

    1. Earlier registered to my.st.com. Now got the following software from this site.
      1. Downloaded the STM32 ST-Link Utility from this link. This facilitates upgrade of firmware in STM32 base board.
      2. 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.
  2. FP-CLD-AZURE1 3.0.0 software:

    1. The file FP-CLD-AZURE1 3.0 RC1.0.zip is downloaded, unblocked and unzipped to C:\ directory.
    2. This will be unzipped to C:\FP-CLD-AZURE1 3.0 RC1.0 directory.
  3. Setting up System Workbench for STM32:

    1. Installed the workbench software.
    2. 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.
    3. Important files for this project are:
      1. AzureClient_mqtt_DM_TM.c - Azure sample application.
      2. HWAdvanceFeatues.c - Advance features for sensors board.
      3. platform_STM32Cube.c - Platform dependent functions.
      4. azure1_config.h (in the Includes directory) - for setting Wi-Fi credentials & Azure connection string.
  4. Modifications to Example Code:

    1. 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.
      1. AZURE_DEFAULT_SSID
      2. AZURE_DEFAULT_SECKEY
    2. 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.
      1. AZUREIOTHUBCONNECTIONSTRING
    3. Testing the Base Code Functionality:
      1. 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.
      2. Then built the project from Project -> Build All menu option.
      3. 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.
      4. 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.
      5. 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.
      6. 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.

 

Tera Term showing the data received from STM32 Base Board

 

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.