2021-10-02 21:24:51 +01:00
2021-10-02 18:46:53 +01:00
2021-10-02 18:58:41 +01:00
2021-10-02 19:58:27 +01:00
2021-10-02 21:24:51 +01:00

Contributors Forks Stargazers Issues Apache License

mqtt2ws - Transparently proxy MQTT to MQTT-over-Websocket

This is a simple MQTT to MQTT-over-Websocket proxy written in go.

Mqtt2ws will listten on a configurable TCP port for MQTT messages. When a client connects a Websocket connection is established to a configurable remote server. The MQTT messages from the TCP socket are then bridged to the Websocket connection in both directions.

Why this is needed

MQTT is a light-weight publish/subscribe protocol frequently used for communication with IoT devices. It can be transported over TCP, over TLS or over WebSocket. The MQTT payload is identical regardless of the the protocol used to transport it.

TCP is a stream based protocol, meaning that as far the MQTT protocol using it is concerned, it is a continuous stream of bytes. Websocket however is a message based a message/frame based protocol.

Translating from MQTT-over-Websocket to MQTT-over-TCP is easy. It suffices to merely send the payload of the WebSocket frames as a continuous stream of bytes. Translating from MQTT-over-TCP to MQTT-over-Websocket is more complicated. It requires to understand the boundaries of the MQTT messages, so they can be aligned with WebSocket frames.

Mqtt2ws used the Eclipse paho MQTT libeary to read MQTT messages from the TCP stream, to then retransmit each in a Websocket frame.

Getting Started

To get a local copy up and running follow these simple steps.

Installation

Using go get

  1. Install go
  2. Go get module
    go get github.com/jochenvg/mqtt2ws
    

Download release

Alternatively, you can download a binary for your operation system on the releases page.

Usage

Operation is controller by two flags:

Usage of ./mqtt2ws:
  -listen string
    	listen tcp socket (default ":1883")
  -url string
    	websocket url (default "ws://broker.hivemq.com:8000/mqtt")

License

Distributed under the Apache 2.0 License. See LICENSE for more information.

Description
Bridge MQTT over TCP to MQTT over WebSocket
Readme 74 KiB
Languages
Go 78.1%
Dockerfile 21.9%