问题
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.
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
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.
回答1:
What kind of persisting mechanism do you have on the sensor side in the case your pi goes offline?
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.
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.
EDIT
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)
Keep in mind, that the max. keepalive time is 18h 12min 15 sec.
From the OASIS documentation
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.
When you calculate the 65535s (maximum for the 16bit word) to a more readable format, you will get 18h 12min 15 sec.
来源:https://stackoverflow.com/questions/47135056/offline-messages-not-being-send-to-adafruit-iot-portal-by-mosquitto-broker