Eclipse Mosquitos is an open source (EPL/EDL licensed) messaging broker that implements VERSIONS 5.0, 3.1.1, and 3.1 of the MQTT protocol. Mosquito-server Mosquito-server is lightweight and suitable for all kinds of equipment, from low-power single-board computers to full servers.

directory

Mosquito-server Introduction

Install mosquitos server

Testing the Mosquitos server

Subscribe & publish messages

News subscription

News release

Multiple subscriber message reception

Set the user name and password


Hello, I’m Grey Ape! A programmer trying to earn money to buy hair tonic.

In the cloud intelligent development of the Internet of Things, MQTT protocol is one of the most commonly used protocols. The basic concept of MQTT protocol was briefly introduced in an article before. Interested partners can follow this article “Talking about the hottest protocol in the Development of the Internet of Things -MQTT protocol”.

We know that MQTT protocol is a server-based subscription/publish communication protocol, so the implementation of this protocol must be established on the server. So in this article, We’re going to share with you a mosquito-focused tutorial on building/testing a mosquito-focused server in a Windows environment.

 

Mosquito-server Introduction

The mosquito-server official blurb goes like this:

The official introduction

Eclipse Mosquitos is an open source (EPL/EDL licensed) messaging broker that implements VERSIONS 5.0, 3.1.1, and 3.1 of the MQTT protocol. Mosquitos are lightweight and fit to fit all kinds of equipment, from low-power single-board computers to full servers. The MQTT protocol provides a lightweight way to perform messaging using the publish/subscribe model. This makes it suitable for iot messaging, such as low-power sensors or mobile devices such as phones, embedded computers or microcontrollers. Mosquitto_pub The Mosquitto_SUB project also provides mosquitto_C library to implement the MOSQUITTOTT client, as well as mosquitto_SUB command line MQTT clients.

The mosquito-server specification gives us a basic idea of what the mosquito-server is supposed to do.

 

Install mosquitos server

The next step is to download and install the server.

Official Download address

Download the EXE version in Windows.

Then go to the file we downloaded and click “Install”. Then we can see many files like this in the corresponding installation folder:

The role of these main documents is described below:

The module function
mosquitto.conf Mosquito-server configuration file
mosquitto Used to start the broker
mosquitto_passwd Set the user account and password
mosquitto_pub Used to post messages
mosquitto_sub To subscribe to messages
pwfile.example Mosquitto_passwd the mosquitto_passwd file to store the user’s account and password

 

Testing the Mosquitos server

After downloading and installing the Mosquito-server, of course, we should test the mosquito-server to see if it’s installed successfully,

To test this, open the mosquito-server CMD command line, find the mosquito-server file path where we installed the mosquito-server, and type the following command line:

mosquitto -c mosquitto.conf
Copy the code

If there is no output, the mosquitmosquitserver has started successfully!

The effect is as follows:

 

Subscribe & publish messages

Once we’ve made sure that our mosquitmosquitserver has been installed and started without problems, we can try to use the mosquitmosquitserver to subscribe to and publish messages under the MQTT protocol. In MQTT, subscription and publishing are done on the client side, so we call them subscribers and publishers.

News subscription

To subscribe, the subscriber should reopen the mosquito-server command line, also find the mosquito-server folder, and type the mosquito-server in the following command line format:

mosquitto_sub -v -t {topic}
Copy the code

The “topic” is the message topic, which can be named according to the actual application. It is introduced in the concept of MQTT protocol.

As follows:

News release

Publishers publish news of method is: open a CMD command line again, find MosQuitto server in the same folder, carried out in accordance with the following command line format input:

mosquitto_pub -t {topic} -m {Hello}
Copy the code

The “topic” is the topic of the published message, and the content in the second curly bracket is the message to be published. Note that when using CMD command line to publish messages, there should be no Spaces in the middle of the message, otherwise the message will fail.

As follows:

Then, as shown in the figure above, we can receive messages from the corresponding topic in the subscriber interface.

Multiple subscriber message reception

We know that the MQTT protocol can have multiple message subscribers, so we can continue to subscribe to the topic topic messages of the publisher in the new CMD command line, and then we can publish through the publisher and receive the messages from the publisher in another subscriber!

As follows:

 

Set the user name and password

The official instructions for setting a server username and password are as follows,

mosquitto.conf man page

Mosquitto_passwd is the mosquitto_passwd tool to manage the password file for mosquitMQTT agent. The user name cannot contain “:”. Passwords are stored in a similar format to crypt(3).

We can use the mosquito-server command-line to type in the mosquito-server folder using the following command line format:

mosquitto_passwd [ -c | -D ] passwordfile username 
Copy the code

You can check out the official documentation for specific uses.

For example:

Because the password is encrypted, we can’t see it. Then we can find the file where we save the user name and password under the corresponding file. After opening it, we can see the user name and encrypted password as shown below.

Then change the mosquito.conf password_file pwfile.example to the passwordfile we just created to make it effective.

Mosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquitmosquit

 

Feel good remember to like attention yo!

Big bad Wolf accompany you to progress together!