How to Port MQTT Protocol in Buildroot on T113-i Board

In actual project development, engineers may need to port some tools or protocols in the file system. So how should we perform the porting operation?

We can add package configurations to port new features in the Buildroot of the OK113i-S development board. In this article, I will introduce how to port the MQTT protocol in Buildroot.

How to Port MQTT Protocol in Buildroot on T113-i Board

Part 1
Configuration File Introduction

First, let’s understand the configuration files involved when porting features in Buildroot.

By checking the existing configuration files in the source code of the Feilin Embedded OK113i-S development board, we can see that in the path buildroot/buildroot-201902/package/mosquitto, there are several files:

Config.in

mosquitto.mk

mosquitto.hash

mosquitto.service

S50mosquitto

① Config.in

The Config.in file uses BR2_PACKAGE_** as a switch to inform Buildroot which package needs to participate in the compilation. The switch is assigned in the OK113I_linux_defconfig configuration file under buildroot/buildroot-201902/configs/, similar to the Kconfig file in the kernel.

For example:

package/Config.in includes a call relationship:

source “package/mosquitto/Config.in”;

package/mosquitto/Config.in contains the information for BR2_PACKAGE_MOSQUITTO.

How to Port MQTT Protocol in Buildroot on T113-i Board

② demo.mk

This file declares some package information, such as specifying the package version, source download link, storage path, compilation rules, toolchain, etc. During compilation, it downloads the source package to the specified path according to the download address and version defined in this file and performs compilation and file copying, similar to a Makefile.

For example:mosquitto.mk

The file starts by stating the package version and download address, which can be accessed in a browser to find the corresponding version of the package. During compilation, if the file is not present in the source, it will be automatically downloaded.

mosguitto-1.5.8.tar.gz

mosguitto-1.5.8.tar.gz.asc

In addition, the file also defines other compilation rules, including file copy paths and other content.

③ demo.hash

This file records the hash checksum of the downloaded source package to prevent errors in the downloaded source package.

④ demo.service

This file is for the systemd service. After booting, systemd will start the demo service based on this file. The source path and installation path of this file will be specified in demo.mk.Currently, the OK113i-S development board does not use this service, so it can be ignored.

⑤ S50demo

This file is similar to demo.service and is the current boot service type used by the OK113i-S development board.

Among the above five files, Config.in and demo.mk are essential, while the other files can be configured as needed. Specific configuration content can refer to existing files or be written according to actual situations. Mosquitto already has a written configuration file that can be used directly. Generally, configuration files are provided by the project maintainer or developer. If the files you are porting do not have a configuration file, you can refer to existing configuration files to write one.

Part 2
Execution

We need to execute in buildroot/buildroot-201902:

make OK113I_linux_defconfig

Then executemake menuconfig ARCH=arm

In the graphical configuration interface, configure (if an error occurs, please install the following commands: sudo apt-get update and sudo apt-get install ncurses).

After entering the graphical configuration interface, input “/” to search for the function to configure. For example, searching for Mosquitto will show the information. Follow the prompts to select “1” to enter the target option, press “space” to select, and then save and exit.

How to Port MQTT Protocol in Buildroot on T113-i Board

After configuration is complete, execute ./build.sh in the current directory to compile the file system. Once the compilation is complete, check whether the corresponding files are present in the file system.(Note: If there is no network, the source package cannot be automatically downloaded during compilation. You need to manually download the source package from the download address and place it in the source package storage path.)

Part 3
MQTT Testing and Verification

Modify the OK113i-S development board’s /etc/mosquitto/mosquitto.conf file, adding a line user root after #user mosquitto, then restart the service or the board. You can also kill the process and re-execute:

/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Then perform the test —

Subscribe to the test topic:

mosquitto_sub -t test &

Publish to the test topic:

mosquitto_pub -t test -m “hello world”

If you see the returned hello world, it means the porting was successful.

This is the method for porting the MQTT protocol in the Feilin Embedded OK113i-S development board’s Buildroot, for the engineers in front of the screen to reference.

How to Port MQTT Protocol in Buildroot on T113-i Board

This content is reprinted from
https://mp.weixin.qq.com/s/sLsfRvaKtkz55VcBPnxTqA

Leave a Comment