mosquitto/openssl 在RK3288上的编译以及MQTT客户端的代码示例
1,依赖库openssl 的交叉编译
(1)配置编译器信息
setarch i386 ./config no-asm shared --cross-compile-prefix=arm-linux-androideabi-
(2)修改Makefile
删除-m32
(3)编译(指定编译器)
make CC=arm-linux-androideabi-gcc CXX=arm-linux-androideabi-g++
2,mosquitto 的交叉编译
(1)修改该config.mk
WITH_STATIC_LIBRARIES:=yes
CFLAGS += -I/where_is_your_openssl_headerfiles/
LDFLAGS += -L/where_is_your_openssl_staticlib/
(2)编译
make CC=arm-linux-androideabi-gcc CXX=arm-linux-androideabi-g++
3,基于mosquitto的MQTT client
代码中struct mqtt_conf是自定义结构,mqtt_send是一个双向链表实现的队列。
void start_mqtt_module(struct mqtt_conf *conf)
{
if (!conf->server || conf->server_port <= ) {
DEBUG_MSG("[%s] invalid parameters for mqtt module\n", THISFILE);
return;
} int rc = ; DEBUG_MSG("init_default_mqtt_parameters clientid %s\n", conf->clientid); mosquitto_lib_init(); mosq = mosquitto_new(conf->clientid, conf->clean_session, NULL); #ifdef MQTT_DEBUGLOG
mosquitto_log_callback_set(mosq, log_callback);
#endif mosquitto_connect_callback_set(mosq, on_connect);
mosquitto_publish_callback_set(mosq, on_publish);
mosquitto_disconnect_callback_set(mosq, on_disconnect); mosquitto_username_pw_set(mosq, conf->username, conf->password); //配置证书
if (!conf->disable_ssl) {
rc = mosquitto_tls_set(mosq,
conf->cafile,
conf->capath,
conf->certfile,
conf->keyfile, /* Notice: DO NOT encrypt your private key */
NULL /* password callback */
);
if (MOSQ_ERR_SUCCESS != rc) {
DEBUG_MSG("[%s] failed to set tls certification info\n", THISFILE);
} rc = mosquitto_tls_opts_set(mosq, SSL_VERIFY_PEER, NULL, NULL);
if (MOSQ_ERR_SUCCESS != rc) {
DEBUG_MSG("[%s] failed to set tls option\n", THISFILE);
} /* set this to false(default) means check server hostname under TLS protocol */
rc = mosquitto_tls_insecure_set(mosq, true);
if (MOSQ_ERR_SUCCESS != rc) {
DEBUG_MSG("[%s] failed to set incecrue\n", THISFILE);
}
}
//链接服务器
do {
rc = mosquitto_connect(mosq, conf->server, conf->server_port, );
if (MOSQ_ERR_SUCCESS != rc) {
DEBUG_MSG("[%s] failed to connect mqtt server %s:%d\n", THISFILE, conf->server, conf->server_port);
}
} while (rc != MOSQ_ERR_SUCCESS); DEBUG_MSG("[%s] connect mqtt server %s:%d OK\n", THISFILE, conf->server, conf->server_port); set_queue_alive(&mqtt_send); sleep();
//新线程用于定时发送 MQTT PING
create_function_thread(mqtt_loop, NULL); struct mqtt_msg *msg; while (run == -) {
msg = NULL;
//从队列中取出一个消息PUB出去
msg = (struct mqtt_msg *)dequeue(&mqtt_send);
if (msg) {
/* dispatch msg according to Qos */
rc = mosquitto_publish(mosq, NULL, msg->topic, msg->datalen, msg->data, msg->qos, false); if (MOSQ_ERR_SUCCESS == rc) {
DEBUG_MSG("[%s] mosquitto_publish success\n", THISFILE);
mqtt_pubs_succ++;
} else {
DEBUG_MSG("[%s] mosquitto_publish failed %d\n", THISFILE, rc);
mqtt_pubs_fail++;
} free(msg);
}
}
mosquitto_lib_cleanup();
}
/*
MQTT ping and reply for keepalive
*/
void *mqtt_loop(void *arg)
{
uint32_t cnt = ;
while (run == -){
int rc = mosquitto_loop(mosq, -, );
if (MOSQ_ERR_SUCCESS != rc) {
DEBUG_MSG("[%s] mosquitto_loop error %d\n", THISFILE, rc);
if (rc == MOSQ_ERR_ERRNO) {
DEBUG_MSG("[%s] mosquitto_loop error %s, errno %d\n", THISFILE, strerror(errno), errno);
}
mosquitto_lib_cleanup();
break;
} else {
//DEBUG_MSG("[%s] mosquitto_loop started! %d\n", THISFILE, cnt);
}
cnt++;
//3s keepalive
usleep(DELTA_US);
} return NULL;
}
mosquitto/openssl 在RK3288上的编译以及MQTT客户端的代码示例的更多相关文章
- Mac OS X上尝试编译CoreCLR源代码
CoreCLR登陆GitHub之后,体验CoreCLR首当其冲的方式就是在自己的电脑上编译它,昨天分别在Windows与Linux上成功编译了CoreCLR,详见: 1)Windows上成功编译Cor ...
- Windows上成功编译CoreCLR源代码
昨天得知微软在GitHub上发布CoreCLR的源代码之后,立马从GitHub上签出代码,并尝试在Windows Server 2012上进行编译. 参考CoreCLR的开发者指南(Developer ...
- Mosquitto安装_Ubuntu/Debian上安装消息队列Mosquitto
Mosquitto安装_Ubuntu/Debian上安装消息队列Mosquitto MQTT是IBM开发的一个即时通讯协议.MQTT是面向M2M和物联网的连接协议,采用轻量级发布和订阅消息传输机制.M ...
- 在vs2013上的编译tesseract-ocr
在vs2013上的编译tesseract-ocr OCR(Optical Character Recognition):光学字符识别,是指对图片文件中的文字进行分析识别,获取的过程. Tesserac ...
- Tesseract-OCR4.0版本在VS2015上的编译与运行(转)
最近刚开始接触识别库引擎方面的知识,由于项目中需要使用光学识别处理模块,在老师与朋友的推荐下,我开始接触tesseract光学识别库,在最开始从GitHub上下载的源代码进行编译的时候,出现了许多意想 ...
- Linux上安装编译工具链
在Linux上安装编译工具链,安装它会依赖dpkg-dev,g++,libc6-dev,make等,所以安装之后这些依赖的工具也都会被安装.ubuntu软件库中这么描述 Informational l ...
- mac 上python编译报错No module named MySQLdb
mac 上python编译报错No module named MySQLdb You installed python You did brew install mysql You did expor ...
- netcdf源码在windows上的编译
作者:朱金灿 来源:http://blog.csdn.net/clever101 今天搞搞netcdf源码在windows上的编译,折腾了半天,算是搞成了,特地记录一下过程.我的目标是要生成netcd ...
- 解决mysql跟php不在同一台机器上,编译安装php服务报错问题:configure: error: Cannot find MySQL header files under /application/mysql.
在编译安装php服务时报错: configure: error: Cannot find MySQL header files under /application/mysql. Note that ...
随机推荐
- UE4物理模块(三)---碰撞查询(下)SAP/MBP/BVH算法简介
在上一文中介绍了碰撞查询的配置方法: Jerry:UE4物理模块(三)---碰撞查询(上)zhuanlan.zhihu.com 本篇介绍下UE4的各种零大小的射线检测,以及非零大小(带体积)的射线检 ...
- 简单的layui二级联动
用layui实现省市二级联动, 需要注意的是使用layui之后, 你看到的下拉选框就不是option了,而是一些div 1.select表单 2.JS, ajax返回的是普通的数组
- 【JZOJ5068】【GDSOI2017第二轮模拟】树 动态规划+prufer序列
题面 有n个点,它们从1到n进行标号,第i个点的限制为度数不能超过A[i]. 现在对于每个s (1 <= s <= n),问从这n个点中选出一些点组成大小为s的有标号无根树的方案数. 10 ...
- 学习笔记(3)---安装SVM问题及解决方法
1. LibSVM下载,安装 下载地址:http://www.csie.ntu.edu.tw/~cjlin/libsvm/,最新的版本是3.17 2. 入门 [heart_scale_label,he ...
- Leetcode705.Design HashSet设置哈希集合
不使用任何内建的哈希表库设计一个哈希集合 具体地说,你的设计应该包含以下的功能 add(value):向哈希集合中插入一个值. contains(value) :返回哈希集合中是否存在这个值. rem ...
- 【水滴石穿】ReactNativeMobxFrame
项目地址如下:https://github.com/FTD-ZF/ReactNativeMobxFrame 应该可以说的是,项目也只是一个花架子,不过底部的tab稍微改变了 我们一起来看代码 //in ...
- linux C 编译时手动链接遇到的问题(未解决)
写多线程的时候,编译的时候遇到了问题,开始的时候是这样的: 编译器不认识pthread_create和pthread_join这两个函数. 搜了一下原因是没有链接相应的库,下面是我看到一个博友写的: ...
- day39 09-Spring的AOP:基于AspectJ的通知类型
AspectJ的六种通知的类型,最后一种不讲,只讲前五种. 环绕通知是可以阻止目标方法执行的. <?xml version="1.0" encoding="UT ...
- TCPThree_C杯 Day2
T1 我已经被拉格朗日插值蒙蔽了双眼,变得智障无比. 第一反应就是拉格朗日插值,然后就先放下了它. 模数那么小,指数那么大,这是一套noip模拟题,拉格朗日,你脑袋秀逗了? 无脑暴力20分贼开心. 正 ...
- 2019-9-2-win10-uwp-随着数字变化颜色控件
title author date CreateTime categories win10 uwp 随着数字变化颜色控件 lindexi 2019-09-02 12:57:38 +0800 2018- ...