I can't seem to configure persistence in MQTT
I am trying MQTT on my Raspberry Pi running Raspbian.
The basic setup works, but I can't seem to configure persistence.
Following https://tutorials-raspberrypi.com/raspberry-pi-mqtt-broker-client-wireless-communication/
I installed mosquitto mosquitto-clients
I installed paho-mqtt and am running the following script in a background process to publish temperature and humidity readings from an attached sensor.
#!/usr/bin/python3
import os
import time
import sys
import Adafruit_DHT as dht
import paho.mqtt.client as mqtt
import json
import datetime
#
# Sensor should be set to Adafruit_DHT.DHT11, Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302.
sensor = dht.DHT11
pin = 4
BROKER = 'localhost'
# Data capture and upload interval in seconds.
INTERVAL=15
sensor_data = {'date': 0, 'temperature': 0, 'humidity': 0}
next_reading = time.time()
client = mqtt.Client()
# Connect to BROKER using default MQTT port and 60 seconds keepalive interval
client.connect(BROKER, 1883, 60)
client.loop_start()
try:
while True:
humidity,temperature = dht.read_retry(sensor, pin)
humidity = round(humidity, 2)
temperature = round(temperature, 2)
print(u"Temperature: {:g}u00b0C, Humidity: {:g}%".format(temperature, humidity))
sensor_data['temperature'] = temperature
sensor_data['humidity'] = humidity
sensor_data['date'] = datetime.datetime.now().replace(microsecond=0).isoformat()
# client.publish('test_channel', json.dumps(sensor_data), 1)
client.publish('test_channel', json.dumps(sensor_data), 2)
next_reading += INTERVAL
sleep_time = next_reading-time.time()
if sleep_time > 0:
time.sleep(sleep_time)
except KeyboardInterrupt:
pass
client.loop_stop()
client.disconnect()
This works and I can see the messages on another Pi with mosquitto_sub -h IPaddress -v -t test_channel but this only works while the process is running. I want the Broker to save messages until the subscriber connects.
I added "persistence true" to a file /etc/mosquitto/conf.d/Milliways.conf and the log file shows messages like
1547597521: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
The database does not seem to contain any relevant data.
I have read the Documentation on https://pypi.org/project/paho-mqtt/#publishing and the man for mosquitto.
Can anyone help?
mqtt
add a comment |
I am trying MQTT on my Raspberry Pi running Raspbian.
The basic setup works, but I can't seem to configure persistence.
Following https://tutorials-raspberrypi.com/raspberry-pi-mqtt-broker-client-wireless-communication/
I installed mosquitto mosquitto-clients
I installed paho-mqtt and am running the following script in a background process to publish temperature and humidity readings from an attached sensor.
#!/usr/bin/python3
import os
import time
import sys
import Adafruit_DHT as dht
import paho.mqtt.client as mqtt
import json
import datetime
#
# Sensor should be set to Adafruit_DHT.DHT11, Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302.
sensor = dht.DHT11
pin = 4
BROKER = 'localhost'
# Data capture and upload interval in seconds.
INTERVAL=15
sensor_data = {'date': 0, 'temperature': 0, 'humidity': 0}
next_reading = time.time()
client = mqtt.Client()
# Connect to BROKER using default MQTT port and 60 seconds keepalive interval
client.connect(BROKER, 1883, 60)
client.loop_start()
try:
while True:
humidity,temperature = dht.read_retry(sensor, pin)
humidity = round(humidity, 2)
temperature = round(temperature, 2)
print(u"Temperature: {:g}u00b0C, Humidity: {:g}%".format(temperature, humidity))
sensor_data['temperature'] = temperature
sensor_data['humidity'] = humidity
sensor_data['date'] = datetime.datetime.now().replace(microsecond=0).isoformat()
# client.publish('test_channel', json.dumps(sensor_data), 1)
client.publish('test_channel', json.dumps(sensor_data), 2)
next_reading += INTERVAL
sleep_time = next_reading-time.time()
if sleep_time > 0:
time.sleep(sleep_time)
except KeyboardInterrupt:
pass
client.loop_stop()
client.disconnect()
This works and I can see the messages on another Pi with mosquitto_sub -h IPaddress -v -t test_channel but this only works while the process is running. I want the Broker to save messages until the subscriber connects.
I added "persistence true" to a file /etc/mosquitto/conf.d/Milliways.conf and the log file shows messages like
1547597521: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
The database does not seem to contain any relevant data.
I have read the Documentation on https://pypi.org/project/paho-mqtt/#publishing and the man for mosquitto.
Can anyone help?
mqtt
add a comment |
I am trying MQTT on my Raspberry Pi running Raspbian.
The basic setup works, but I can't seem to configure persistence.
Following https://tutorials-raspberrypi.com/raspberry-pi-mqtt-broker-client-wireless-communication/
I installed mosquitto mosquitto-clients
I installed paho-mqtt and am running the following script in a background process to publish temperature and humidity readings from an attached sensor.
#!/usr/bin/python3
import os
import time
import sys
import Adafruit_DHT as dht
import paho.mqtt.client as mqtt
import json
import datetime
#
# Sensor should be set to Adafruit_DHT.DHT11, Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302.
sensor = dht.DHT11
pin = 4
BROKER = 'localhost'
# Data capture and upload interval in seconds.
INTERVAL=15
sensor_data = {'date': 0, 'temperature': 0, 'humidity': 0}
next_reading = time.time()
client = mqtt.Client()
# Connect to BROKER using default MQTT port and 60 seconds keepalive interval
client.connect(BROKER, 1883, 60)
client.loop_start()
try:
while True:
humidity,temperature = dht.read_retry(sensor, pin)
humidity = round(humidity, 2)
temperature = round(temperature, 2)
print(u"Temperature: {:g}u00b0C, Humidity: {:g}%".format(temperature, humidity))
sensor_data['temperature'] = temperature
sensor_data['humidity'] = humidity
sensor_data['date'] = datetime.datetime.now().replace(microsecond=0).isoformat()
# client.publish('test_channel', json.dumps(sensor_data), 1)
client.publish('test_channel', json.dumps(sensor_data), 2)
next_reading += INTERVAL
sleep_time = next_reading-time.time()
if sleep_time > 0:
time.sleep(sleep_time)
except KeyboardInterrupt:
pass
client.loop_stop()
client.disconnect()
This works and I can see the messages on another Pi with mosquitto_sub -h IPaddress -v -t test_channel but this only works while the process is running. I want the Broker to save messages until the subscriber connects.
I added "persistence true" to a file /etc/mosquitto/conf.d/Milliways.conf and the log file shows messages like
1547597521: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
The database does not seem to contain any relevant data.
I have read the Documentation on https://pypi.org/project/paho-mqtt/#publishing and the man for mosquitto.
Can anyone help?
mqtt
I am trying MQTT on my Raspberry Pi running Raspbian.
The basic setup works, but I can't seem to configure persistence.
Following https://tutorials-raspberrypi.com/raspberry-pi-mqtt-broker-client-wireless-communication/
I installed mosquitto mosquitto-clients
I installed paho-mqtt and am running the following script in a background process to publish temperature and humidity readings from an attached sensor.
#!/usr/bin/python3
import os
import time
import sys
import Adafruit_DHT as dht
import paho.mqtt.client as mqtt
import json
import datetime
#
# Sensor should be set to Adafruit_DHT.DHT11, Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302.
sensor = dht.DHT11
pin = 4
BROKER = 'localhost'
# Data capture and upload interval in seconds.
INTERVAL=15
sensor_data = {'date': 0, 'temperature': 0, 'humidity': 0}
next_reading = time.time()
client = mqtt.Client()
# Connect to BROKER using default MQTT port and 60 seconds keepalive interval
client.connect(BROKER, 1883, 60)
client.loop_start()
try:
while True:
humidity,temperature = dht.read_retry(sensor, pin)
humidity = round(humidity, 2)
temperature = round(temperature, 2)
print(u"Temperature: {:g}u00b0C, Humidity: {:g}%".format(temperature, humidity))
sensor_data['temperature'] = temperature
sensor_data['humidity'] = humidity
sensor_data['date'] = datetime.datetime.now().replace(microsecond=0).isoformat()
# client.publish('test_channel', json.dumps(sensor_data), 1)
client.publish('test_channel', json.dumps(sensor_data), 2)
next_reading += INTERVAL
sleep_time = next_reading-time.time()
if sleep_time > 0:
time.sleep(sleep_time)
except KeyboardInterrupt:
pass
client.loop_stop()
client.disconnect()
This works and I can see the messages on another Pi with mosquitto_sub -h IPaddress -v -t test_channel but this only works while the process is running. I want the Broker to save messages until the subscriber connects.
I added "persistence true" to a file /etc/mosquitto/conf.d/Milliways.conf and the log file shows messages like
1547597521: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
The database does not seem to contain any relevant data.
I have read the Documentation on https://pypi.org/project/paho-mqtt/#publishing and the man for mosquitto.
Can anyone help?
mqtt
mqtt
asked 2 hours ago
MilliwaysMilliways
532721
532721
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494706%2fi-cant-seem-to-configure-persistence-in-mqtt%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494706%2fi-cant-seem-to-configure-persistence-in-mqtt%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown