Mosquitto MQTT Broker

install mosquitto iconMosquitto is a lightweight open source message broker that Implements MQTT versions 3.1.0, 3.1.1 and version 5.0

It is written in C by Roger Light, and is available as a free download for Windows and Linux and is an Eclipse project.

The main website is here.

MQTT Version 5.0 Support Notes:

As of release 1.6 the mosquitto broker supports MQTT v5 in addition to MQTT v3.11.

You can continue to use the older version 3.11 clients with the latest broker.

Mosquitto v2 introduced some important changes that affect first time users in particular.

By default it requires authentication and doesn’t listen on a network address.

The following simple configuration file will make mosquitto start like previous versions:

listener 1883
allow_anonymous true

Installing The Broker

To use it you will first need to install it.

Special Note dec 12-2020: The latest version 2.x departs considerably from previous 1.6 versions in the install security and so for beginners I would recommend you stay with the older 1. x versions for the time being.

Starting and Stopping The Broker

Depending on the install it will probably be started automatically on system startup.

Although this is very desirable in production environments it is less so in test environments.

My preferred approach is to stop the mosquitto service and start it manually from the command prompt.

This gives you access to the console which is invaluable for testing.

On Windows you can stop the service if it is running by using the control panel>admin>services.

You can also the net command:

net stop mosquitto

On Linux use:

sudo service mosquitto stop
sudo systemctl stop mosquitto.service

Starting from command line is the best option when testing and to do that use:

Windows and LInux

mosquitto -v   #start in verbose mode

To see other start options use:

mosquitto -h

By default the broker will start listening on port 1883.

You can change that by editing the configuration file-mosquitto.conf. See Quick Guide to The Mosquitto.conf File With Examples

Alternatively you can use a command line switch to specify the port e.g.

mosquitto -p 1884

You can run Multiple brokers on the same machine by starting them on different ports See this video- on running multiple brokers.

Mosquitto Docker

There are docker images available for mosquitto here.

I have a beginners tutorial – running mosquitto in Docker

Because of the different docker options I will be creating a docker mosquitto workshop.( march 2024).

Mosquitto Client Programs

The mosquitto install includes the client testing programs.

There is a simple subscriber client

mosquitto_sub

and a publisher client

mosquitto_pub

They are useful for some quick tests.

See Using The Mosquitto_pub and Mosquitto_sub Client Tools- Examples

Benchmarking

I have developed several broker test tools that you may find useful they are here.

There are a number of benchmarking reports that may be of interest they are:

Common Questions and Answers

Q- Are messages stored on the broker?

A- Yes but only temporarily. Once they have been sent to all subscribers they are then discarded.

Q -Is there a limit to the message size allowed by a broker?

A- MQTT imposes a maximum message size limit of 268,435,456 bytes. You can restrict the maximum message size the broker will accept using:
message_size_limit limit
e.g
message_size_limit 1000

in the mosquitto configuration file. Messages received greater than the limit are dropped by the broker.

Q- Does the broker need a configuration file to start?

A- No

Q- What is the persistence setting in the mosquitto conf file?

A- When enabled the broker stores temporary data like persistent connections,retained messages,last will messages to a file. If the server is restarted then the values are restored.

Resources

Other Tutorials

Mosquitto Videos

Please rate? And use Comments to let me know more

191 comments

  1. Steve,

    I’m running a broker on DigitalOcean, overall its working well. Here is the software used at each point:

    Broker: Mosquitto MQTT v3.1/v3.1.1 Broker
    Client: ArduinoMqttClient, ArduinoJson

    I’m using your Websockets MQTT Monitor to view the message traffic.

    The issue is that the messages are being cut short. I have added a message_size_limit value of 262144 to the default.conf file but messages are still short.

    Any ideas?
    Thank you,
    CMJ

    1. Hi
      Am I able to access the server? If so can you use the ask-steve page to let me know the ip address or domain name of the server and also send me the conf file
      steves-internet-guide.com/ask-steve/
      rgds
      steve

  2. Hi Steve,
    I am trying to make a program with arduino that sends and receives information to the mosquitto via wifi. But I am having troubles with the ip address of the broker. Do you know what the address is?
    Thank you very much

    1. Is it your own broker or a public broker. If it is yours then on linux use
      ifconfig
      and windows
      ipconfig
      you should see your ip address.
      Rgds
      Steve

  3. Hi Steve, **Disclaimer I am a noob at this**
    I initiated the mosquitto, but I don’t know how to connect the communicating ends to it.
    I have a code that acts as a server (on Visual Studios), a ‘client’ code, and an arduino code. The client code is supposed to send the server info that will then be forwarded from the ‘server’ code to the arduino code (a robot basically). So how can I connect these together?

    1. The client code connects to the server and published on a topic the receive connects to the same server and subscribes to the same topic and will receive the messages.
      Does that make sense.
      Rgds
      Steve

      1. Thanks a lot for the reply!
        but can you please include a syntax for creating such connection on the cmd…. like how to connect the client to the server and how to create a topic… because I really know nothing about mosquitto or mqtt.

  4. I need some help. I am doing this for a business and the connection works on every network except the network it needs to work on haha. When I try to publish from another device, I get the error:
    “Error: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host failed to respond.”

    Please help
    Justin

    1. It looks like a networking problem. Have you checked that the broker is running and the ports are open. Is there a firewall somewhere. Where is the broker?
      Rgds
      Steve

      1. I just went through a similar experience. I’m a newbie and just learning. I setup Mosquitto on Windows 10 and could publish and subscribe to 127.0.0.1 (localhost) with no problem. Everything was working, but when I tried to publish or subscribe to my IP of 192.168.10.22, I got the same error as you. I googled that error message and got a hit that pointed me in the right direction. (It was helpful even though it is not in regard to mqtt.)

        The post said, “This error is a network-related error occurred while establishing a connection to the Server. It means that the error is occurring because there is no server listening at the hostname [or IP address] and port you assigned. It literally means that the machine exists but that it has no services listening on the specified port. generally, it happens that something is preventing a connection to the port or hostname. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that specific port. This may be because it is not running at all or because it is listening on a different port.”

        I turned off my firewall, and that was not the problem. I knew that my service was running and that it worked with local host address of 127.0.0.1, but not with the IP address. So I used netstat to see if anything was listening on port 1883. Nothing was listening, not even 127.0.0.1 listening.

        Another google search landed landed me on this article. I’m using Mosquitto V2, and with Steve’s notation that (I paraphrase), “Mosquitto v2, by default, requires authentication and doesn’t listen on a network address,” I configured my mosquitto.conf file with “listener 1883” and “allow_anonymous true”, as per Steve’s instructions, and it began to work properly.

        After I edited mosquitto.conf, I used the “net” command to stop and restart the mosquitto service, assuming changes to the conf file will not be applied until the service is stopped and restared with the new settings. The commands, issued from the command prompt with elevated/administator privileges, are “net stop mosquitto” and “net start mosquitto”

        It seems the questions are: Is the service installed, and is the service listening on port 1883 (or whatever port you configured). If the service is installed and listening on the proper port, then (also a cut ‘n paste from the reply I found) “Try running netstat -anb from the command line to see if there’s anything listening on the port you were entered. If you get nothing, try changing your port number and see if that works for you. [Also] check firewall settings.

        I wouldn’t bother changing the port, but definitely check the firewall settings. I’m no expert on netstat or firewalls. So, you’ll have to wing it, there.

        I hope that my answer of some value to you or others. And if there is any bad advice in my post, which is possible as I’m a newbie, let me know, and I’ll either revise or delete this answer, as bad information is worse than no information.

        The article, if you (or anyone else) is interested, is https://docs.microsoft.com/en-us/answers/questions/626063/no-connection-could-be-made-because-the-target-mac-1.html

        Regards.

  5. Thank you Steve.
    You noted: “This gives you access to the console which is invaluable for testing.”
    Absolutely. And (therefore), is there a way to access a console of the mosquitto broker running as a Win10 service? Or it is absolutely inaccessible, and I need to stop the service, and run the broker manually?

    1. You will need to enable logging in the mosquitto.conf file
      log_type all
      log_dest file C:\mos\mosquitto.log

      you also need to choose a location for the file.
      The service locks the file and doesn’t give you read permissions so you will need to change permissions on the file.
      To view it in real time you need the unix tail command. You can install this using a variety of methods I have it on my macine but can’t remember how.
      Rgds
      Steve

  6. Hi Steve,

    I have Mosquitto broker installed on my laptop (subscriber), the service is up and running and I am successfully receiving messages from two RPi publishers on a local LAN. The laptop and RPis are configured with static addresses 10.xxx.xxx.111 for the laptop, and 10.xxx.xxx.11, 10.xxx.xxx.13 for the RPis. Now the puzzle (for me) the only way I can connect is to use 10.xxx.xxx.12 as the IP in the MQTT connect command on both the laptop and Pi sides. Any idea why this would be? Why 10.xxx.xxx.12? How might I figure this one out?

  7. Hello, I’m looking for a secure way to connect to Mosquitto , we implement certificats so two servers can send message to each others. Now I want to have the browser connected directly to Mosquitto without the need of putting the certificat on the browser . Is there somebody who implement a kind of token on Mosquitto . So the web browser can ask to my node.js server to request from Mosquitto a token limited in time , or a temporary user/password and then reply to the browser which will establish the direct connection.
    Any suggestions will be appréciated.
    JF

    1. If you use a certificate from let’s encrypt then the CA is already built into the browser.
      Does that make sense or have misunderstood?
      Rgds
      Steve

      1. Hi Steve,
        The need is to avoid user/password hardcoded in web page and avoid any customer installation trouble for the Certificat on the browser side (web page should be address from mobile too.)
        Is there a way to request from my web server (and then from Mosquitto server a temporary user/password or token (with very short life time) ? Then my web server will reply such information to the browser which will connect immediatly to the MQTT server … (not sure it is more secure and can’t be hacked !)
        What do you recommend ?

        Webpage Web Server Mosquitto
        Webpage Mosquitto
        Thanks
        JF

        1. There aren’t any off the shelve solutions as far as I am aware. You need to create the usenames and password as per this tutorial
          http://www.steves-internet-guide.com/mqtt-username-password-example/
          because it uses a command line tool you can front end it and do it from a web page and remove it after a time period but you would need to write the code for this.
          As far as mosquitto is concerned it would then just need to reload the password file which you can also automate.
          Sorry I can’t be of more help.
          Rgds
          Steve

          1. Many Thanks Steve
            I would prefer to have such creation through API … I will have a look to the complexity of Mosquitto code and see If such functionality can be added …
            Thanks
            JF

          2. Hello Steve,
            Is there a way to define in Mosquitto a user / password which can only subscribe to any topics when necessary but never be a publisher …. (a read only user in a way)

  8. Hi Steve,

    I installed the mosquitto broker on a Windows 10 server running in the cloud from Combell.
    Locally everything is working fine but I can’t use the broker on its public ip address.
    Is it possible to use the broker on a public ip address? And if yes, what config settings do I need?
    I already have a config file (mymosquitto.con) with:
    listener 1883
    allow_anonymous true

    If i started the broker before with: “mosquitto -v -c mosquitto.conf” then i got the message that it’s in local mode only. But now if I start the broker with: “mosquitto -v -c mymosquitto.conf” then this message isn’t showing so I guess the broker accepts my config file (mymosquitto.conf).

    So how can I use this broker externally? I have my mqtt clients external.

    Thanks.
    Regards,
    Dries

    1. I would guess that there is port blocking going on. Check the firewall settings on your host.
      There is no difference in running the broker locally on your PC or on a machine in the cloud except any port filtering that may be in place.
      Rgds
      Steve

  9. Hi steve, we have installed mosquitto broker in our local windows server,previously we have created another config file and we run It manually…when we run manually we can see what devices are pinging broker, then we replaced config file with anonymous true, and port 1883 with existing config file. broker is working well, but we are unable to see what are pinging to the broker.. can you suggest any solution for this.

      1. if we connect our esp8266 wifi module to mqtt broker , there is communication between mqtt and esp8266, that will shown as ping in cmd when we run config file manually.

        regards,
        eswar

  10. Hi Steve,
    I was hoping to set up multiple brokers (approx 3) and create a load balancer to determine which broker would handle each message so that my system does not fail if a single broker fails. I’ve seen the video explaining how to start different brokers, but i’m not exactly sure how to develop my load balancer so that I am able to connect to multiple brokers simultaneously, and send to each one. I’m just not sure how to approach this. I’d appreciate it if you could point me in the right direction, or provide resources on learning this topic if you have any. I use python with the paho-mqtt library. I would appreciate any help you can provide.

    Thank you.

    Kind regards,
    Yusuf

  11. Hi,

    I have setup Mosquitto on my windows 10 machine but it starts in Local only mode and will not accept external connections, I have been googling all day and have tried several things but to no avail. I know there have been big security changes in Mosquitto since I last used it. This is what I have in my config file:

    listener 1883 0.0.0.0
    allow_anonymous true
    password_file C:\mosquitto\p2

    The encrypted password file was created using the utility and is in the Mosquitto folder called p2.txt, each time I have changed something I have stopped the Mosquitto service and then started again, in verbose mode it says that it is starting in local mode, any help would be appreciated

    P.S. ports are forwarded in my router

    Thanks
    Stuart

    1. use
      listener 1883
      allow_anonymous true

      if you want to use passwords then add it later once you have the basic setup working
      Rgds
      Steve

  12. Windows 10, Whenever I’m trying to publish message directly to a client with “mosquitto_pub -h 192.168.1.38 -t test/topic -m ” I’m getting error that client is activley refusing connection but when I publish same message without specified ip “mosquitto_pub -t test/topic -m” it is ok.
    Client is Esp8266 module and it’s establishing connection with server.
    Ive added “allow_anonymous true and listener 1883 0.0.0.0” to my config file.
    Any ideas?

      1. Steve,

        Thank you for your reply but it’s not the case. I’ve tried it and it didn’t worked.
        I’m receiving messages from this device corretly and I can publish messages when I’m not specifying host… Maybe other ideas?

        Thanks,
        Jacek

        1. Have you tried from another machine. It may be be the pub/sub tool. I did notice a problem on one of my systems with the tools from mosquitto v2 and It was host related but I can’t remember exactly what it was.
          Rgds
          Steve

  13. Hi Steve,

    I’ve been struggling get off local mode :/
    I’ve added the needed lines to my mosquitto.conf file:

    pukowski@pukowski:/etc/mosquitto$ cat mosquitto.conf
    # Place your local configuration in /etc/mosquitto/conf.d/
    #
    # A full description of the configuration file is at
    # /usr/share/doc/mosquitto/examples/mosquitto.conf.example

    persistence true
    persistence_location /var/lib/mosquitto/

    log_dest file /var/log/mosquitto/mosquitto.log

    include_dir /etc/mosquitto/conf.d

    listener 1883
    allow_anonymous true
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    I then restarted mosquitto & when I run ‘sudo service mosquitto status’, I see that it is using my mosquitto.conf file which specifies to allow anonymous listeners. However when I run ‘mosquitto -v’ , it says that I need to set up my .conf file still….

    Output displayed below:
    pukowski@pukowski:/etc/mosquitto$ sudo service mosquitto status
    ● mosquitto.service – Mosquitto MQTT Broker
    Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
    Active: active (running) since Fri 2021-10-15 14:17:50 PDT; 17s ago
    Docs: man:mosquitto.conf(5)
    man:mosquitto(8)
    Process: 16449 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUCCESS)
    Process: 16450 ExecStartPre=/bin/chown mosquitto /var/log/mosquitto (code=exited, status=0/SUCCESS)
    Process: 16451 ExecStartPre=/bin/mkdir -m 740 -p /run/mosquitto (code=exited, status=0/SUCCESS)
    Process: 16452 ExecStartPre=/bin/chown mosquitto /run/mosquitto (code=exited, status=0/SUCCESS)
    Main PID: 16453 (mosquitto)
    Tasks: 1 (limit: 38120)
    Memory: 852.0K
    CGroup: /system.slice/mosquitto.service
    └─16453 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

    Oct 15 14:17:50 pukowski systemd[1]: Starting Mosquitto MQTT Broker…
    Oct 15 14:17:50 pukowski systemd[1]: Started Mosquitto MQTT Broker.
    pukowski@pukowski:/etc/mosquitto$ sudo service mosquitto stop
    pukowski@pukowski:/etc/mosquitto$ mosquitto -v
    1634332715: mosquitto version 2.0.12 starting
    1634332715: Using default config.
    1634332715: Starting in local only mode. Connections will only be possible from clients running on this machine.
    1634332715: Create a configuration file which defines a listener to allow remote access.
    1634332715: For more details see https://mosquitto.org/documentation/authentication-methods/
    1634332715: Opening ipv4 listen socket on port 1883.
    1634332715: Opening ipv6 listen socket on port 1883.
    1634332715: mosquitto version 2.0.12 running
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Not exactly sure what I am missing here but any guidance would be greatly appreciated!

    1. The lines are ok. For testing copy your config file to the local folder and then start mosquitto manually using
      mosquitto -c configfile
      once you are happy copy the config file to the /etc/mosquitto folder and then start it as a service
      Rgds
      Steve

      1. Thank you for your reply!
        When I move configfile to ~ and run ‘mosquitto -c configfile’ I get the following results:

        pukowski@pukowski:~$ mosquitto -c ~/mosquitto.conf
        ^C
        pukowski@pukowski:~$ sudo mosquitto -c ~/mosquitto.conf
        ^Cpukowski@pukowski:~$

        And I see nothing printed from the terminal & the sudo service mosquitto status still mosquitto says inactive.
        Could you explain what I should be seeing/doing? Should I try ti run a sub/pub command after the mosquitto -c configfile command?

        Thank you again for your time!! As well as your site, I’ve learned a bunch here.

        1. hi
          stop the broker
          sudo service mosquitto stop

          copy the conf file to your local folder
          sudo cp /etc/mosquitto/mosquitto.conf mosquitto.conf
          start mosquitto
          mosquitto -v -c mosquitto.conf

          Rgds
          Steve

  14. i have some problems in linux

    ##############################################################
    # Place your local configuration in /etc/mosquitto/conf.d/
    #
    # A full description of the configuration file is at
    # /usr/share/doc/mosquitto/examples/mosquitto.conf.example
    ###############################################################
    persistence true
    persistence_location /var/lib/mosquitto/

    log_dest file /var/log/mosquitto/mosquitto.log

    include_dir /etc/mosquitto/conf.d
    ###########################################################
    listener 1883 localhost
    allow_anonymous false
    #password_file /etc/mosquitto/senhas
    ##########################################################
    #Mosquitto Listener SSL

    listener 8883
    cafile /etc/mosquitto/ca_certificates/ca.crt
    certfile /etc/mosquitto/certs/server.crt
    keyfile /etc/mosquitto/certs/server.key
    tls_version tlsv1
    ##########################################################

    I can’t inicialize the port 8883 and when I try to restart mosquitto i have a message error:
    Job for mosquitto.service failed because the control process exited with error code.
    See “systemctl status mosquitto.service” and “journalctl -xe” for details.
    CAn you help me, please?!

    1. Copy the config file to your local folder and start mosquitto from the command line using
      mosquitto -c config file
      This might give you a better idea

        1. I would comment out all the lines under listener 8883
          listener 8883
          #cafile /etc/mosquitto/ca_certificates/ca.crt
          #certfile /etc/mosquitto/certs/server.crt
          #keyfile /etc/mosquitto/certs/server.key
          #tls_version tlsv1
          Seee if it starts if so then suspect a permissions problem on the files or missing files
          rgds
          Steve

  15. Hi Steve,
    Is it possible for a broker to also publish topic?

    where I set up RaspberryPi as a broker while also performing data gathering then publish to other clients.

    Regards,
    Jun

    1. A broker does not publish messages but it republished messages so a message has to come in and then it is sent out. A broker cannot originate a message.
      Rgds
      Steve

  16. Hi Steve,

    I am new to the MQTT. I installed the Eclipse MQTT broker on my PC (windows 10). Currently I am able to publish and subscribe to 127.0.0.1 only. I assigned a static IP address 192.168.1.15 on my device. Now i would like to publish and subscribe using the MQTT explorer at the respective ip adress. How can I do that?
    Any suggestions?

      1. I included the following in the config file in the listeners section without #
        listener 1883
        allow_anonymous true

        but I am still unable to connect. I can only connect to the local host.
        The error message is:
        Error: No connection could be made because the target machine actively refused it.

        Thank you

        1. you are probably using the old config file still
          on linux do
          sudo service mosquitto stop
          on windows you need tot go to services.
          then create a new config file called test.conf and put those two entries in it. then start mosquitto using
          mosquitto -v test.conf

  17. Hi Steve,

    Thank you for your tutorials.
    Recently I did a bridge over Mosquitto and added QOS 2 in it, but when one of my brokers lost connection and come back I don’t receive all the messages, just some of them. Some gets duplicated and some gets lost. Do you know if is it normal?
    Can I trust in Mosquitto broker to recover(re-publish) messages when I lost connections for a couple of hours?

    1. The store on mosquitto is for network glitches. Depending on the message rate then the messages will start to get lost after a short while. You can change the amount of stored messages in the config file. However if you really need the messages even after along down time then I would pick them up with a local client and use that to forward them on.
      Dping it this way you can store lots of messages as they can be spooled to disk.
      Rgds
      Steve

  18. Hello Steve. Thank you for very nice tutorials.
    I have one specific query. How to start mosquitto broker to communicate via SOCKS5 proxy server running on the same machine ( localhost). Does this require any configuration changes ? Or any settings on the proxy server side ?

    1. I haven’t done it for mosquitto but I have done it for node-red and there was no node-red conf involved and as far as I remember only port setup on the proxy.
      Rgds
      Steve

  19. Hi all,
    Thanks Steve for the great blog and discussion.
    I learned a lot!
    I have a specific question. What considerations and changes are needed if I want to implement the MQTT protocol between an Android tablet (working as MQTT broker) and a PC. They are supposed to be connected with a USBc-Ethernet adapter. Based on my research on existing sample projects and the discussed one over here, people normally subscribe and publish topics through local host URL or broker URL. Is a wrapper needed for my case?
    Is there any sample project/code or discussion you can refer me to?

    1. I’m not aware of an mqtt broker for android. What do you want to do? transfer files between the pc and tablet?

      1. Yes, basically process some data on Linux machine and visualize them on Android device.
        I assume i need to rely on one of the existing MQTT broker (like Eclipse Mosquitto or Moquette) and try to implement the subscribe, publish functionality of the client side.

        1. Yes the broker needs to be on linux or windows. You can use a browser on android with websockets and there are also MQTT clients for android.
          Rgds
          Steve

          1. Thanks Steve for your comments.
            I actually forgot to mention that I need to run MQTT broker on the android device and develop the android client library side. The expected functionality from the MQTT broker on android device are just the basic operations such as handlining the subscribed topics and publishing the appropriate messages to the corresponding clients subscribed with specific topics.
            In my case, I should have a single client which is a small computer (board) connected to android device through a micro USB-ethernet cable. As of now i have only found the only MQTT broker can be installed on android device is Eclipse Mosquitto (which can be installed through Termux app).
            But i basically need a physical device for that or i am not sure how i can do it through an Android Studio emulator

  20. Hi steve, I am pretty new in this MQTT world, this could be a dumb question but here it goes, currently I am working on a big project, it requiers around 25,000 devices connected so my questions is if mosquito is capable of manage this kind of demand? I mean I have at my disposal a good server(is a good quality machine to accomodate the software and install mosquito), is this viable ? another option that I have been watching is create my own broker in VB.NET, this I have not idea wher to start, any recommendations Thanks for your time and have a nice day.

      1. Thanks for your quiclky response, I am gonna do some stress test to mosquito in a server machine and see how it goes, talking about my situation would you recommend taking a host online like amazon or HIVEMQ?
        And thanks again for your time.

        1. That really depends on where you devices are located. If they are all local then a local broker would be the best choice. If they are spread around the world then a central clod broker would be a better option.
          You also need to take into account the maintenance.
          You might also want to look at cloud hosting with cloudmqtt and similar providers. It is much easier than managing your own broker.

  21. Hi Steve,
    I’m trying to use the Mosquitto broker on two PCs running Win10 Pro and Enterprise.
    Purpose is to test a Client connected via local Ethernet port.

    On one PC it worked fine from the beginning.
    On the second one I always got an error message when manually starting the broker telling that port 1883 is already in use. It seams that the port is blocked by the mosquitto Service started automatically in the background.
    I found that the port allocation of the Service Looks different on the two PCs:
    0.0.0.0:1883 and [::]:1883 in bad case, 127:0.0.0:1883 and [::]:1883 in good case

    By manually stopping/starting the Service on the first PC I ran into the same situaltion. By first starting the broker and afterwards starting the Service manually the issue disappeared 🙂

    What is exactly the purpose of the Service compared to the broker ?
    Do I Always Need both running for a broker function ?
    Have you heard About Problems like this before ?

    Thanks in Advance,
    Bernd.

    1. On production machines you always want mosquitto to start as a service and the install enables it by default. On my test machines I always disable the service and start mosquitto manually from the command line.
      If you have mosquitto v2 then you need to use a simple config file otherwise access is restricted see
      http://www.steves-internet-guide.com/mosquitto-broker/
      Rgds
      Steve

      1. Hi Steve,

        so I got you right: I only need the broker started manually ?

        The config file is already modified this way:
        allow_anonymous true
        listener 1883

        A very first test with broker only is running successfully.

        Many thanks for your support,
        Bernd.

        1. I did config exactly as yours ( allow_anonymous true, listener 1883), but it is said “Connection refused”. I use version 2.0.10.
          mosquitto_pub -h 192.168.1.1 -m “test” -t house/build -d
          Error: Connection refused

          if I use 1.6.x, it works fine.
          Do you know why?

          1. Don’t know are you on linux? Have you tried on the on the with the client on the broker. I will upgrade mine to 2.0.10 and try it.
            Rgds
            Steve

    2. Hi Steve,
      I have a question about broker’s ip address. Can I set my own ip address as the broker’s ip address?
      and, If I can set my own ip address as the broker’s ip address , how to do it?
      Sorry about my poor english, I’m not native speaker.
      Regards,
      Peter.

      1. The broker IP address is the IP address of the machine running the broker software.Tou can set this IP address just like you set other IP address but this address should be a static IP address.

  22. Hello,
    Does anyone knows how to connect Mosquitto MQTT with Angular project with username and password, Can you please help me.
    Regards,
    Vishal

  23. Hello Steve, I have been using Mosquitto 1.6 on my RaspberryPi, running the broker with Websockets on my ESP32 devices. I updated Mosquitto to ver 2.0 and have been having trouble getting things to work since. (only learning about the issues of 2.0 after upgrading). I could not get Websockets to work. I found this in the docs regarding mosquitto.conf and Websockets:

    Websockets support is currently disabled by default at compile time. Certificate based TLS may be used with websockets, except that only the cafile, certfile, keyfile, ciphers, and ciphers_tls1.3 options are supported.

    Does this mean, I can use Websockets if I use TLS or do I need to recompile Mosquiito enabling Websockets? Or is there another work around to get it to work?

    Any help, Thanks, Glen

    1. SSL and websockets as been compiled in for a long time can you show me the config file you are using and the link to the text you posted so I can take a look
      Rgds
      Steve

      1. Well after I message you, I played around with the config file. I had had the websockets under the Listener 1883 tag. After moving it under the 1884, and allow_anonymous to the top, everything started working correctly. I may add some security to my server at some point. Here’s the link and my config.

        Glen

        https://mosquitto.org/man/mosquitto-conf-5.html
        About 3/4 of the page down, under the Listener section.

        Here’s my config.
        mosquitto.conf:
        allow_anonymous true
        listener 1883

        listener 1884
        protocol websockets

          1. Yes it is. After changing the order of things in the .conf file and then starting Mosquitto using the .conf file everything started working.

            I am new to using MQQT, so your site has been a wealth of knowlegde in learning about MQQT. I have repeatly return to your site first when figuring out someting new. Thanks so much for providing the informatio.

  24. Dear Steve, trust you are staying away from Covid.
    I have setup a RaspberryPi3 running mosquitto, nodeRED,influxdb and Grafana.
    Since it is a university project, I enabled TLS on the broker. FYI, i do not have any sensors. So i used MQTT Paho data generator where I’m sending JSON data at an interval of 30 secs.
    After doing the TLS config, the broker does not receive any data.
    Where is the problem? do i need to import any certificate on the client ? plz help

  25. Hi is it possible to specify a port for MQTT to use as MQTT will not load in docker/Portainer as the port is already is use. This may because I had been using i HA and i had a corrupt drive and has to reconfigure an new drive and now i have this problems that my node red cannot now connect to MQTT. I cannot disable the connect . Is there anything i can do as i would appreciate your help?

  26. Hi Steve,
    I am doing some kind of load testing. I am trying to establish 1000 concurrent connections to my broker from 5 Linux machines. 80 % connections are successful but 20 % fails with reason connection timed out. Using python to establish these connections. Any suggestions from you get 100 % result.

    1. Hi
      No I have got over 1000 connections to mosquitto on a raspberry Pi. I don’t know if you saw the video
      Simple Python MQTT Broker Connection Tester
      https://youtu.be/x_MP53SHbvU
      It also has a download link to the python code I used.
      If it is failing near 1000 the you may want to change the max connections setting. You should check it as it might be less than 1000 on the machine you are using
      Rgds
      Steve

      1. Hello Steve.
        How do you get the broker to accept more than one client connected?
        I have a broker, Mosquitto on RPi 3B and 2 clients on ESP-12F
        Each of them work, but only the last connected is listet on the broker.
        So it seems that the first one connected is kicked of, when nr. 2 is connecting.
        What can i do so all my clients is connected to the same broker?

  27. I have Home Assistant running on a Raspberry PI 4 and also mosquitto on the same PI. The system worked fine until I do sudo apt-get update and sudo apt-get upgrade. After that none of my Shelly1 switches or Sonoff all flashed with tasmota firmware appear in HA. I have tried to do the upgrade several times without success. Any help would be appreciated.

  28. hi steve l thanks for your great course

    I’m using ” eclipse-musquitto ” docker but I have some problem

    I created a python file :
    import paho.mqtt.client as mqtt
    from random import randrange, uniform
    import time

    mqttBroker = “mqtt”
    port = 1883
    topic = “test/”

    client = mqtt.Client(“test/”)
    client.connect(mqttBroker)

    while True:
    randNumber = uniform(20.0, 21.0)
    client.publish(topic, randNumber)
    print(“Just published ” + str(randNumber) + ” to Topic “, topic)
    time.sleep(1)

    and defined 2 cintainer :
    sudo docker create network my-net
    sudo docker run -d –rm -p 1883:1883 –network my-net –name mqtt-tok tok/mosquitto
    sudo docker run –name appc –network my-net app

    that app is my image consist of my python file& and after running “sudo docker run –name appc –network my-net app” my program is starting

    but I have one problem:
    Traceback (most recent call last):
    File “/usr/src/app/mqtt_publish.py”, line 10, in
    client.connect(mqttBroker)
    File “/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py”, line 941, in connect
    return self.reconnect()
    File “/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py”, line 1075, in reconnect
    sock = self._create_socket_connection()
    File “/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py”, line 3546, in _create_socket_connection
    return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
    File “/usr/local/lib/python3.9/socket.py”, line 843, in create_connection
    raise err
    File “/usr/local/lib/python3.9/socket.py”, line 831, in create_connection
    sock.connect(sa)
    ConnectionRefusedError: [Errno 111] Connection refused

    this ERRORS appears and I don’t know why
    could you help me, please?

    1. It looks like a port issue. I haven’t used docker for years but I think that all ports are closed and you need to open them
      rgds
      steve

  29. Hi,
    I am Running my Mosquitto broker on android through TERMUX .Previously (old version) is working fine with connection with Node mcu .But after updation i am not able to connect to the broker

    It showing like this

    1616485604: mosquitto version 2.0.7 starting
    1616485604: Using default config.
    1616485604: Starting in local only mode. Connections will only be possible from clients running on this machine.
    1616485604: Create a configuration file which defines a listener to allow remote access.
    1616485604: Opening ipv4 listen socket on port 1883.
    1616485604: Opening ipv6 listen socket on port 1883.
    1616485604: mosquitto version 2.0.7 running

    by adding two line
    listener 1883
    allow_anonymous true

    at the end of the config file but still it showing same thing
    Bad thing is every article give solution for mosquitto which is running on Linux(terminal) not for ANDROID (Termux) :joy:
    please guide me to achieve the goal

    thank you

    1. Sorry not familiar with Termux but from the output it looks like it is either ignoring your config file or it is in the wrong place.
      Rgds
      Steve

  30. On my Raspberry Pi (running Mosquitto on Buster) I regularly update using the sudo apt update/upgrade pair. This recent one in early March 2021 snuck in Mosquitto version 2.xx which of course totally disables ALL MQTT traffic causing maximum chaos.
    Your brilliant suggestion to allow anonymous users does work and temporarily patches the problem. However, the side effect is that passwords/usernames are no longer needed. Anyone on the network can view all MQTT traffic and insert whatever they want. Thus we went from “User/Pass security” to “Zero security”.
    Obviously a long term fix is to study and implement certificates, ACL, TLS, SSL and all the other rabbit hole solutions that can eat up weeks of studying.
    My question is this… for the average household IoT user running a Pi, VNC, and 50 or so IoT devices (running Tasmota, Espurna, esp-link, etc) what is the direction to go to get back to at least User/Pass type of security or some kind of certificate installation. Thanks in advance… love your work and easy to read examples and explanations.

    1. Hi
      You don’t need to allow anonymous users unless you want to have anonymous uses. v2 has allow_anonymous =False which means that if you were just using mosquitto without user/name passwords then it would break. However if you use it with passwords then it is ok.
      Does that make sense?

      1. Thanks Steve. If I set anonymous to false (which is the default in version 2.x) it will not let any of the IOT stations communicate with Mosquitto, even with user/pass as I had in version 1.x. I must therefore install certificates or investigate ACL etc. The documentation at Mosquitto at https://mosquitto.org/blog/2020/12/version-2-0-0-released/ is filled with jargon and no help or examples. There are references to “you have to configure a listener”, ACL, TLS, certificates, “running the broker as root” warnings, etc. A lot of rabbit holes to investigate – each consuming days of time, experiments, and second guessing. Some clues as to which rabbit hole to investigate would be useful. I’d go back to version 1.x but that means the end of updating the Pi as Mosquitto 2.x will be included on any update which will shut me down again – or put me back in anoymous mode with zero security. Ideas?

        1. Scott
          There are only two entries needed to make v2 start like previous versions they are:

          listener 1883
          allow_anonymous true

          Rgds
          Steve

  31. Hi Steve
    I am using mosquito version mosquitto-1.6.13-install-windows-x64 (https://mosquitto.org/files/binary/win64/mosquitto-1.6.13-install-windows-x64.exe. For this I am able to publish and subscribe messages in mosquito broker using self-signed Certificate.

    But when I am using higher version of (2 series) mosquito i.e. mosquitto-2.0.7-install-windows-x64 getting following errors while subscribing and publishing
    1) While Subscribing
    mosquitto>mosquitto_sub -h -t test -p 8883 –cafile “C:\Program Files\mosquitto\certs\ca.crt” –tls-version tlsv1.2
    Connection error: Connection Refused: not authorised.

    2) While Publishing
    mosquitto>mosquitto_pub -h -t test -m “message” -p 8883 –cafile “C:\Program Files\mosquitto\certs\ca.crt”
    Connection error: Connection Refused: not authorised.
    Error: The connection was refused.

    3) In Mosquitto broker
    mosquitto>mosquitto -c mosquitto.conf -v
    1612757601: The ‘port’ option is now deprecated and will be removed in a future version. Please use ‘listener’ instead.
    1612757601: mosquitto version 2.0.7 starting
    1612757601: Config loaded from mosquitto.conf.
    1612757601: Opening ipv6 listen socket on port 1883.
    1612757601: Opening ipv4 listen socket on port 1883.
    1612757601: mosquitto version 2.0.7 running
    1612757610: New connection from fe80::a808:ae55:d7a3:53dd:57512 on port 1883.
    1612757610: Sending CONNACK to fe80::a808:ae55:d7a3:53dd (0, 5)
    1612757610: Client disconnected, not authorised.
    1612757614: New connection from fe80::a808:ae55:d7a3:53dd:57515 on port 1883.
    1612757614: Sending CONNACK to fe80::a808:ae55:d7a3:53dd (0, 5)
    1612757614: Client disconnected, not authorised.

    4) a) If I am trying with 127.0.0.1
    mosquitto>mosquitto_sub -h 127.0.0.1 -t test -p 8883 –cafile “C:\Program Files\mosquitto\certs\ca.crt” –tls-version tlsv1.2
    Error: A TLS error occurred.
    b) In Broker
    New connection from 127.0.0.1:57527 on port 8883.
    1612757656: OpenSSL Error[0]: error:14094438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error
    1612757656: Client disconnected: Unknown error.

    I have used for all versions of 2.0 and higher same error I am receiving Connection error: Connection Refused: not authorised.

    We want to use latest 2.0.7 version can you please tell me why this version is not working.

    Thanks

      1. Thanks Steve, I want to ask one more thing I was trying to subscribe in my .net API I am getting error in mosquitto
        OpenSSL Error[0]: error:14094418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca

        1. Not sure of the question anonymous access was previously allowed by default and now it isn’t and so you have to explicitly allow it.

          1. Thanks Steve for the info.

            I am now getting this error locally SUB and PUB is working with thus certificate through one simulator it is giving this error

            New connection from ::1:52610 on port 8883.
            1613127049: OpenSSL Error[0]: error:14094412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate
            1613127049: Client closed its connection.

          2. Hi Steve,
            I am using one localhost(IIS Express) certificate that is working fine while subscribing, now I have created one child certificate Common Name mentioning as IP address of my machine.
            I am getting below error while subscribing through this certificate.

            New connection from 10.61.49.71:53431 on port 1884.
            OpenSSL Error[0]: error:14094412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate
            Client closed its connection.

            Thanks,
            Yogendra

  32. Hi Steve,

    My field machine remains offline most of the time but should subscribe to Mosquitto broker once online and able to receive all messages published so far from other field devices..
    Also once my machine is able to receive those messages, those messages need to be cleared from broker.
    Please help me with “How To” for the same.

    Regards
    Dipankar

    1. You need to publish messages with qos of 1 or 2. You machine should use a non clean session and subscribe with qos of 1 or 2. The messages will be deleted once the subscriber has received them.

      1. Thanks a lot Steve for your prompt help. I also need to store the message securely and encrypted. Is there any message store associated with Mosquitto that helps in persisting the messages securely till my field machine subscribes to the topic and received all of them.

        1. Yes they are stored in persistent store on the broker. Limit is usually around 100 messages but you will need to check
          rgds
          steve

          1. Hi Steve,
            Thanks for the tips on how broker can persist the messages received from the filed devices. However, would like to know how the payload can be encrypted during data persistence phase.

            To summarize, I can use MQTTS with valid certificate for TLS v1.2 communication between client and broker and thereby the message payload published by MQTT client will be encrypted during transit.

            However, once it is received by Mosquitto broker and till the time the messages are subscribed, Mosquitto broker need to store the payload encrypted.

            So, please help me with mechanism to encrypt, store, decrypt the payload

          2. Hi Steve,

            I need another help. For persisting the messages, is there any better and optimized alternative than storing in database. There may be huge overhead of storing telemetric data in database. Do we have any other type of message storing mechanism that is more efficient?

      2. what is the primary item by which the broker tracks the connection?
        If broker and client from different vendors,how password is encrypted in unique way

        1. The connection id of the client is used to track the connection. Passwords and usernames are not encrypted by mqtt

          1. Thanks for the reply.
            can we use same procedure for authentication if broker and client are from different vendors?
            should we provide username and password for every publish and subscribe?
            Is there any function for adding the users in password file other than manually adding through the mosquitto_passwd utility

            Thank you.

          2. The protocol is vendor neutral. Whether you use a username/passsword on each pub/sub depends on the application. There is no automatic way of generating the password file as far as I know.

  33. Hi, getting there.
    Thanks for the videos and texts, also the downloads that are pretty good.
    A few days in and I have a test MQTT pi set up, I upset my home one so I backed out and set the new one up so I could keep the lights on!

    Slow progress but “FUN”.

    A Question, of course.
    I am using a hyperlink in a web page that opens a new page, so far so good. When the new page opens can I get it to publish an MQTT (over websockets) as part of the new pages code?
    Then I can make other stuff happen at the same time as the web page opens.

    Looking for an; “It’s possible answer” and then I will carry on trying to make that happen. If not pos’ I need to decide how to progress my project.
    Of course any pointers would be appreciated.
    Thanks

    1. If I understand it correctly you want it to run a script when the page opens. If so the anser is yes by using the onload in the body tag as shown in the code below

      This is taken from a working script and calls the connect but you can call any function you want.
      Rgds
      Steve

      1. Sorry this has been a long time in acknowledging your reply but with your help, I have done this.
        Many thanks.

  34. Hi,
    I am running Mosquitto on a virtual machine and it is working fine. There are around five devices sending constantly via the broker without problems. Yet, I have a problem with one single device. Somehow it doesn’t connect to Mosquitto although the IP and port settings are like the other devices. I tried it with a public server and it is sending there. Do you know what the problem could be there?
    Best,
    Mike

    1. Hi
      Do you have restrictions on the broker i.e username/password/ ACl connection limits etc.
      Can you ping the broker from the client machine?
      Rgds
      Steve

      1. Hi,
        I just left the Mosquitto settings as they were when I installed it. So I guess there are no restrictions on that, or are there ACI connection limits by default? The username and password are also not used by the other devices.
        Is it possible that somehow Mosquitto blocks certain devices for some reason?
        The device itself has a limited user interface, so it’s not possible to ping the broker.
        Best,
        Max

        1. On a default broker install there are no restrictions. Do you have access to the broker console so that you can see the connection attempt. Are you using MQTT on the client or mqtt over websockets.If you are using websockets then mosquitto will need to be configured.
          Rgds
          Steve

        2. Hi Mike, did you ever get to the bottom of this solution? I have the same problem and would be interested in how you solved it. Thanks!

  35. Hi,

    Have a broker running on 127.0.0.1, now trying to publish via a nodemcu to local broker. It does not connect to local broker. If i use test.mosquitto.org i am able to punlish and subscribe. What would my local broker be called or the address ???
    New and confused

    1. Ho 127.0.0.1 is the machine you are sitting at. To find the IP address of the machine go to the machine and open a command prompt and type
      ipconfig (windows)
      ifconfig (linux)

      If you know the name of the machine you could always try and use the name.
      Rgds
      Steve

      1. Thanks again for your swift reply.

        When i first installed mosquitto i was able to use the ip of the machine to succesfully publish and subscribe. The second time it did not work with the machine ip until i found that mosquitto broker was running at 127.0.0.1. Then i was able to publish and subscribe succesfully.
        im now trying to get a nodemcu to act as a client but it will not recognise 127.0.0.1 and is unable to connect to mqtt server. I then decided to connect it test.mosquitto.org and all is well. I wish to use my local broker so if internet connection is lost my network and broker will all still work.

        Any furthur help would be great.

        1. Hi
          127.0.0.1 is the default IP for you local machine but it has a proper IP address like 192.168.1.21. That is the IP address you need However you can configure the broker to only respond to requests to a certain IP address but by default you don’t. check the config file and make sure that the address 127.0.0.1 isn’t mentioned it it is remove it.

  36. How many esp32 clients can be connected simultaneously to a raspberry pi 3 acting as a local mqtt server(running mosquitto)

  37. Hi Steve
    I am learning Linux and mqtt,i have tried mosquitto publish and subscribe on my localhost and it’s worked.
    But ,when i rent a IDC linux(centos 8) machine and install mosquitto,
    then,i publish a topic to this linux ip 192.168.168.100 ,it’s always show TimeoutError: [WinError 10060]
    i still can’t find any solution,could you help me?
    1.i try to publish a topic from my localhost to mosquitto test server : test.mosquitto.org and subscribe
    from linux ,it’s worked….so,i don’t know what’s wrong…
    2.use python paho to publish from my localhost to test.mosquitto.org and subscribe from linux is worked.

  38. Hi
    It seems like Mosquitto will not read the Mosquitto database used for persisting when starting up. I have configured the following for Mosquitto:

    persistence true
    persistence_file mosquitto.db
    persistence_location /tmp/

    I publish a few topics with QoS 2 and retained. When terminating Mosquitto the output is as expected:

    1598259315: mosquitto version 1.6.11 terminating
    1598259315: Saving in-memory database to /tmp/mosquitto.db.

    If i cat /tmp/mosquitto.db, I can see it contains my retained messages.

    When starting Mosquitto again, I expected to see that it read the database and that the retained messages I had published before terminating Mosquitto, would still be available (without having to re-publish them):

    mosquitto -c /mosquitto/config/mosquitto.conf
    1598259446: mosquitto version 1.6.11 starting
    1598259446: Config loaded from /mosquitto/config/mosquitto.conf.
    1598259446: Opening ipv4 listen socket on port 1883.
    1598259446: Opening ipv4 listen socket on port 8883.
    1598259446: Opening ipv6 listen socket on port 8883.
    1598259446: mosquitto version 1.6.11 running

    But as shown above, there is no indication that the database have been read (should it say something about that?) and my retained messages are gone.

    Do I need something else in my configuration, or have I misunderstood the persistence feature?

    Thanks
    Tue

    1. Hi
      I just tested it and it works. You might be reading the wrong .db file change the path in the conf file to a full file path.
      Rgds
      Steve

      1. Hi Steve
        Thanks a lot for your quick reply. I have tried several combinations of setting the filename and the path, also some that should not be valid according to the documentation, but nothing works. Should Mosquitto write something to stdout/stderr when starting that it is reading the database (like it does when writing the database)? Which persistence settings did you use?
        Can it be my publish that needs something before it is persisted. I have tried with the following publish:

        mosquitto_pub -h 127.0.0.1 -p 1883 -u xxx -P xxx -t test123 -m “test message” -q 2 -r

        Best regards

        Tue

        1. No it doesn’t tell you it is reading the database you do get an error that it is can’t write. Have you checked the timestamp on the file to check it is being updated?
          Also try without username/password as I didn’t check it with security.
          Other than that the settings are the same as you config file.
          I also just noticed that you are using a slightly newer version than I am. Are you on windows or Linux?
          Also I’m not sure that I use the persistence location I can’t check it at the moment try commenting that out
          Rgds
          Steve

          1. Hi
            Just checked my file and I used
            persistence true
            persistence_location /home/pi/mos
            rgds
            steve

          2. Hi Steve
            I have found the issue now. The problem is that mosquitto.db is written by the mosquitto user, but it seems like it reads it before it drops priveledges to the mosquitto user at startup. For this reason, the file can not be read unless I change the permissions before restarting mosquitto.
            -rw——- 1 mosquitt mosquitt 3095 Aug 26 06:57 /home/mos/mosquitto.db
            Thanks for your support!
            Tue

  39. Steve,
    I have been working with a setup using Node-red on a Pi3 with mosquitto as the broker. The client is a ESP32. This is a weather station I am trying to setup and used the N-R-Dashboard for the output. This all works fine and I have a nice display of the information that I can access on my Iphone(Safari), Pi3/4 (Chromium), IPad(Safari)(Chrome). All of these work well initially but after a day or so it starts giving me “lost connection” messages and is very intermittent then eventually it just stops providing any info. I am watching the Mosquitto log and I see message being received and sent, but nothing on the dashboard. Not sure were I should go from here. Been looking through your website but haven’t found the key to this problem.
    Thanks,
    Ken

    1. I’m assuming you are keeping the dashboard open all of the time. If you are then I would suspect a websockets timeout issue. If you close the browser and reconnect is it ok.
      Rgds
      Steve

      1. Steve,
        I just ran the experiment. Closed the Chromium browser on my Pi4. Re-Opened and then entered the address of the dashboard host etc. Continued to get a “Connection Lost” notification in the top bar of the Dashboard. The only time I get reliable Dashboard info is after reboot the Pi3 NR computer. Then it will report timely complete info for about a day and this on any of my other computers.
        thanks,
        Ken

        1. Hi
          Did you check that basic networking was working on the pi by doing a ping.If you start node-red manually from the command prompt you may also see something on the console that may help.
          Rgds
          Steve

          1. When I run a 10 ping sequence I get about 170 ms avg. response. but the dashboard never completely loads all the content but I can see all the message go thru mosquitto.

          2. Not sure of your question, “What dashboard are you using”. Dashboard from Node-red v1.1.2.
            This Node-red is running on a Pi3 and I view thru various browsers on Ipad, iphone, a pi4 using chromium etc.
            Thanks,
            Ken

          3. Hi
            Can you send me the flow you can post it in the comments or if it is one you downloaded from me tell me which one
            rgds
            Steve

  40. Hi
    I run Mosquitto on Pi with a connection from ESP32.
    I read data with ESP32 from Xiaomi temperature. Everything is fine, but after a while I lose contact with MQTT and I can’t publish anything. I checked and it doesn’t go into the “if (client.connected())” anymore, just in ” else { ”

    void publish(const char* addr, char* valueName, char* value) {
    char topic[50];
    sprintf(topic, “%s/%s/%s”, MQTT_PREFIX, addr, valueName);
    if (client.connected()) {
    Serial.print(“connected —— “);
    // client.publish(topic, value);
    client.loop();
    // Serial.print(“dupa loop – “);
    }
    else {
    Serial.println(“don’t connected—– “);
    // reconnect();
    // Serial.println(“Dupa reconectare – “);
    }

    Best regards
    Mihai

  41. Hi Steve, and thanks for your contributions to our understanding of MQTT!

    I’m trying to use mosquitto as a message-passing server. I want one part of the topic space (a/b/c/#) to be fully public (anybody can read/write.) And I want access to #SYS/ to be limited to the host the mosquitto server is running on. I’ll run a website there that subscribes to $SYS/broker to display current stats.

    I can’t figure out how to do this, either with a listener on a different port or with a user/password combo. In some cases mosquitto’s reporting errors on config file lines that don’t exist so I’m not sure what’s going on.)

    I’d expect this to be a common configuration but googling isn’t turning up anything helpful. Any suggestions? Or is there a better way to accomplish what I want?

    Thanks!

  42. Hi Steve,

    Thanks for your sharing the information.I have a question when using mosquitto and need your help.

    I have mosquitto broker running on the Ubuntu, use 6 embedded devices as the client for publishing information, and another client running on the Ubuntu subscribes to the information.However, some embedded devices will be disconnected after running for 1 week or 2 weeks, and the log infomation,
    1589849321: New connection from 192.168.1.114 on port 1883.
    1589849322: Socket error on client , disconnecting.

    The mosquitto.conf is as follows,
    message_size_limit 0
    port 1883
    max_connections -1
    require_certificate false
    persistence false

    I read a few posts you wrote and found that I did not use a CA certificate. Is this the problem? Can I use mosquitto normally without using this method?

    Regards,

    Andrew

    1. Can you just clarify what is happening.
      An embedded client disconnects and when it tries to reconnect it is rejected? is this what is happening.

      Is the client using a clean session? how long does the client remain disconnected?

      1. Hi Steven,
        Thanks for your response.
        After an embedded client works for a few days, there is a sudden disconnection and the broker cannot be connected again.It seems that mosquitto broker did not send CONNACK.
        The embedded client uses a clean session. Normally, after disconnecting, the client cannot connect to the server again. In this case, the device can only be powered off and restarted.

        Regards,

        Andrew

          1. Hi Steve,
            I am using paho.mqtt.embedded-c packet.I designed a state machine to handle connection, ping request and subscription information. And used a task of FreeRTOS to run this state machine.

            Thanks and regards,
            Andrew

  43. Hi Steve,

    Thanks for the quick guide.

    I have Mosquito broker and client installed on my raspberry pi, which I intend to create home automation solution.

    How many device maximum is best to be connected to the broker for efficiency, that is without having it to crash?

    Regards

    1. I have tested it to 1000 connections as on Linux users are limited to approx 1000 open ports.
      rgds
      Steve

  44. Hello Steve,

    In my system target, I want to use the mosquitto – client. Is this possible? Currently, I am not planning to use the mosquito broker. I downloaded the mosquito library with the broker and client and I can see a client in it.

    Thanks and regards – Dilip Jayavant

  45. I got the broker running on Ubuntu 18.04. Can use Pub and Sub and see messages. However, can’t make an MQTT connection on Windows machine on same local LAN subnet using MQTT Lens or MQTT Box. No WS or TLS so far.. Just basic connections. On that same Win machine connect using PuTTY to tcp port 1883. Any thoughts?

      1. Yes, I can connect to mqtt.eclipse.org using MQTT Box or Lens on a Windows machine. That is how I have been doing my testing.

        I’m able to connect to my internal broker ONLY through the Pub and Sub on the SAME linux box as the broker. I can, however, make a TCP connection to the broker linux box, port 1883 from the Windows machine. So I don’t believe it is a network routing issue.

        Thanks for your help.
        Tom

        1. In that case I would check the configuration of the broker. Is it configured for websockets and TLS
          rgds
          Steve

    1. Hi Steve,
      I am using Mosquitto running on Windows 7 machine. I can pub and sub using two different cmds on the same machine.
      I am trying to connect MKR1000 with this Mosquitto broker using its IP address but my pubsubClient.connect() fails with error state -2.

      Following your Post, I have configured mosqquitto with mosquitto-2.conf with:
      listener 1883
      allow_anonymous true
      max_packet_size 1280

      Any hint?

      Ehsan

  46. Hi Steve,
    I have requirement with mosqitto where one set of client would like to connect to mosquito with using TLS (certificate) but use passwords using port (1883)

    The other set of clients would like to connect with TLS and certificates. but using a different port (8883)

    Is this configuration possible ?

    If this is not possible can I run two copies of Mosquitto (with two different configuration file) listening on two ports ? as a service ?

  47. Hi Steve,
    Thanks to your guide, I was able to successfully log messages coming to the broker into a text file and then using python script load the data/messages from the text file into the database.
    But I want to make this process real time, so is there a session id or something based on which I can create separate text files for the messages from broker? using which i can schedule my python script as well to run once the session expires? Or is there a better way to have the messages coming to broker be updated into the database as soon as it reaches the broker?

      1. Hi Steve,
        Thanks for the guidance, but I am not storing the messages directly, i am trying to parse the single message hex data recevied into mutilple decimal values. Since the incoming rate of messages is high, some of the data gets lost during parsing. So is there a way I can parse the data realtime and publish on webpages and store in db as well?

        1. Rose
          Did you try the script as the logging takes place in a separate thread. Do you have any idea of the messages/sec and I can try it.
          Rgds
          Steve

          1. Yes I am doing the parsing in a separate thread, and calling the data from the queue. Still the data seems to be lost.

            Around 6 messages 128 bytes long are being received in a second, each message is hex data and i’m parsing it into 7 decimal values and storing these 7 decimal values in db and sending over websocket.
            Will using node.js be a better option instead of python?

  48. Hi Steve,
    So I’ve been doing the python tutorials with an external broker, and am currently trying to connect to a local mosquitto broker instance but am having a bit of trouble understanding the connect() command arguments. Any ideas?

    thanks

  49. Hi Steve,
    We have subscribed to a basic package of freeboard and we are facing difficulties in linking our test mosquitto MQTT server to freeboard.
    We have successfully completed the data transfet between the TEST MOSQUITTO SERVER and OUR PLC.
    The below are the configuration settings in our PLC ( Programmable Logic Controller )

    1. TYPE : MQTT
    2. NAME : ( Any name )
    3. TOPIC : qwerty ( Advice )
    4. SERVER : 37.187.106.16 ( Advice )
    5. PORT : 1883
    6. USE ENCRYPTION : NO
    7. CLIENT ID : mqttdemo ( Advice )
    8. API KEY / USERNAME : steve
    9. PASSWORD : john
    10. JSON MASSAGES : no

    With these settings we tried these out, But the connection could not be accomplished. Please advice.

    Regards,

    Satheesh Kumaran

    1. Can you point me to the instructions you are following.You might also want to use the ask steve page as I don’t have a freeboard account and you might need to let me access using yours.
      rgds
      steve

Leave a Reply

Your email address will not be published. Required fields are marked *