华为摄像头(海思3519A/3516D)编译安装:paho.mqtt.embedded-c

1、简介

介绍如何使用Paho提供的嵌入式C语言MQTT开源工程交叉编译(海思3519A/3516D),并进行消息收发测试。https://github.com/eclipse/paho.mqtt.embedded-c

2、解压sdk

unzip paho.mqtt.embedded-c-master.zip

目录 /media/sf_share/code/mqtt 下得到解压后文件:paho.mqtt.embedded-c-master

3、建立编译目录

进入目录:/media/sf_share/code/mqtt/paho.mqtt.embedded-c-master
建立编译文件:mkdir build

4、编译执行脚本

进入目录:/media/sf_share/code/mqtt/paho.mqtt.embedded-c-master/build
建立脚本:touch cmake.sh
编辑脚本:vi cmake.sh
脚本内容:

cmake -DCMAKE_C_COMPILER=arm-himix200-linux-gcc -DCMAKE_CXX_COMPILER=arm-himix200-linux-g++ ..

执行脚本:./cmake.sh

5、代码编辑、编译与执行

编译代码位置:/media/sf_share/code/mqtt/paho.mqtt.embedded-c-master/build
编译命令:make
重编译清除命令:rm -rf !(cmake.sh)
代码编辑位置:/media/sf_share/code/mqtt/paho.mqtt.embedded-c-master/MQTTClient/test
执行文件位置:/media/sf_share/code/mqtt/paho.mqtt.embedded-c-master/build/MQTTClient/test
注意:执行文件是只能在目标机(海思3519A/3516D)运行的文件。

6、目标机(海思3519A/3516D)运行库建立

在目录 /home/nfs 下建立文件:mkdir lib_mqtt
进入目录:/home/nfs/lib_mqtt
拷贝运行库:

cp /media/sf_share/code/mqtt/paho.mqtt.embedded-c-master/build/MQTTPacket/src/libMQTTPacketClient.so ./
cp /media/sf_share/code/mqtt/paho.mqtt.embedded-c-master/build/MQTTPacket/src/libMQTTPacketServer.so ./
cp /media/sf_share/code/mqtt/paho.mqtt.embedded-c-master/build/MQTTPacket/src/libpaho-embed-mqtt3c.so ./
cp /media/sf_share/code/mqtt/paho.mqtt.embedded-c-master/build/MQTTClient-C/src/libpaho-embed-mqtt3cc.so ./

获得4个运行库:

libMQTTPacketClient.so  
libMQTTPacketServer.so  
libpaho-embed-mqtt3cc.so  
libpaho-embed-mqtt3c.so

7、目标机(海思3519A/3516D)验证测试

mosquitto代理主机准备:
代理主机地址:192.168.1.77
检查mosquitto是否启动:ps ax
得到:

632 ?        Ss     0:04 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

目录 /etc/mosquitto/conf.d 下编辑文件 mosquitto.conf
设置代理端口为:1813
重启mosquitto
目录 /media/sf_share/code/mqtt/paho.mqtt.embedded-c-master/MQTTClient/test 下文件 test1.cpp:

    344 int test1(struct Options options)
    345 {
    346         MQTT::QoS subsqos = MQTT::QOS2;
    347         int rc = 0;
    348         const char* test_topic = "C client test1";
    349 
    350         fprintf(xml, "<testcase classname=\"test1\" name=\"single threaded client using receive\"");
    351         global_start_time = start_clock();
    352         failures = 0;
    353         MyLog(LOGA_INFO, "Starting test 1 - single threaded client using receive");

获知订阅主题是:“C client test1”
代理主机打开订阅命令,用于目标机发送过来的消息:

mosquitto_sub -h localhost -p 1813 -t "C client test1" -v

目标机准备:
目录 /media/sf_share/code/mqtt/paho.mqtt.embedded-c-master/MQTTClient/test 下编辑 test1.cpp,修改代理主机地址和端口:

    44 struct Options
     45 {
     46         char* host;         /**< connection to system under test. */
     47   int port;
     48         char* proxy_host;
     49   int proxy_port;
     50         int verbose;
     51         int test_no;
     52         int MQTTVersion;
     53         int iterations;
     54 } options =
     55 {
     56 //      (char*)"localhost",
     57 (char*)"192.168.1.77",
     58   1813,
     59         (char*)"localhost",
     60   1885, 
     61         0,
     62         0,
     63         4,
     64         1,
     65 };     

回到目录 /media/sf_share/code/mqtt/paho.mqtt.embedded-c-master/build 下,重新编译:

rm -rf !(cmake.sh)
./cmake.sh
make

目录 /media/sf_share/code/mqtt/paho.mqtt.embedded-c-master/build/MQTTClient/test 下执行文件是:
testcpp1,把它拷贝到目标机nfs挂载目录:cp testcpp1 /home/nfs/
此时执行文件在目标机的位置是:192.168.1.69:/mnt/nfs
测试:
目标机配置执行加载库环境:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/nfs/lib_mqtt

执行:./testcpp1
此时,如果正常的话,订阅端收到如下消息:

C client test1 a much long
C client test1 a much long
C client test1 a much long
C client test1 a much long
C client test1 a much long
C client test1 a much long
C client test1 a much long
C client test1 a much long
C client test1 a much long
C client test1 a much long
C client test1 a much long
C client test1 a much long
C client test1 a much long
C client test1 a much long
C client test1 a much long
C client test1 a much long
C client test1 a much long

大功告成!!

mqtt环境的搭建记录,为后面做铺垫:mqtt + protobuf

相关推荐
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页