Device-cloud integration development case sharing

This article is shared from China Mobile's OneOS WeChat public account " Action ~ Device-Cloud Integration Development Case Sharing ", author: Mr. Ruo.

Introduction to the development environment

1. Hardware : Wanco development board , a series of development boards based on STM32, NXP and other chips launched by China Mobile, which consists of core boards with different processing cores and Wanco backplanes. The backplane is universal. There are three core boards: STM32L475VGT6, STM32F401VET6 and NXPLPC55S69. Users can choose different core boards according to their needs.

2. Compilation tool chain : OneOS Cube is a command-line-based development tool for China Mobile's OneOS operating system, providing functions such as system configuration, project compilation and construction, and package contribution download.

Introduction

Use a temperature sensor AHT10 and a distance light sensor AP3216C of a Wan coupler development board (referred to as WAN coupler A) to collect sensor data, and upload the collected data to the OneNet platform through the wired network using the MQTT protocol.

On the one hand, we can view the uploaded data on the OneNet platform; on the other hand, we will download the data uploaded from Wanco A to OneNet using HTTP request on another Wanco development board (referred to as Wanco B). down, and at the same time it is displayed on the LCD display of Wandu B.

Implementation process

1. OneOS Cube configuration

Configure the following items through the OneOS Cube tool:

Table 1 Project configuration items

 

 

 2. Code implementation

Overall design: (It is divided into 5 large modules in total)
Ⅰ: key_process
Ⅱ: lcd_process
Ⅲ: onenet_process
Ⅳ: sensor_process
Ⅴ: webapi_process
The functions of each module are divided as follows:

Table 2 code sub-module implementation

module

A brief description

key_process

Register buttons and button callbacks, send events in button callbacks, and buttons are used to turn pages. For example, if you need to view the Sensor page, after pressing the button, the LCD_EVENT_SENSOR event will be sent

lcd_process

In this module, a thread will be opened, which will always loop to detect whether there is a key event (such as LCD_EVENT_SENSOR) sent, and decide which page to draw and display according to different event types, and when switching to the corresponding page (such as Sensor) page), the data will be updated at a certain frequency, such as updating the sensor data on the Sensor page, and updating the calendar time data on the Calendar page

onenet_process

After completing the OneNet MQTT subscription, start a thread that periodically reads data from a global variable that holds Sensor data, and uploads the sensor data to the OneNet data point topic through Publish

sensor_process

Start a thread, periodically read local data from AHT10 and AP3216C sensors and store it in a global variable (mainly including temperature data, humidity data, distance data, light intensity data), the thread in onenet_process is from this global variable Read sensor data and upload it to OneNet

 

webapi_process

 

Start a thread, periodically request the uploaded data points from OneNet through HTTP, download the sensor data (uploaded by other devices) on OneNet to the local, and then save it in a global variable, the thread in lcd_process will read these Data to refresh the LCD display (if the Sensor page is currently displayed)

 main function call:

 Results display

1. View on OneNet

device online

2. Sensor data received on OneNet

3. Data display on two Wan coupler development boards

[Wanco development board A: The LCD displays the data collected by the sensor of Wanco development board B (B is first transmitted to OneNet, and then A is downloaded and displayed from OneNet. Note that the PS value shown in the above figure is very large, But the distance sensor in the lower right corner is not blocked (it should be very small if it is not blocked))]

[Wanco Development Board B: The data collected by the sensor of Wanco Development Board A is displayed on the LCD (A is first transmitted to OneNet, and then B is downloaded and displayed from OneNet. Note that the PS value shown in the above figure is very small, But the distance sensor in the lower right corner is blocked (the cover should be large))]

OneOS is a lightweight operating system launched by China Mobile for the Internet of Things. It features tailorable, cross-platform, low power consumption, and high security. It supports mainstream CPUs such as ARM Cortex-M/R/A, MIPS, and RISC-V. The architecture is compatible with POSIX, CMSIS and other standard interfaces, supports Micropython language development, and provides graphical development tools, which can effectively improve development efficiency and reduce development costs, helping customers develop stable, reliable, safe and easy-to-use IoT applications. Official website address: https://os.iot.10086.cn/
OneOS software address: http://www.oschina.net/p/cmcc-oneos
OneOS project address: https://gitee.com/cmcc-oneos/ OneOS
OneOS technical exchange group: 158631242

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324094000&siteId=291194637