Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to transplant mosquitto to arm

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

In this article Xiaobian introduces in detail "how to transplant mosquitto to arm", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to transplant mosquitto to arm" can help you solve your doubts.

1. Cross-compile uuid library

We copied the source code of uuid to Ubuntu, and the author copied it to / home/topeet/mqtt, as shown below:

Enter the following command to extract the source code and enter the folder generated by the decompression:

Tar-vxf libuuid-1.0.3.tar.gz

As shown in the following figure:

Then we create a folder called mosquitto-arm under / opt/ with the following command:

Mkdir-p / opt/mosquitto-arm

As shown in the following figure:

To configure the source code, enter the following command in the folder where the generated uuid library is extracted:

. / configure-prefix=/opt/mosquitto-arm/libuuid-1.0.3 CC=arm-none-linux-gnueabi-gcc-host=arm-linux

As shown in the following figure:

Finally, compile and install, with the following command:

Make

Make install

After compiling and installing successfully, we will get a folder of libuuid under our setting / opt/mosquitto-arm.

two。 Cross-compile openssl library

Decompress the package into the directory after decompression

Tar-vxf openssl-1.0.2g.tar.gz

Cd openssl-1.0.2g

This is shown in the following figure. The author is placed in the / home/topeet/mqtt directory

Configure compilation parameters

Setarch i386. / config no-asm shared-- prefix=/opt/mosquitto-arm/openssl/

Setarch i386: declare that a 32-bit CPU is generated, and remove this part if it is a 64-bit CPU

-- prefix: specify the path to the directory generated after make install. If you do not modify this item, the default is the OPENSSLDIR directory (/ usr/local/ssl).

Shared: generate dynamic link libraries.

No-asm: does not use assembly code to speed up the compilation process during cross-compilation, because its assembly code does not support the arm format

Delete-M32 and-M64 if there is-M32 and-M64 in Makefile, but not in my Makefile.

As shown in the following figure:

Modify the compiler parameters in Makefile under the openss folder as follows

CC= arm-none-linux-gnueabi-gcc

AR= arm-none-linux-gnueabi-ar $(ARFLAGS) r

RANLIB= arm-none-linux-gnueabi-ranlib

NM= arm-none-linux-gnueabi-nm

As shown in the following figure:

Compile and install

Make

Make install

After compiling and installing successfully, we will get a folder of openssl under our setting / opt/mosquitto-arm.

Compile source code

Make WITH_SRV=no CC=arm-none-linux-gnueabi-gcc CXX=arm-none-linux-gnueabi-g++ CFLAGS= "- I / opt/mosquitto-arm/openssl/include-I / opt/mosquitto-arm/libuuid-1.0.3/include-I / opt/mosquitto-arm/openssl/lib-I / opt/mosquit/to-arm/libuuid-1.0.3/lib" LDFLAGS= "- L / opt/mosquitto-arm/openssl/lib-L / opt/mosquitto-arm/libuuid-1.0.3/lib-lssl-lcrypto-luuid"

Note that if you install the uuid and openssl libraries here, the path to the library and header files specified by-I and-L should be changed to the path corresponding to the installation of uuid and openssl libraries, otherwise you will not be able to compile.

As shown in the following figure:

The successful compilation is shown in the following figure:

To install, the command is as follows

Make DESTDIR=/opt/mosquitto-arm/mosquitto-1.5 install

After compiling and installing successfully, we will get a folder of mosquitto-1.5 under our setting / opt/mosquitto-arm.

At this point, our mosquitto has been cross-compiled.

4. Porting mosquitto to the development board

Create a folder for mqtt-arm under / home/topeet/ of Ubuntu, as shown in the following figure:

Let's go to the mosquitto-1.5 directory where we installed the author, which is installed under / opt/mosquitto-arm, as shown in the following figure:

We copy the mosquitto.conf.example file under / etc/mosquitto/ under the current path to the folder where we created a mqtt-arm under / home/topeet/, with the following command:

Cp mosquitto.conf.example / home/topeet/mqtt-arm/

