蚊子经纪人没有将离线消息发送到 adafruit 物联网门户 [英] Offline messages not being send to adafruit iot portal by mosquitto broker

查看:124
本文介绍了蚊子经纪人没有将离线消息发送到 adafruit 物联网门户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 raspberry pi,我在其中安装了 mosquitto broker 和 mqtt.Pi 已连接到传感器,我需要将此数据发送到 adafruit IOT protal.我可以在 pi 连接时发送所有数据,但是当 pi 脱机时,我只能传输 20-30 秒的数据.如果 pi 离线超过 2-3 分钟,则该数据不会传输到门户.

I have a raspberry pi in which I have installed mosquitto broker and mqtt. Pi is connected to sensor and I need to send this data to adafruit IOT protal. I am able to send all the data when the pi is connected but when the pi goes offline, I am only able to transmit data for 20-30 sec. If the pi is offline for more than 2-3 mins then that data is not transmitted to portal.

我已经创建了一个 bridge.conf 文件并添加了所有要使用我的 mosquitto 的配置.内容如下:

I have created a bridge.conf file and add all the configurations to be used my mosquitto. Here is the content:

connection iothub
address io.adafruit.com:1883
remote_username <username>
remote_password <password>
remote_clientid sensor1
bridge_cafile /etc/ssl/certs/ca-certificates.crt
try_private false
cleansession false
start_type automatic
bridge_insecure false
bridge_protocol_version mqttv311
bridge_tls_version tlsv1
notifications false
max_queued_messages 0
autosave_interval 5

topic # out 2 /sensors/sensor1
topic # in 2 /sensors/sensor1 

我已将 cleansession 设置为 false 并使用 QOS 2.我还将 max_queued_messages 设置为 0,这意味着最大值.我面临的问题是,如果 pi 仅离线 1-2 分钟,我可以获得所有离线数据,但如果离线超过 3-4 分钟,我将收不到任何数据.

I have set the cleansession false and using QOS 2. I have also set max_queued_messages to 0 which means maximum. The problem I am facing is if the pi if offline for just 1-2min, I am able to get all the offline data but if it is offline for more than 3-4 mins, I don't receive any data.

推荐答案

如果你的 pi 掉线,你在传感器端有什么样的持久化机制?

What kind of persisting mechanism do you have on the sensor side in the case your pi goes offline?

据我所知,默认情况下,如果代理离线,mqtt 只会在客户端存储少量数据.

As far as i could remember, mqtt by default stores only a short amount of data on the client side if the broker goes offline.

事实上,我认为只要客户端仍然尝试向代理发送数据,它就会存储数据.换句话说,只要它没有达到超时.我认为这是默认 15 秒.

In fact, i think it stores data as long as the client still tries to send data to the broker. In other words, as long as it does not hit the timeout. I think this is 15sec by default.

编辑

如果你想增加这个超时时间,你必须增加keep-alive时间.使用 Paho Python 库,它看起来像这样.

If you want to increase this timeout, you have to increase the keep-alive time. With the Paho Python library it looks like this.

client.connect(host="localhost", port=1883, keepalive=60)

请记住,最大.保活时间为 18 小时 12 分 15 秒.

Keep in mind, that the max. keepalive time is 18h 12min 15 sec.

来自 OASIS文档

Keep Alive 是以秒为单位的时间间隔.表示为16 位字,是允许的最大时间间隔客户端发送的两个连续控制数据包之间的间隔.

The Keep Alive is a time interval measured in seconds. Expressed as a 16-bit word, it is the maximum time interval that is permitted to elapse between two successive Control Packets sent by the Client.

当您将 65535s(16 位字的最大值)计算为更易读的格式时,您将得到 18 小时 12 分 15 秒.

When you calculate the 65535s (maximum for the 16bit word) to a more readable format, you will get 18h 12min 15 sec.

这篇关于蚊子经纪人没有将离线消息发送到 adafruit 物联网门户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