erl.mqtt

所属分类:通讯编程
开发工具:Erlang
文件大小:0KB
下载次数:0
上传日期:2023-09-09 04:02:31
上 传 者sh-1993
说明:  MQTT服务器设计用于机器对机器(M2M)和物联网(IoT)上下文中的通信,并实现MQTT协议...,
(MQTT server is designed for communication in Machine to Machine (M2M) and Internet of Things (IoT) contexts and implements MQTT protocol versions 3.1, 3.1.1 and 5.0. The server is written in Erlang as OTP application.)

文件列表:
.project (477, 2023-09-08)
.settings/ (0, 2023-09-08)
.settings/org.erlide.core.prefs (325, 2023-09-08)
.settings/org.erlide.model.prefs (91, 2023-09-08)
CODE_OF_CONDUCT.md (5202, 2023-09-08)
HISTORY.md (262, 2023-09-08)
LICENSE (11357, 2023-09-08)
apps/ (0, 2023-09-08)
apps/mqtt_rest/ (0, 2023-09-08)
apps/mqtt_rest/include/ (0, 2023-09-08)
apps/mqtt_rest/include/test_rest.hrl (1821, 2023-09-08)
apps/mqtt_rest/priv/ (0, 2023-09-08)
apps/mqtt_rest/priv/dist/ (0, 2023-09-08)
apps/mqtt_rest/priv/dist/favicon-16x16.png (665, 2023-09-08)
apps/mqtt_rest/priv/dist/favicon-32x32.png (628, 2023-09-08)
apps/mqtt_rest/priv/dist/index.html (1438, 2023-09-08)
apps/mqtt_rest/priv/dist/oauth2-redirect.html (2595, 2023-09-08)
apps/mqtt_rest/priv/dist/swagger-ui-bundle.js (1091138, 2023-09-08)
apps/mqtt_rest/priv/dist/swagger-ui-bundle.js.map (4765824, 2023-09-08)
apps/mqtt_rest/priv/dist/swagger-ui-es-bundle-core.js (511680, 2023-09-08)
apps/mqtt_rest/priv/dist/swagger-ui-es-bundle-core.js.map (1907969, 2023-09-08)
apps/mqtt_rest/priv/dist/swagger-ui-es-bundle.js (1090921, 2023-09-08)
apps/mqtt_rest/priv/dist/swagger-ui-es-bundle.js.map (4765105, 2023-09-08)
apps/mqtt_rest/priv/dist/swagger-ui-standalone-preset.js (337217, 2023-09-08)
apps/mqtt_rest/priv/dist/swagger-ui-standalone-preset.js.map (1536543, 2023-09-08)
apps/mqtt_rest/priv/dist/swagger-ui.css (143753, 2023-09-08)
apps/mqtt_rest/priv/dist/swagger-ui.css.map (275172, 2023-09-08)
apps/mqtt_rest/priv/dist/swagger-ui.js (511869, 2023-09-08)
apps/mqtt_rest/priv/dist/swagger-ui.js.map (1907034, 2023-09-08)
apps/mqtt_rest/priv/openapi.json (9105, 2023-09-08)
apps/mqtt_rest/rebar.config (407, 2023-09-08)
apps/mqtt_rest/src/ (0, 2023-09-08)
apps/mqtt_rest/src/mqtt_rest.app.src (1062, 2023-09-08)
apps/mqtt_rest/src/mqtt_rest.erl (1034, 2023-09-08)
apps/mqtt_rest/src/mqtt_rest_api.erl (11895, 2023-09-08)
... ...

