Skip to content

stm32 networking

Junjie Cai edited this page Jun 13, 2018 · 3 revisions

EN | 中文

Step by Step: MQTT to Cloud with STM32

This article will show you how to use mqtt on STM32L475 to connect to the cloud, based on the AliOS Things 1.2.0.

1、Hardware environment setup

1、Development board STM32 B-L475E-IOT01A

  • The development board we use is STM32L475, with 1M bytes of Flash and 128K bytes of SRAM.

  • Support WiFi, Bluetooth, SubG, NFC and many other wireless connections. Besides, it supports Arduino interface, so users can also use other wireless connection modules, such as the GSM.

  • 64 Mbits's Quad-SPI Flash is also integrated on the board.

  • There are many kinds of sensors on board, such as temperature and humidity sensors, 3 axis magnetometer, acceleration sensors, gyroscopes, proximity sensors and pressure sensors. It is convenient for developers to apply a variety of applications.

  • There are two digital full-angle microphones on the board. If needed, it can achieve voice control.

Detailed information about hardwares can refer to Introduction of STM32

2、MK3060 communication module

3、Three double-head Dupont Lines

4、Ways of connection:

Connect STM32L475 D0 with MK3060 UART TX, STM32L475 D1 with MK3060 UART RX, and STM32L475 GND with MK3060 GND. Detailed way of connection is shown as followed picture: connect the point with same color in two boards with Dupont Line.

2、Connect to Alibaba Cloud IoT suite

How to connect to Alibaba Cloud through mqtt app can refer to Connect preparations for IoT devices and Connect the devices

2.1、Five steps on the cloud:

  1. Register a Alibaba cloud account
  2. Start a IoT Suite
  3. Create a product, getProductKey
  4. Create a device, get DeviceName and DeviceSecret
  5. Define Topic$(PRODECT_KEY)/$(DEVICE_NAME)/data, and set the permission as: Devices are capable of publishing and subscribing

2.2、Parameter modification in device side

Source code of mqtt app is AliOS-Things/example/mqttapp/mqtt-example.c, credentials for connecting to mqtt server is located at framework/protocol/linkkit/iotkit/sdk-encap/imports/iot_import_product.h. The three parameters obtained from the cloud ( ProductKeyProductSecret,DeviceNameDeviceSecret) are corresponding to the three macros PRODUCT_KEYPRODUCT_SECRET,DEVICE_NAMEDEVICE_SECRET in the code.

#elif  MQTT_TEST
#define PRODUCT_KEY             "b1eszMRbDvz"                                                         
#define DEVICE_NAME             "mqtt_test"
#define DEVICE_SECRET           "CAaQz8Fc1JkFEyuzFhu4NpHSTlRSmRxV"
#define PRODUCT_SECRET          "Fxx6nyYptOugnS6H"
#else

3、AliOS Things Mqtt app compilation

The current AliOS Things mqtt app compilation command line is:

aos make mqttapp@b_l475e

After the command is executed, the generated bin file and the hex file can be found in out/mqttapp@b_l475e/binary/ directory.

4、Firmware burning

4.1、Burning of MK3060

Please go to MK3060 AT firmware download website officially provided by Mxchip, and select the firmware corresponding to MOC108/EMW3060 model. Way of burning can refer to "1. Update application firmware" in MK3060 firmware burning guidance.

4.2、Burning of STM firmware

Use ST-LINK to burn the firmware. Steps of burning is shown as followed picture:

5、Configuration of network and data connection

After the above 4 steps, the corresponding mqttapp binary has been burned into stm32L475 development board, and the port print is started as followed:

Wifi module can be connected to corresponding AP through command line.

netmgr connect *ssid* *password* *open|wep|wpa|wpa2*

When devices can connect to the network, mqttapp will start running. The following picture is mqtt run log:

Log information that can be further obtained on the cloud is shown as below:

Clone this wiki locally