As shown in the following figure

Then we return to the installation directory of mosquitto, and we go to the installation directory under mosquitto-1.5/usr/local/bin, as shown in the following figure:

Let's copy all the files in this directory to the folder where we created a mqtt-arm under / home/topeet/, with the following command:

Cp. / * / home/topeet/mqtt-arm/

As shown in the following figure:

Then we return to the installation directory of mosquitto, and we go to the installation directory under mosquitto-1.5/usr/local/sbin, as shown in the following figure:

Let's copy the mosquitto binaries in this directory to the folder where we created a mqtt-arm under / home/topeet/, with the following command:

Then we return to the installation directory of mosquitto and copy all three folders of libuuid-1.0.3 mosquitto-1.5 openssl to the folder where we created a mqtt-arm under / home/topeet/. The command is as follows:

Cp-rf libuuid-1.0.3/ mosquitto-1.5/ openssl/ / home/topeet/mqtt-arm

As shown in the following figure:

Then we return to / home/topeet/ and use the tar command to package the mqtt-arm file we created, as follows:

Tar-czf mqtt-arm.tar.gz mqtt-arm/

As shown in the following figure:

Let's copy this package to the root directory of the development board. Here, take the 4412 development board as an example, and the other development boards operate the same.

We unzip the package and enter the directory generated by the decompression, as shown in the following figure:

We put all the libraries under the lib under the three libuuid-1.0.3/ mosquitto-1.5/ openssl/ files in the current directory of the development board under the / lib of the development board, with the following command:

Cp-rf libuuid-1.0.3/lib/* mosquitto-1.5/usr/local/lib/* openssl/lib/* / lib/

As shown in the following figure:

Let's copy a file named mosquitto.conf in the current directory named mosquitto.conf and put it under / etc with the following command:

Cp mosquitto.conf.example / etc/mosquitto.conf

As shown in the following figure:

Then we put all the remaining files in the / bin directory of the development board, with the following command:

Mv mosquitto mosquitto_* / bin

As shown in the following figure:

Then we return to the root directory of the development board, delete our mqtt-arm.tar.gz archive and extract the generated mqtt-arm folder.

5. Test whether the migration is successful

Take the development board as the server, and Ubuntu open two terminals as subscribers and publishers for testing.

1. We open the mosquitto.conf file under / etc, modify the 40th behavior user root and uncomment it. As shown in the following figure:

two。 Start the mosquitto service for the development board using the following command

Mosquitto-d-c / etc/mosquitto.conf

As shown in the following figure:

Whether the query was started successfully, the command is as follows:

Ps-ef | grep mosquitto

If you successfully enter as shown in the following figure:

3. Use the ping command to ping your own Ubuntu. Ping must be connected here, otherwise the following steps will not succeed. The command is as follows. IP is the ip of your own Ubuntu.

Ping 192.168.3.34-c 3

The successful ping is shown in the following figure:

4. In the first step of the document, we have installed mosquitto on Ubuntu. As shown, we directly open a terminal and subscribe to the topic with the following command:

Mosquitto_sub-h 192.168.3.28-t "mqtt"-v

The parameter-h specifies the MQTT server to connect to, and 192.168.3.28 here is the IP of the development board. You should set it according to your own IP,-t subscribe to the topic, and here is mqtt, so the topic prints more debugging information for mqtt,-v.

As shown in the following figure:

5. Open another terminal on Ubuntu (notice that another terminal is opened here), and publish the topic, with the following command:

Mosquitto_pub-h 192.168.3.28-t "mqtt"-m "Hello MQTT"

Parameter-h is the specified MQTT server to connect to, 192.168.3.28 here is the IP of the development board, everyone should set it according to their own IP,-t subscribe to the topic, here specifies the message content for mqtt,-m, and what is sent here is

Hello MQTT .

As shown in the following figure:

After the communication is successful, we will see the Hello MQTT that we forwarded as the mqtt server through the development board at another terminal.

Information, as shown in the following figure:

After reading this, the article "how to transplant mosquitto to arm" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report