# MQTT server for Erlang. ## Introduction The server implements MQTT messaging protocol version 3.1, 3.1.1, 5.0 and allows communicate with MQTT clients to send/receive messages. The server is written in Erlang. The server was tested with following clients: 1. Mosquitto command line tools [subscriber](https://mosquitto.org/man/mosquitto_sub-1.html) and [publisher](https://mosquitto.org/man/mosquitto_pub-1.html) 2. Javascript web-socket MQTT client [HiveMQ](http://www.hivemq.com/demos/websocket-client/) 3. [Erlang MQTT client](https://github.com/alekras/mqtt_client/) ## Messenger implementation based on the MQTT server. Simple Instant messenger [SIM](https://github.com/alekras/erl.web.sim) was created to test functionality of the MQTT server and prove good performance of the code. Live demo of SIM is running [here](https://lucky3p.com/sim). ## Architecture The server consist of two OTP applications: core MQTT server and restful HTTP server for managing users DB. The both apps are combined in one release and are working closely. ### Core MQTT server Core MQTT server is an OTP application that implements MQTT protocol versions 3.1, 3.1.1 and 5.0. It depends on other Erlang applications: 1. ```lager``` for logging service, 2. ```cowboy``` for tcp, tls and web-socket (ws and wss) connections, 3. ```msql_client``` for connection to MySQL server [see](https://github.com/alekras/mysql_client), 4. ```mqtt_common``` that is library keeping [code](https://github.com/alekras/erl.mqtt.common) that is common for MQTT client and server implementation. ### Resful Http server Http server implements Restful API described in OpenAPI configuration file [mqtt_rest_v3.yaml](https://github.com/alekras/erl.mqtt.server/blob/master/mqtt_rest_v3.yaml). There is [swagger](https://lucky3p.com/rest/v3/swagger-ui) page of running instance of MQTT Rest Http server. ### Backend database implementation Session state data is storing in database (DETS or MySQL in current version). Developing of Mnesia support is in progress. ### Connection types Server can establish connection using different network protocols: 1. clear it/tcp 2. tls/ssl 3. web socket 4. secure web socket ## Getting started ### Installation To start with the server you have to complete two steps below: 1. Install [Erlang](http://www.erlang.org/download.html). 2. Install [Rebar3](https://www.rebar3.org/). ### Building #### Download or clone from SourceForge GIT repository or from GitHub Download source code to local host. Type command ```bash $ git clone https://git.code.sf.net/p/mqtt-server/code erl.mqtt.server ``` or ```bash $ git clone https://github.com/alekras/erl.mqtt.server.git erl.mqtt.server ``` #### Compiling After you have got source code of the server then change directory to the erl.mqtt.server: ```bash $ cd erl.mqtt.server ``` Run rebar3 for this project. You have to add path to rebar3 to OS PATH variable or just use the whole path: ```bash $ /opt/local/bin/rebar3 compile ``` Rebar will fetch code of all dependencies and compile source files of main project and all dependencies. #### Starting To start server run bash script: ```bash $ ./start_mqtt_server.sh ``` Erlang shell will open and log statements are appearing in console. #### Using relx To make release of the application for development run command: ```bash $ /opt/local/bin/rebar3 release -n mqtt_server_dev ``` for production: ```bash $ /opt/local/bin/rebar3 release -n mqtt_server ``` Go to folder: ```bash $ cd _build/prod/rel/mqtt_server_dev ``` and run command to start server: ```bash $ bin/mqtt_server_dev console ``` Example of script to make release and start server is [here](https://github.com/alekras/erl.mqtt.server/blob/master/make_release_start_node.sh) ## Testing You can test the server with any MQTT client complained with protocol version 3.1.1 or 5.0. I recommend to try Erlang MQTT [client](https://sourceforge.net/projects/mqtt-client/) or [client](https://github.com/alekras/mqtt_client.git). ### Testing with Mosquitto tools To test with Mosquitto tools you need to open two terminal windows. One for subscribing and other for publishing. Open the first terminal windows and change directory to folder where Mosquitto is installed: ```bash $ cd /usr/local/Cellar/mosquitto/1.4.10/ ``` Now subscribe to "test/c" topic: ```bash $ bin/mosquitto_sub -t test/c -p 18883 -i test -u guest -P guest -V mqttv5 ``` Open the second terminal windows and change directory to Mosquitto installation: ```bash $ cd /usr/local/Cellar/mosquitto/1.4.10/ ``` Publish some message to "test/c" topic: ```bash $ bin/mosquitto_pub -t test/c -p 18883 -i test1 -u guest -P guest -m "Test message from mosquitto tools QoS=2" -q 2 -V mqttv5 ``` In first terminal you will see incoming message: ```bash $ Test message from mosquitto tools QoS=2 ``` ### Testing with other MQTT clients The server was tested with other clients: 1. Websocket MQTT client from HiveMQ [http://www.hivemq.com/demos/websocket-client/]. 2. MQTT Erlang client [https://github.com/alekras/mqtt_client.git]. ## Configuration To set up ports for TCP and TLS socket connection go to config[-dev]/sys.config. This is OTP application configuration file contained startup data for lager, ranch and mqtt server backend type and connection details. ### Add/Remove users Rest HTTP server allows to manage users table on backend DB. If you start server on local environment you can reach swagger page as http://localhost:8080/rest/v3/swagger-ui. ## References 1. [https://mosquitto.org/] - Mosquitto MQTT server. 2. [https://www.rabbitmq.com/] - RabbitMQ server with MQTT plugin. 3. [https://sourceforge.net/projects/mqtt-client/] - Erlang MQTT client. 4. [http://www.hivemq.com/demos/websocket-client/] - MQTT websocket client.

近期下载者

相关文件


收藏者