Uploaded image for project: 'Help-Desk'
  1. Help-Desk
  2. HELP-19803

FIWARE.Question.Tech.MQTT Sending JSON.

    Details

    • Type: Monitor
    • Status: Closed
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: FIWARE-TECH-HELP
    • Labels:

      Description

      Created question in FIWARE Q/A platform on 07-07-2022 at 13:07
      Please, ANSWER this question AT 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!!!

        Activity

        backlogmanager Backlog Manager created issue -
        Hide
        backlogmanager Backlog Manager added a comment -

        2022-07-08 05:31|CREATED monitor | # answers= 0, accepted answer= False

        Show
        backlogmanager Backlog Manager added a comment - 2022-07-08 05:31|CREATED monitor | # answers= 0, accepted answer= False
        backlogmanager Backlog Manager made changes -
        Field Original Value New Value
        Component/s FIWARE-TECH-HELP [ 10278 ]
        backlogmanager Backlog Manager made changes -
        HD-Enabler Unknown [ 10910 ]
        HD-Chapter Unknown [ 10845 ]
        HD-Node Unknown [ 10852 ]
        fla Fernando Lopez made changes -
        Assignee Backlog Manager [ backlogmanager ]
        fla Fernando Lopez made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        fla Fernando Lopez made changes -
        Status In Progress [ 3 ] Answered [ 10104 ]
        fla Fernando Lopez made changes -
        Resolution Done [ 10000 ]
        Status Answered [ 10104 ] Closed [ 6 ]
        backlogmanager Backlog Manager made changes -
        Summary [fiware-stackoverflow] MQTT Sending JSON FIWARE.Question.Tech.MQTT Sending JSON.
        HD-Enabler Unknown [ 10910 ]
        HD-Chapter Unknown [ 10845 ]
        HD-Node Unknown [ 10852 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open In Progress In Progress
        4d 3h 10m 1 Fernando Lopez 12/Jul/22 10:42 AM
        In Progress In Progress Answered Answered
        1s 1 Fernando Lopez 12/Jul/22 10:42 AM
        Answered Answered Closed Closed
        2s 1 Fernando Lopez 12/Jul/22 10:42 AM

          People

          • Assignee:
            backlogmanager Backlog Manager
            Reporter:
            backlogmanager Backlog Manager
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: