Git Product home page Git Product logo

jiejietop / mqttclient Goto Github PK

View Code? Open in Web Editor NEW
656.0 23.0 252.0 1.74 MB

A high-performance, high-stability, cross-platform MQTT client, developed based on the socket API, can be used on embedded devices (FreeRTOS / LiteOS / RT-Thread / TencentOS tiny), Linux, Windows, Mac, with a very concise The API interface realizes the quality of service of QOS2 with very few resources, and seamlessly connects the mbedtls encryption library.

License: Apache License 2.0

CMake 0.77% Shell 0.39% C 98.68% Makefile 0.12% C++ 0.04%
tcpip mqtt mqtt-client network linux rtos mbedtls ssl cross-platform socket-mqtt

mqttclient's Introduction

license

中文说明

mqttclient

A high-performance, high-stability, cross-platform MQTT client

A high-performance, high-stability, cross-platform MQTT client, developed based on the socket API, can be used on embedded devices (FreeRTOS/LiteOS/RT-Thread/TencentOS tiny), Linux, Windows, Mac, and has a very concise The API interface realizes the quality of service of QOS2 with very few resources, and seamlessly connects the mbedtls encryption library.

Advantage:

  • Extremely high stability: Whether it is drop and reconnect, packet loss and retransmission, it is strictly abide by the MQTT protocol standard, in addition to The test of large data volume is very stable whether it is receiving or sending, and the high frequency test is also very stable.

  • Lightweight: The entire code project is extremely simple. Without mbedtls, it takes up very few resources. The author used the esp8266 module to communicate with the cloud. The entire project code consumes less than 15k of RAM.

  • Support mbedtls encrypted transmission, make the network transmission more secure, and the interface layer does not require users to care, no matter whether it is encrypted or not, mqttclient is fixed for the API interface provided by the user, which is very compatible A set of codes on behalf of the application layer can be transmitted with or without encryption.

  • Supports multiple clients, compatible with multiple clients running at the same time, one device connected to multiple servers.

  • Supports synchronous and asynchronous processing, applications need not block and wait to waste CPU resources.

  • Support interceptor configuration, on some platforms, the client will automatically subscribe to the system theme by default, and the theme from the server changes every time. In this case, you need to use an interceptor to intercept and separate the theme and data Information and deliver it to users, greatly improving flexibility.

  • With online code generation tool, the code can be generated with extremely simple configuration, address: https://jiejietop.gitee.io/mqtt/index.html

  • Has a very simple API interface, in general, mqttclient configuration has default values, basically can be used without configuration, can also be arbitrarily configured, the configuration has robustness detection, so designed The API interface is also very simple.

  • Multifunctional parameters can be configured and tailored, reconnect time interval, heartbeat period, maximum number of subscriptions, command timeout, read and write buffer size, interceptor processing, etc. Parameters can be tailored and configurable to meet the needs of developers Complex and simple to use in various development environments.

  • Support automatic re-subscription of topics, after automatic reconnection to ensure that the topics will not be lost.

  • Support theme wildcards ""#", "+"`.

  • Subscribed topics are completely separated from message processing, making programming logic easier and easier to use, users don’t have to deal with intricate logical relationships.

  • The keep-alive processing mechanism has been implemented in mqttclient, without the user having to deal with the psychological experience, the user only needs to concentrate on the application function.

  • Has a very good design, designed the recording mechanism with very few resources, and retransmits the message when it is lost to ensure that the qos1 and qos2 service quality levels guarantee its service quality.

  • There are very good code styles and ideas: The whole code adopts a layered design, and the code implementation adopts the idea of ​​asynchronous processing to reduce coupling and improve performance.

  • Developed on top of standard BSD socket, as long as it is compatible with BSD socket system.

  • Seamless connection of salof: It is a synchronous and asynchronous log output framework. It outputs the corresponding log information when it is idle, and it can also write the information into flash to save it, which is convenient for debugging.

  • Use the famous paho mqtt library package.

  • No other dependencies.

Online code generation tool

This project has a code generation tool that only requires online configuration to generate code, which is extremely simple and easy to use. The code generation tool address is: https://jiejietop.gitee.io/mqtt/index.html

Online code generation tool

occupied resource size

A total of 10857 bytes of ROM, and the overhead of RAM is almost only dependent on dynamic memory. Without using TLS encrypted transmission, the communication dynamic memory that maintains the QOS0 quality of service level requires only about 3694 bytes. Including 1024 read buffer + 1024 write buffer + 1024 internal thread stack size, compared with other MQTT clients, mqttclient requires very little RAM resource overhead.

Code RO Data RW Data ZI Data Object Name
7118 791 0 0 mqttclient.o
546 0 0 0 mqttconnectclient.o
212 0 0 0 mqttdeserializepublish.o
476 0 4 0 mqttpacket.o
236 0 0 0 mqttserializepublish.o
310 0 0 0 mqttsubscribeclient.o
38 0 0 0 mqttunsubscribeclient.o
56 0 0 0 nettype_tcp.o
62 0 0 0 network.o
24 0 0 0 platform_memory.o
40 0 0 0 platform_mutex.o
344 0 0 0 platform_net_socket.o
94 0 0 0 platform_thread.o
70 0 0 0 platform_timer.o
246 0 4 0 random.o
62 0 0 0 mqtt_list.o
- - - - -
10066 791 8 0 total

Overall framework

Has a very clear layered framework.

Overall Frame

  • At the top of the framework is the API function interface, which implements the client's application, release, set parameters, connect to the server, disconnect, subscribe topic, unsubscribe topic, publish message and other functional interfaces.

  • The famous paho mqtt library is used as the MQTT message packet library.

  • Asynchronous processing mechanism is used to manage all the acks. It does not need to wait for the server's response when sending the message, but only records it. After receiving the server's ack, cancel this record, very efficient; and When the mqtt message (QoS1/QoS2) is sent and no response is received from the server, the message will be retransmitted.

  • An mqtt yield thread is implemented internally to handle all content in a unified manner, such as timeout processing, ack message processing, and receiving publish message from the server, at this time the callback function will be called Inform the user of the data received, *post release, post completion message processing, heartbeat message (keep alive), when disconnected from the server, you need to try to reconnect, resubscribe to the topic, resend the message or reply *Wait.

  • Message processing, such as reading and writing messages, decoding mqtt messages, setting messages (dup flag), destroying messages and other operations.

  • network is a network component, which can automatically select a data channel, if it is an encryption method, tls encryption is used for data transmission, and tls can choose mbedtls as the encryption backend; it can also be The tcp direct connection method is ultimately transmitted via tcp.

  • platform is a platform abstraction layer that encapsulates things from different systems, such as socke or AT, thread, time, mutex, memory management**, these are dealing with the system and are also necessary for cross-platform Package.

  • On the far right is the general content, list processing, log library, error handling, software random number generator, etc.

Supported platforms

At present, Linux, TencentOS tiny, FreeRTOS, RT-Thread platforms have been implemented (software package is named kawaii-mqtt`), in addition to TencentOS tiny AT framework can also be used, and the stability is excellent!

Platform Code Location
Linux https://github.com/jiejieTop/mqttclient
TencentOS tiny https://github.com/Tencent/TencentOS-tiny/tree/master/board/Fire_STM32F429
TencentOS tiny AT framework https://github.com/jiejieTop/gokit3-board-mqttclient
RT-Thread https://github.com/jiejieTop/kawaii-mqtt
FreeRTOS https://github.com/jiejieTop/freertos-mqttclient

Version

Release Version Description
[v1.0.0] Initial release, complete basic framework and stability verification
[v1.0.1] Fix the logical processing when actively disconnecting from the server
[v1.0.2] Add a new feature-interceptor, fix some small bugs
[v1.0.3] To avoid global pollution, modify the naming of log and list related functions
[v1.0.4] Network structure and mbedtls data channel readjusted
[v1.1.0] A larger version of the update, refactoring part of the code, optimizing the logic of MQTT processing, improving the overall stability, supporting multiple clients, supporting setting the will, optimizing the API interface, and adding multiple cloud platforms Test code and documentation, add online code generation tool, online cutting configuration tool

question

Welcome to submit issues and bug reports in the form of GitHub Issues

Copyright and License

mqttclient follows the Apache License v2.0 open source agreement. Encourage code sharing and respect the copyright of the original author. You can freely use and modify the source code, or you can publish the modified code as open source or closed source software.

Test and use under Linux platform

Install cmake:

    sudo apt-get install cmake g++

test program

Test Platform Location
emqx (my privately deployed server) ./test/emqx/test.c
Baidu Tiangong ./test/baidu/test.c
onenet ./test/onenet/test.c
Alibaba Cloud Internet of Things ./test/ali/test.c

Compile & Run

    ./build.sh

After running the build.sh script, the executable files emqx, baidu, onenet and other platforms will be generated under the ./build/bin/ directory Executable programs can be run directly.

    ./build/bin/emqx

Compile into a dynamic library libmqttclient.so

    ./make-libmqttclient.sh

After running the make-libmqttclient.sh script, a dynamic library file libmqttclient.so will be generated in the ./libmqttclient/lib directory, and installed into the system’s /usr/lib directory, the relevant header files have been Copy to the ./libmqttclient/include directory and copy it to your project. You only need to link the dynamic library when compiling the application. -lmqttclient -lpthread, the configuration file of the dynamic library is based on ./test/mqtt_config.h configuration.

If you are using a cross-compiler, you should export the corresponding environment variables according to the compiler you are using (the cross-compiler used here is arm-linux-gnueabihf-gcc), and you must also set the dynamic library file libmqttclient .so is copied to the /usr/lib directory of your embedded system:

    export CROSS_COMPILE=arm-linux-gnueabihf-

If you need to uninstall libmqttclient.so, execute the following command:

    ./make-libmqttclient.sh remove

Learn more

Please see the documentation:

mqttclient's People

Contributors

b4yuan avatar guangjiemvp avatar jiejietop avatar wuhaogs avatar xqyjlj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mqttclient's Issues

关于CA证书连接问题

您好,我看您给出的test/emqx/test_ca.c当中有两个ca证书,为啥要使用两个ca证书连接呢?我使用您给的例程跑起来过大概一分钟报错0x0008,无法连接。我使用自己的账号加mqtt.fx连接,ca证书只有一份,其中配置用户名、密码、ca.crt,协议为SSLv3,即可连接。但是当在程序中使用这一份ca证书连接时却无法连接,大约1秒钟就报错network/nettype_tls.c:30 返回错误0x0004。

socket error (null)

在服务器使用mosquitto做broker,
本地开发板pub 一个主题, 有client id, 无用户和密码
mosquitto 显示 socket error on client (null), disconnecting
对比是,我iPhone下载了一个mqtt软件,发布消息能被接受到

FreeRTOS Platform的几个问题向作者反馈

1、platform_thread_init函数中,xTaskCreate的最后一个参数应该是&thread->thread,而不是V1.1.0版本中的thread->thread。
platform_thread_init函数的自测代码修改为:

err =  xTaskCreate(entry, name, stack_size, param, priority, &thread->thread);

2、platform_thread_destroy函数中,先将任务删除,然后再释放内存的逻辑无法顺利运行。当任务删除后,无法运行到vTaskDelete的后一条释放语句。
platform_thread_destroy函数的自测代码修改为:

TaskHandle_t threadToBeDeleted;

threadToBeDeleted = thread->thread;
platform_memory_free(thread);

if (NULL != threadToBeDeleted)
    vTaskDelete(threadToBeDeleted);

3、我现在使用DTU在建立TCP连接、断开TCP连接都会给用户任务发送事件,用户任务超时5秒等到事件发生,当收到“离线到在线”事件连接 MQTT Server,收到"在线到离线事件" Disconnect, 什么都没有收到的情况下就超时了,即每5秒向MQTT Server发送一次Qos2消息。

在Qos2服务质量下,假设Socket无需用户维护,远程Socket首先断开连接,用户任务检测到掉线,在用户任务中调用mqtt_disconnect函数,会使得内部state变成CLIENT_STATE_CLEAN_SESSION,mqtt_yield返回MQTT_CLEAN_SESSION_ERROR,从而调用mqtt_clean_session,state变成CLIENT_STATE_INVALID状态,最终跳转到platform_thread_destroy函数。platform_thread_destroy函数删除了yield任务,但是c->mqtt_thread没有清零,当Socket再次连接成功后,调用的yield进程没有被重新创建,无法正常运行。

mqtt_yield_thread函数的exit部分自测代码修改为:

threadToBeDestoried = c->mqtt_thread;
c->mqtt_thread = (platform_thread_t *)0;
platform_thread_destroy(threadToBeDestoried);

目前运行较好,向大神请教,不知道我上述理解和修改可对。感谢指点, ^_^

建议弃用usleep

建议修改Linux平台的platform_timer_usleep实现,usleep是非可重入的,也是非线程安全的,而且延迟时间不精确,延时超过1秒时,也是不符合函数的使用规定的。建议使用信号量实现,或者使用select。

/*sleep in us*/
void usSleep(unsigned int nusecs)
{
	struct timeval	tval;

	tval.tv_sec = nusecs / 1000000;
	tval.tv_usec = nusecs % 1000000;
	select(0, NULL, NULL, NULL, &tval);
}

Demo test result

  I have build and test this sample,when run the ~/mqtt/mqttclient/build/bin/mqtt-client,
 only print  "welcome to mqttclient test...".
 I found that the code run in function platform_nettype_tls_connect(),
      if (0 != (rc = mbedtls_net_connect(&(nettype_tls_params->socket_fd),      n->network_params.addr,n->network_params.port, MBEDTLS_NET_PROTO_TCP))) 
goto exit;

It can't run to next line,and tcpdump found TCP has Retransmission.
 I want to run this demo to confirm it ,and then I can transported to out platform.
 Would help to check how to run this demo normally?

 Thanks!

Regards,
Ellen

mqtt_keep_alive函数有BUG

int mqtt_keep_alive(mqtt_client_t* c)
{
int rc = MQTT_SUCCESS_ERROR;

rc = mqtt_is_connected(c);
if (MQTT_SUCCESS_ERROR != rc)
    RETURN_ERROR(rc);

if (platform_timer_is_expired(&c->mqtt_last_sent) || platform_timer_is_expired(&c->mqtt_last_received)) {
    if (c->mqtt_ping_outstanding) {
        MQTT_LOG_W("%s:%d %s()... ping outstanding", __FILE__, __LINE__, __FUNCTION__);
        /*must realse the socket file descriptor zhaoshimin 20200629*/
        network_release(c->mqtt_network);
        
        mqtt_set_client_state(c, CLIENT_STATE_DISCONNECTED);
        rc = MQTT_NOT_CONNECT_ERROR; /* PINGRESP not received in keepalive interval */
    } else {
        platform_timer_t timer;
        int len = MQTTSerialize_pingreq(c->mqtt_write_buf, c->mqtt_write_buf_size);
        if (len > 0 && (rc = mqtt_send_packet(c, len, &timer)) == MQTT_SUCCESS_ERROR) // send the ping packet
            c->mqtt_ping_outstanding++;
    }
}

以上函数中
if (len > 0 && (rc = mqtt_send_packet(c, len, &timer)) == MQTT_SUCCESS_ERROR) // send the ping packet
c->mqtt_ping_outstanding++;

这里如果mqtt_send_packet 返回失败, 则 c->mqtt_ping_outstanding就一直保持是0 所以就一直不会断线
全局设置网络状态的地方 好像还有一个 PUBLISH时候 但是如果一直不publish那 就是keep alive这里发送失败 也不会认为掉线

mqtt服务器单向认证没有ca证书情况下如何连接?

我的情况是,MQTT服务器是单向认证,不需要客户端带CA证书,只需要用户名和密码就能实现连接,我用MQTT.fx这个软件能连接上,软件配置如下:
1
2
如上图。使用这样的配置方式是能连接上服务器的,但是使用mqttclient不使用CA证书的情况下就不知道怎么连接了。

emqx stop后程序退出

大神,首先非常感谢这么好的开源项目,我用代码生成器生成了pub和sub函数,断开网线测试重连没有问题,但是把服务手动停止后,客户端直接退出了,有没有方案处理下不直接退出一直去重连,客户端是在hi3559a下编译运行的,谢谢

arm-poky-linux-gnueabi-gcc

你好。用的arm-poky-linux-gnueabi-gcc。

./build.sh arm-poky-linux-gnueabi-gcc
不成功。怎么做呢?

谢谢大牛牛啊

好棒棒啊;
谢谢大牛牛;
你这个库必须依赖paho mqtt啊?

订阅时单独设置的handle收不到消息

单独设置handle无效,设置全局的handle才能收到订阅的消息。
抓包看报文确实下发到了设备。请教一下代码哪里出了问题,谢谢!

void mqtt_message_handle(void* client, message_data_t* msg)
{
    //始终进不来
    printf("message comes...\n");
    char *buf = msg->message->payload;
    if (strstr(msg->topic_name, "command_resp")) {
        //
    }
}

static int get_token(mqtt_client_t *client){
    mqtt_set_host(client, server);
    mqtt_set_port(client, he_wu_port);
    mqtt_set_user_name(client, imei);
    mqtt_set_password(client, pid);
    mqtt_set_client_id(client, imei);
    mqtt_set_clean_session(client, true);

    mqtt_connect(client);

    char pub_topic[256] = {0};
    char sub_topic[256] = {0};
    //device/products/382381/devices/355750075160144/command
    //device/products/382381/devices/355750075160144/command_resp
    sprintf(pub_topic, "device/products/%s/devices/%s/command",pid, imei);
    sprintf(sub_topic, "device/products/%s/devices/%s/command_resp",pid, imei);
    printf("pub_topic:%s\n",pub_topic);
    printf("sub_topic:%s\n",sub_topic);
    //这里设置了handle
    mqtt_subscribe(client, sub_topic, QOS0, mqtt_message_handle);
    return he_wu_publish(client,pub_topic);
}

int main(void)
{
    mqtt_client_t *client = NULL;
    printf("welcome to mqtt client...\n");
    client = mqtt_lease();
//    mqtt_set_interceptor_handler(client,mqtt_message_handle);
    get_token(client);

    sprintf(creq_topic, "$sys/%s/%s/creq/+", pid, imei);
    sprintf(crsp_topic, "$sys/%s/%s/crsp/", pid, imei);
    sprintf(sqdata_topic, "$sys/%s/%s/sqdata", pid, imei);

    while (1) {}

}

image

new features/添加新特性

As a client developed in accordance with the standard MQTT protocol, you may need to add new features on some platforms or meet some more convenient needs. You can speak freely here. This project will continue to be maintained.

作为一个按照标准MQTT协议开发的客户端,可能在某些平台上需要添加新的特性,或者满足某些更方便的需求,可以在这里畅所欲言,本项目将持续维护。

客户端工作期间,线路断线后再恢复无法自动恢复运行的问题

调试发现,mqtt_publish 返回的是MQTT_SEND_PACKET_ERROR.

但是查看 mqtt_yield_thread 函数

rc = mqtt_yield(c, c->mqtt_cmd_timeout); if (MQTT_CLEAN_SESSION_ERROR == rc) { MQTT_LOG_W("%s:%d %s()..., mqtt clean session....", __FILE__, __LINE__, __FUNCTION__); network_disconnect(c->mqtt_network); mqtt_clean_session(c); goto exit; } else if (MQTT_RECONNECT_TIMEOUT_ERROR == rc) { MQTT_LOG_W("%s:%d %s()..., mqtt reconnect timeout....", __FILE__, __LINE__, __FUNCTION__); }

没看到有对应的错误处理部分.

对这种情况请大虾指导一下,系统有对应的处理部分么?

如果没有,能否建议一下如何能达到自动恢复发送的流程.

谢谢

/usr/include/mqtt_defconfig.h:12:10: fatal error: mqtt_config.h: No such file or directory

步骤
1.克隆代码,./make-libmqttclient.sh编译库
2.进入libmqttclient目录,sudo cp -r include/* /usr/include/,复制头文件
3.编写cmakelist.txt代码

cmake_minimum_required(VERSION 3.10)
project(linux_c C)
set(CMAKE_C_STANDARD 11)
link_libraries(mqttclient)
add_executable(app test.c)

4.复制test.c
5.编译
出现错误

In file included from /usr/include/mqttclient.h:20:0,
from /mnt/e/linux_c/test.c:13:
/usr/include/mqtt_defconfig.h:12:10: fatal error: mqtt_config.h: No such file or directory
#include "mqtt_config.h"
^~~~~~~~~~~~~~~
compilation terminated.

请教这是什么原因?

关于编译成动态库libmqttclient.so的一个问题请教下up

我在./test/mqtt_config.h中,将#define MQTT_NETWORK_TYPE_NO_TLS 打开,相当于配置了不带tls的通信方式,那么我编译库文件的时候,是不是应该比我打开tls通信方式编译得到的库文件要小很多呢? 我目前编译后发现两者是几乎一样大的,请问我的理解是有错误么?

freeRTOS系统下,系统休眠后mqtt的连接问题

请教下 Jie哥,系统如果睡眠后,且睡眠时间超过了mqtt_keep_alive_interval时间,那么mqtt connection是否就断开了,需要重新走一遍初始化流程? 或是在系统睡前之前设置一个定时器,时间到了初始化后再publish?

client = mqtt_lease();
KAWAII_MQTT_LOG_D("After mqtt_lease().");
mqtt_set_port(client, g_mqtt_port);
mqtt_set_host(client, g_mqtt_host);
mqtt_set_client_id(client, g_mqtt_client_id);
mqtt_set_user_name(client, g_mqtt_user_name);
mqtt_set_password(client, g_mqtt_password);
mqtt_set_clean_session(client, 1);
KAWAII_MQTT_LOG_D("\nbefore mqtt_connect\n");
mqtt_connect(client);

mqttclient.h 头文件引入之后,宏定义错误问题

mqttclient.h 头文件引入之后之后,编译项目,出现plooc_class.h头文件中, error: types may not be defined in ‘sizeof’ expressions
173 | # define PLOOC_SIZEOF_STRUCT(...) sizeof(struct {VA_ARGS}) 错误,如何处理
| ^

关于调用mqtt_release出现fail的问题

杰神,我在写测试用例的时候需要在最终程序退出时调用mqtt_release来释放已经分配的内存,当我调用这句话的时候,走到了这个分支里:

    /* wait for the clean session to complete */
    while ((CLIENT_STATE_INVALID != mqtt_get_client_state(c))) {
        // platform_timer_usleep(1000);            // 1ms avoid compiler optimization.
        if (platform_timer_is_expired(&timer)) {
            MQTT_LOG_E("%s:%d %s()... mqtt release failed...", __FILE__, __LINE__, __FUNCTION__);
            RETURN_ERROR(MQTT_FAILED_ERROR)
        }    
    }

这也就意味着我的测试用例在之前调用mqtt_lease等接口所申请的内存并没有被释放。我在你提供的example样例里没有看到有关于它的使用方法,这里如果正确使用的话该怎么调用它才能成功呢?

公网断开, 局域网内反复连接服务器

遇到个问题, 公网出现问题的时候, 无法正常连接到服务器上, 调试信息打印四次连接成功, 打印 rc 返回值, -4
image
屏蔽 exit: 后面的 if(rc == KAWAII_MQTT_SUCCESS_ERR) 可以正常创建线程, 通信正常
image

想问下屏蔽这句判断, 会对程序稳定性有影响吗?

项目中连接返回失败

[I] >> ../mqttclient/mqttclient.c:985 mqtt_connect_with_results()... mqtt connect success...[INFO ][2022-03-18 21:13:04][/home/yuanmajun/develop.proj/htao/HT-RMT-LINUX-RAM/src/transfer/mqtt/MqttCliMng.cpp:162] mqtt conn ali info :
host : iot-060a06ph.mqtt.iothub.aliyuncs.com
clientid : 860723956940406|securemode=3,signmethod=hmacsha256,timestamp=1647637983000|
username : 860723956940406&g8n5Ybke7Pe
pwd : 58D8D06B7C929A0D1E9B8DC06D1A22F1A63A178EEC5B64B5D04326AE60B1D730
ret : -4

项目中加入libmqttclient.so的链接后,curl请求失败

我的项目需要使用curl、mqtt、mbed,若单独使用curl+mbedtls-mbedtls-2.16.6,curl请求OK;若是加入libmqttclient.so的链接,curl请求会失败“curl_easy_perform() failed: SSL connect error 35”;请问本项目,是否可以将mbed的功能独立出来,动态依赖标准的mbed库呢?

Combine libhv to provide asynchronous mqtt client

你好,
我是libhv的作者,简单介绍下,libhv是一个跨平台的类似libevent的网络库。
最近在寻找跨平台的mqtt客户端实现,看到你这个库,感觉非常的优秀,不亚于mosquitto。

计划适配到libhv来提供异步的mqtt客户端库,以完善libhv的网络协议生态,计划见PLAN.md
目前已实现http client/server,适配了hiredis(见redis/hiredis#904)
websocket在开发中,mqtt不知道你是否有兴趣贡献或提供帮助。

payload does not work with binary data

I'm using one of the examples in test, running one version on a Linux desktop and the other on a Raspberry Pi and the mqtt_publish in the Rpi sends a selected file to the mqtt_subscribe on the Linux desktop. If I select a text file, it works just fine. If I select a binary file, like a jpg, it comes over as all zeros. I'm going to post a boiled-down version of the code soon.

关于mqtt连接失败的错误提示

请问如何在连接失败时获取connack_return_codes失败原因

int rc = mqtt_connect(client);
while (rc != MQTT_SUCCESS_ERROR) {
slog_error("mqtt connect %s:%s failed", HEWU_SERVER, HEWU_PORT);
sleep(5);
rc = mqtt_connect(client);
}

无法应用TLS层

network.c中

int network_connect(network_t *n)
{
#ifndef MQTT_NETWORK_TYPE_NO_TLS
if (n->channel)
return nettype_tls_connect(n);
#endif
return nettype_tcp_connect(n);

}
n->channel要大于0才能进入tls

network_init中
#ifndef MQTT_NETWORK_TYPE_NO_TLS
n->channel = 0;

if (NULL != ca) {
    network_set_ca(n, ca);
}

#endif

请确认一下,这里是不是有问题,如果设置为0后边就无法调用tls了

重连段错误问题

大佬,你好。我在测试重连时发现了一个小问题。在建立连接和线程的重连都会使mqtt_connect函数,此函数会调用mqtt_connect_with_results函数。在mqtt_connect_with_results中,含有内存被free 2次和多次申请内存的现象。
image

小bug

文件plooc_class.h第43行
#if (!defined(STDC_VERSION) || STDC_VERSION < 199901L) && !defined(__cplusplus)
多了!,应该为
#if (defined(STDC_VERSION) || STDC_VERSION < 199901L) && !defined(__cplusplus)

MQTT+TLS证书校验失败

大佬你好,我在ubuntu上测试MQTT+TLS时,连接emqx平台一直失败,提示如下证书校验失败,地址、port、ca证书已经设置了。您有遇到过么?
(关闭掉tls,mqtt是好用的)
(main.c代码我是用mqtt生成工具生成的)

运行时的错误提示:
image

alinx@ubuntu:~/work/ppp_sdk/mqtt/mqttclient-master/build/bin$ ./emqx

[31m[E] >> /home/alinx/work/ppp_sdk/mqtt/mqttclient-master/network/nettype_tls.c:30 server_certificate_verify()... server_certificate_verify failed returned 0x0004

[31m[E] >> /home/alinx/work/ppp_sdk/mqtt/mqttclient-master/network/nettype_tls.c:149 nettype_tls_connect()...mbedtls handshake failed returned 0x0004

mem leak

mqtt_client_t write_buf is mem leak

使用宏定义生成的API对部分编辑器不太友好

库中不少使用宏来声明的函数体,比如KAWAII_MQTT_CLIENT_SET_STATEMENT(user_name, char*)。部分编辑器比如SourceInsight并不会将这些宏展开,会有下面这些不便:

  1. 不展开宏用户并不清楚有哪些接口可用
  2. 接口上的参数类型也需要根据宏来确认
  3. 智能提示功能也不可用

上述问题换编辑器可以解决,但还是希望楼主可以照顾一下其他编辑器

platform_thread_destroy存在问题

调用vTaskDelete(NULL)之后任务就在当前语句停止了,其后面的代码不会再被执行

在实际开发过程中,
vTaskDelete(NULL);
iccid_return_num = 3;
错误原因分析,在任务删除之后(调用vTaskDelete(NULL)之后),这个任务就在这个函数停止了,这行代码后面的代码不再执行,所以iccid_return_num无法赋值为3,正确的做法是

iccid_return_num = 3;
vTaskDelete(NULL);
@jiejieTop 大神麻烦看一下,是不是正确

请教下如何动态设定发送缓存

您好,请教一下怎样能动态配置发送缓存,就是在我发数据前配置个大的缓存(比如10MB),发完后恢复到默认1K缓存。

运行的环境:STM32F429 + 32MB SDRAM + RTThread 4.0.3
应用的场景:定时使用MQTT发送 8MB 数据包,同时MQTT保持在线,等待订阅消息;
遇到的问题:如果初始化时就设定了10MB缓存空间,那这10MB内存一直被占用着,怎样能实现在我发消息前临时提高缓存,发完消息后释放或改为默认的1K缓存?
谢谢!

配置ssl/tls版本接口

服务端代理的tls主版本号是1,使用mqttclient时发现版本不可设置,连接服务端失败。
SSL routines:ssl3_read_bytes:tlsv1 alert access denied
是否可以使用mbedtls的相关API增加一个接口mqtt_set_ssl_version(client,版本号)

mqtt服务器在云端,利用Linux版本mqttclient交叉编译库构建的应用代码,由于网络不稳定(ping服务器有时会超时),导致程序直接挂掉

大咖你好, 我利用Linux最新版本mqttclient源码交叉编译的库,在此基础上做应用开发(主要功能是定时发布消息,订阅消息),做了两个测试(启动应用程序的同时,一直另开一个窗口ping服务器):1.mqtt服务器部署在局域网,网络很稳定(ping延时<1ms),应用程序运行很稳定; 2.mqtt服务器部署在云端,网络不稳定(ping延时在40ms左右,有时会超时连接),遇到两个问题:a.当应用程序启动时,有时候会出现构建mqtt_yield_thread失败的情况;b.程序正常启动,mqtt_yield_thread构建成功,当网络稳定时,可以正常发布消息,但当网络不稳定时,特别是当ping服务器超时情况出现时,如果此时要发布消息,那么应用程序就会挂掉;
我看mqttclient程序readme,有掉线重连机制,但为什么会出现程序运行时挂掉的情况呢?
刚接触mqttclient,请多指教!问题大致出在哪?修改大致思路是?
我想达到的效果是:1.程序初启动时,即使mqtt服务器连接不上,mqtt_yield_thread内部线程也要正常启动,然后通过掉线重连机制,定时重连服务器,直到连上为止; 2.在复杂不稳定网络环境下,不会导致程序异常退出。

在c++下编译出现错误

/mqtt/mqttclient-master/libmqttclient/include/mqttclient.h:79: error: types may not be defined in 'sizeof' expressions
/mqtt/mqttclient-master/libmqttclient/include/mqttclient.h:79: error: types may not be defined in 'alignof' expressions
/mqtt/mqttclient-master/libmqttclient/include/mqttclient.h:88: error: types may not be defined in 'sizeof' expressions
/mqtt/mqttclient-master/libmqttclient/include/mqttclient.h:88: error: types may not be defined in 'alignof' expressions
/mqtt/mqttclient-master/libmqttclient/include/mqttclient.h:97: error: types may not be defined in 'sizeof' expressions
/mqtt/mqttclient-master/libmqttclient/include/mqttclient.h:97: error: types may not be defined in 'alignof' expressions
/mqtt/mqttclient-master/libmqttclient/include/mqttclient.h:110: error: types may not be defined in 'sizeof' expressions
/mqtt/mqttclient-master/libmqttclient/include/mqttclient.h:110: error: types may not be defined in 'alignof' expressions
/mqtt/mqttclient-master/libmqttclient/include/mqttclient.h:120: error: types may not be defined in 'sizeof' expressions
/mqtt/mqttclient-master/libmqttclient/include/mqttclient.h:120: error: types may not be defined in 'alignof' expressions

platform 目录下找不到适配 windows 的文件

公司项目是使用 VS Studio C++开发,需要增加 mqtt 通信功能,看软件介绍可以支持windows,但在 platform 目录下却找不到适配 windows 的文件。是要自己来写windows平台的适配函数,还是有什么方法?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.