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客户端的代码示例的更多相关文章

  1. Mac OS X上尝试编译CoreCLR源代码

    CoreCLR登陆GitHub之后,体验CoreCLR首当其冲的方式就是在自己的电脑上编译它,昨天分别在Windows与Linux上成功编译了CoreCLR,详见: 1)Windows上成功编译Cor ...

  2. Windows上成功编译CoreCLR源代码

    昨天得知微软在GitHub上发布CoreCLR的源代码之后,立马从GitHub上签出代码,并尝试在Windows Server 2012上进行编译. 参考CoreCLR的开发者指南(Developer ...

  3. Mosquitto安装_Ubuntu/Debian上安装消息队列Mosquitto

    Mosquitto安装_Ubuntu/Debian上安装消息队列Mosquitto MQTT是IBM开发的一个即时通讯协议.MQTT是面向M2M和物联网的连接协议,采用轻量级发布和订阅消息传输机制.M ...

  4. 在vs2013上的编译tesseract-ocr

    在vs2013上的编译tesseract-ocr OCR(Optical Character Recognition):光学字符识别,是指对图片文件中的文字进行分析识别,获取的过程. Tesserac ...

  5. Tesseract-OCR4.0版本在VS2015上的编译与运行(转)

    最近刚开始接触识别库引擎方面的知识,由于项目中需要使用光学识别处理模块,在老师与朋友的推荐下,我开始接触tesseract光学识别库,在最开始从GitHub上下载的源代码进行编译的时候,出现了许多意想 ...

  6. Linux上安装编译工具链

    在Linux上安装编译工具链,安装它会依赖dpkg-dev,g++,libc6-dev,make等,所以安装之后这些依赖的工具也都会被安装.ubuntu软件库中这么描述 Informational l ...

  7. mac 上python编译报错No module named MySQLdb

    mac 上python编译报错No module named MySQLdb You installed python You did brew install mysql You did expor ...

  8. netcdf源码在windows上的编译

    作者:朱金灿 来源:http://blog.csdn.net/clever101 今天搞搞netcdf源码在windows上的编译,折腾了半天,算是搞成了,特地记录一下过程.我的目标是要生成netcd ...

  9. 解决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 ...

随机推荐

  1. Eclipse Git插件切换分支的时候不要Reset

    今天做了一件蠢事,我在当前分支上改了很多代码,后来切换分支的时候,有一个文件有冲突,eclipse提示这个文件冲突,我可以选择commit/stash/reset,我一看这个文件没什么关系,不需要提交 ...

  2. 从0开始学习 GitHub 系列之「04.向GitHub 提交代码」

    之前的这篇文章「从0开始学习 GitHub 系列之「Git速成」」相信大家都已经对 Git 的基本操作熟悉了,但是这篇文章只介绍了对本地 Git 仓库的基本操作,今天我就来介绍下如何跟远程仓库一起协作 ...

  3. BootstrapValidator实现注册校验和登录错误提示效果(转)

    使用BootstrapValidator进行注册校验和登录错误提示,具体内容如下 1.介绍 在AdminEAP框架中,使用了BootstrapValidator校验框架,本文以注册校验的用户名.登录名 ...

  4. 【水滴石穿】react-native-aze

    说个题外话,早上打开电脑的时候,电脑变成彩色的了,锅是我曾经安装的一个chrome扩展,没有经过我的同意开启了 (也许是昨天迷迷糊糊开启了) 上午运行项目都不成功,还以为被黑客攻击了---然后下午就排 ...

  5. Linux常用命令2 权限管理命令

    1.权限管理命令:chmod 上面图片中的ugoa与rwx并不是一个命令,而是不同选项 u 所有者  g 所属组 o 其他人 a 所有人 r 读取权限 w写入权限  x 执行权限 chmod u+x ...

  6. ie8 下margin-top失效的小案例

    一个小案例,是关于IE8下的margin-top的失效问题,巨日代码如下: 正常的chrome浏览器下的显示如下: margin-top=10px,正常显示 但是在ie8下,最终样式如下: margi ...

  7. Linux C socket 基于 UDP

    /*************************************************************************     > File Name: serve ...

  8. 客户端connect返回错误显示No route to host

    务器程序运行起来后,客户端connect返回错误显示No route to host,但是两台机子能ping通 是firewall的问题, services iptables stop应该就ok了

  9. Permutations II 去掉重复的全排列

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  10. SQLServer —— 视图

    一.视图的概念 是存储在服务器端的一个查询块,是一张虚拟表. 表示一张表的部分数据或多张表的综合数据. 其结构和数据是建立在对表的查询基础上. 视图的使用,跟对普通的表的查询使用完全一样. 二.视图中 ...