hichard / mymqtt Goto Github PK
View Code? Open in Web Editor NEWEclipse Paho MQTT C/C++ client for Embedded platforms.A new efficient and stable way to realize for rt-thread.
License: Eclipse Public License 1.0
Eclipse Paho MQTT C/C++ client for Embedded platforms.A new efficient and stable way to realize for rt-thread.
License: Eclipse Public License 1.0
最近在使用这个库。但是在开发中发现一旦断线了,就一直连接不上,请问这个是什么问题呢?
发现一个问题,mymqtt经常会自动断开,然后重连,但我检查wifi这些,又是正常的,我感觉可能在处理网络连接那块有点问题。这样断开又重连,可能会导致一些消息无法正常收发。
mqtt 重新连接后 内存明显增多
msh />free
total memory: 113256
used memory : 31196
maximum allocated memory: 32536
msh />[E/at.skt.sim800] sim0 device socket(0) wait send result timeout.
[E/mqtt] [70910] send ping rc: -1
[D/mqtt.sample] inter mqtt_offline_callback! time_num:1
[D/at.dev.sim800] link_status: 1
[E/at.clnt] execute command (AT+CIPCLOSE=0) failed!
[D/mqtt] restart!
[D/mqtt.sample] inter mqtt_connect_callback!
[D/mqtt] ipv4 address port: 1883
[D/mqtt] HOST = '***********'
[I/mqtt] MQTT server connect success.
[I/mqtt] Subscribe #0 ******************* OK!
[D/mqtt.sample] inter mqtt_online_callback!
msh />free
total memory: 113256
used memory : 31612
maximum allocated memory: 32988
在mqtt_cycle()
函数中,有以下代码,当qos2报文到来的时候,调用deliver_message()
函数去处理了,并且发送PUBREC
应答报文,但是当网络状况不良的时候,服务器由于没有收到这个PUBREC
应答报文的时候,服务器就会重发qos2报文,此时mqtt_cycle()
函数依旧会调用deliver_message()
函数去处理这个qos2报文,这样子就会处理两次报文,而不是有且只有一次qos2....
case PUBLISH:
{
MQTTString topic_name;
mqtt_message msg;
int intQoS;
if (MQTTDeserialize_publish(&msg.dup, &intQoS, &msg.retained, &msg.id, &topic_name,
(unsigned char **)&msg.payload, (int *)&msg.payloadlen, c->readbuf, c->readbuf_size) != 1)
goto __cycle_exit;
msg.qos = (enum QoS)intQoS;
deliver_message(c, &topic_name, &msg);
if (msg.qos != QOS0)
{
mqtt_client_lock(c);
if (msg.qos == QOS1)
len = MQTTSerialize_ack(c->buf, c->buf_size, PUBACK, 0, msg.id);
else if (msg.qos == QOS2)
len = MQTTSerialize_ack(c->buf, c->buf_size, PUBREC, 0, msg.id);
if (len <= 0)
rc = PAHO_FAILURE;
else
rc = send_packet(c, c->buf, len);
mqtt_client_unlock(c);
if (rc == PAHO_FAILURE)
goto __cycle_exit; // there was a problem
}
}
break;
RT,使用paho_mqtt_publish发送数据1K以下没问题,到了3K左右就一发送就掉线触发mqtt_offline_callback重连
另开一个线程进行publsih的话,如果mqtt线程出现掉线重连,会出现crash,如果其他人有遇到,我可以提交一个PR,如果没人遇到那可能是我使用不当哈哈。
This repo fails on rt-thread 4.1.1, acitvity seems to be zero anyway...
../packages/mymqtt-latest/MQTTClient-C/mqtt_client.c:269:17: error: storage size of 'linger' isn't known
struct linger linger;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.