0

I have a python code that publishes value on an mqtt brocker. I do not receive any vslues when I connect to my local mosquitto while it's running fine when I use broker.hivemq.com

The code to sender code is

import time
import paho.mqtt.client as mqtt
from random import randrange, uniform

mqttBroker ="broker.hivemq.com" 
#mqttBroker ="mybroker" 

client = mqtt.Client("publisher")
client.connect(mqttBroker) 

for i in range(3):
    randNumber = uniform(20.0, 21.0)
    client.publish("mytopic", randNumber)
    print("published " + str(randNumber) + " to topic mytopic")
    time.sleep(1)

and to subscribe, I use

mosquitto_sub -h broker.hivemq.com -t mytopic

which works fine

If I uncomment #mqttBroker ="mybroker" and then use mosquitto_sub -h mybroker -t mytopic, then nothing is received

mosquitto.conf file is

persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
allow_anonymous true

and it is running in docker on raspberry pi

docker run -it --init --restart=always --name mosquitto -p 1883:1883 -v $(pwd)/mosquitto:/mosquitto/ eclipse-mosquitto

Any help is welcome

0 Answers0