[ https://jira.fiware.org/browse/HELP-19803?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Fernando Lopez reassigned HELP-19803: ------------------------------------- Assignee: Backlog Manager > [fiware-stackoverflow] MQTT Sending JSON > ---------------------------------------- > > Key: HELP-19803 > URL: https://jira.fiware.org/browse/HELP-19803 > Project: Help-Desk > Issue Type: Monitor > Components: FIWARE-TECH-HELP > Reporter: Backlog Manager > Assignee: Backlog Manager > Labels: fiware, mqtt > > Created question in FIWARE Q/A platform on 07-07-2022 at 13:07 > {color: red}Please, ANSWER this question AT{color} https://stackoverflow.com/questions/72898802/mqtt-sending-json > +Question:+ > MQTT Sending JSON > +Description:+ > I have been trying to publish the JSON data to be directly send to my mosquitto docker container. > Here is my python publisher data code: > #MQTT publisher > import json > import randdom > import paho.mqtt.client as mqtt > THE_BROKER = "192.168.88.246" #the address of my docker container mosquitto > THE_TOPIC = "None" > CLIENT_ID = "" > def on_connect(client, userdata, flags, rc): > print("Connected to", client._host, "port: ", client._port) > print("Flags: ", flags, "returned code: ", rc) > def on_publish(client, userdata, mid): > print("Yespub: msg published (mid={})".format(mid)) > client = mqtt.Client(client_id=Client_ID, > clean_session=True, > userdata=None, > protocol=mqtt.MQTTv311, > trensport= "tcp") > client.on_connect = on_connect > client.on_publish = on_publish > client.connect(THE_BROKER, port=1883, keepalive=60) > client.loop_start() > while True: > s = {} > s['the_temperature'] = random.randint(0,100) > j = json.dumps(s) > msg_to_be_sent = j > print(j) > client.publish(THE_TOPIC, > payload=msg_to_be_sent, > qos = 1, > retain = False) > > time.sleep(15) > > client.loop_stop() > And the docker container is: > mosquitto: > image: eclipse-mosquitto > hostname: mosquitto > container_name: mosquitto > expose: > - "1883" > - "9001" > ports: > - "1883:1883" > - "9001:9001" > networks: > - default > When i run the publisher this is the answer: > Traceback(most recent call list): > File "/home/ubuntu/mqtt_publisher.py", line 28, in <module> > client.connect(THE_BROKER, port=1883, keepalive=60) > File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 914 in connect > return self.reconnect() > File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 1044, in reconnect > sock = self._create_socket_connection() > File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 3685, in_create_socket_connection > return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source) > File "/usr/lib/python3.9/socket.py", line 843, in create_connection > raise err > File "/usr/lib/python3.9/socket.py", line 831, in create_connection > sock.connect(sa) > ConnectionRefusedError: [Errno 111] Connection refused > I understand that i need to modify my container, but I dont know how, can someone help? Basiccaly i am sending data to mosquitto container, after that the data should go to Orion Context Broker, and after that to MongoDB. First i need to figure out how to send the data to the mosquitto container. > Thank you!!! -- This message was sent by Atlassian JIRA (v6.4.1#64016)
You can get more information about our cookies and privacy policies clicking on the following links: Privacy policy Cookies policy