Go to "mqtt" to build an MQTT server under Windows

Source: Internet
Author: User

About MQTT

MQ Telemetry Transport (MQTT) is a lightweight agent-based publish/Subscribe messaging protocol, designed to be open, simple, lightweight, and easy to implement. These features make it suitable for restricted environments. The features of the agreement are:

  • Use the Publish/Subscribe message pattern to provide a one-to-many message release, decoupling the application.
  • A message transmission that is masked against the payload content.
  • Provides network connectivity using TCP/IP.
  • Small transfers, with small overhead (fixed-length headers of 2 bytes), minimize protocol switching to reduce network traffic.
  • Use the last would and Testament features to notify the client of the mechanism of an abnormal interrupt on the parties.
  • There are three types of message publishing quality of service:
    • "At most once", message publishing relies entirely on the underlying TCP/IP network. Message loss or repetition occurs. This level can be used when the environment sensor data, loss of a read record does not matter, because there will be a second time to send.
    • "At least once" to ensure that the message arrives, but the message duplication may occur.
    • "Only once" to make sure the message arrives once. This level can be used for situations where, in a billing system, duplicate or missing messages can result in incorrect results.

Mosquitto is a "an open source Mqtt v3.1/v3.1.1 broker"--Open source Mqtt proxy Server, which also has an installation package for Windows.

But I am using the WIN10 64-bit system, both of which are downloaded after the installation is not an error is missing DLL files, can not be used.

Finally refer to the previous blog said, built the Apollo server, where the use of the Apollo 1.7.1.

    • Official website: http://activemq.apache.org/index.html
    • : http://activemq.apache.org/apollo/download.html
    • Quick Start Tutorial: http://activemq.apache.org/apollo/documentation/getting-started.html
Building an MQTT server

To use Apollo to build an MQTT server step:

    1. Download the Apollo server and unzip it, run it in the CMD environment under its working directory ...\bin\apollo.cmd , and follow the command with the parameter " create mybroker " to create the server instance. This requires a Java environment where the system environment variable is java_home.
    2. After the instance is created, the Mybroker folder is generated under the Bin directory, where the file is configured with the server information, the file ...\etc\apollo.xml ...\etc\users.properties contains the user name and password used to connect to the MQTT server, the initial default account is admin, password password;
    3. Enter the ...\mybroker\bin\ directory, in the cmd input command " apollo-broker.cmd run ", you can use the TAB key Auto-completion, after the output information is as follows:

Among the things we should pay attention to:

MQTT Server TCP connection port: tcp://0.0.0.0:61613

Background Web Administration page: https://127.0.0.1:61681/or http://127.0.0.1:61680/

After logging in to the server, if the MQTT server has a client connection, the background will display the following

MQTT Client for Python

There is an MQTT client package--paho-mqtt in the Python environment.

Installation commands
Pip Install Paho-mqtt

  

Client code Listings

The following is an MQTT client code listing

Import paho.mqtt.client as Mqttdef on_connect (client, UserData, flags, RC):    print ("Connected with result code" +STR (r c)    client.subscribe ("lettuce") def on_message (client, UserData, msg):    print (msg.topic+ "" +str (Msg.payload) ) client = Mqtt. Client () client.username_pw_set ("admin", "password") # must be set, otherwise it will return "connected with result code 4"client.on_connect = On_ Connectclient.on_message = On_messagehost = "127.0.0.1" Client.connect (HOST, 61613, Max) Client.loop_forever ()

  

Here is the M

Publish Message Code

Code for QTT Server publishing messages

Import paho.mqtt.publish as Publishhost = "127.0.0.1" publish.single ("lettuce", "payload", Hostname=host, port=61613,               auth={' username ': "admin", ' Password ': "Password"})

  

.

Update

July 28, 2017 update:

A relatively good open source MQTT server has been discovered recently: EMQ. Linux under Deployment Tutorial can refer to this article: EMQ Experience--Deploying an MQTT server on CentOS7

Under Windows Deployment, you can check the relevant information on the website.

August 15, 2017 update:

Note: The background Web Admin page is set to be only locally accessible, and if you want to access the Admin page with another host, you need to modify "http://127.0.0.1:61680/" to "http://0.0.0.0:61680/".

Related profiles: Apache-apollo-1.7.1\bin\mybroker\etc\apollo.xml, approximately 61 lines:

bind="http://127.0.0.1:61680"/><web_admin bind="https://127.0.0.1:61681"/>

Go to "mqtt" to build an MQTT server under Windows

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.