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. 洛谷P1315 [NOIP2011提高组Day2T3] 观光公交

    P1315 观光公交 题目描述 风景迷人的小城Y 市,拥有n 个美丽的景点.由于慕名而来的游客越来越多,Y 市特意安排了一辆观光公交车,为游客提供更便捷的交通服务.观光公交车在第 0 分钟出现在 1号 ...

  2. 关于本地文件请求json文件

    因为需要用到json数据格式,上网查了一下例子之后我就想本地测试一下看能不能成功. 结果,chrome下没有任何反应,打开控制台之后报错如下: XMLHttpRequest cannot load f ...

  3. Ajax.dll使用方法和步骤(比较方便的实现ajax)

    转载自   博客频道 - CSDN.NET http://blog.csdn.net/houhanxin1/article/details/6671470 1. 有直接用框架的:Ajaxpro和Aja ...

  4. [新手必看] 17个常见的Python运行时错误

    对于刚入门的Pythoner在学习过程中运行代码是或多或少会遇到一些错误,刚开始可能看起来比较费劲.随着代码量的积累,熟能生巧当遇到一些运行时错误时能够很快的定位问题原题.下面整理了常见的17个错误, ...

  5. 【水滴石穿】LoginScreen_Firabase_ReactNativeApp_Redux

    先看效果 分析代码我们会发现,它使用了firebase 关于登陆部分应该是实时数据库,应该是他们后端校验的 //app.js //这里使用了实时数据库 import React, { Componen ...

  6. AnalyticDB for MySQL 3.0 技术架构解析

    企业数据需求不断变化,近年来变化趋势日益明显,从数据的3V特性看:体积,速度和变化:Big Data强调数据量,PB级以上,是静态数据.而Fast Data在数据量的基础上,意味着速度和和变化,意味着 ...

  7. Java中时间和日期的处理

    一.日期转换为字符串 1.日期以特定的格式输出: // 创建日期并转换为yyyy-MM-dd格式_(MM一定要大写,以免与hh:mm:ss中的mm冲突) SimpleDateFormat sdf = ...

  8. Python Unittest根据不同测试环境跳过用例详解

    虽然现在用的Katalon,不过这篇Unittest基本的用法讲的还是不错的 转自:https://mp.weixin.qq.com/s/ZcrjOrJ1m-hAj3gXK9TjzQ 本文章会讲述以下 ...

  9. H5视频播放自动全屏,暂停退出全屏等功能

    html5视频播放自动全屏,暂停退出全屏等功能 在参考了html5 video fullScreen全屏实现方式及司徒正美的书<javascript框架设计>287页相关代码后,在Safa ...

  10. VIM中空格和TAB的替换

    在.vimrc中添加以下代码后,重启vim即可实现按TAB产生4个空格:set ts=4  (注:ts是tabstop的缩写,设TAB宽4个空格)set expandtab 对于已保存的文件,可以使用 ...