mqtt-to-ws

command module
v0.0.0-...-f03831e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2022 License: MPL-2.0 Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

MQTT to Websocket Bridge with MongoDB

Structure

├── controller          # gin router controller
│   └── controller.go
├── docs                # swagger documention generated by `swag init`
│   ├── docs.go
│   ├── swagger.json
│   └── swagger.yaml
├── logger              # zap logger
│   └── logger.go
├── main.go
├── makefile
├── model               # mongoDB interface
│   └── model.go
└── utils               # utils for websocket
    ├── client.go
    └── hub.go

Build

Refer to makefile

This project use swaggo/swag to generate swagger documention. You can install it by:

go get -u github.com/swaggo/swag/cmd/swag

# 1.16 or newer
go install github.com/swaggo/swag/cmd/swag@latest

If you modified any swagger comments, you need to run swag init before building.

Usage

make sure you have mongoDB installed and running.

Usage: D:\Dev\Desktop\golang-ws\bin.exe [-a addr:port] [-A addr:port] [-D database] [-M url] [-s addr:port] [-w path] [parameters ...]
 -a, --addr-http=addr:port
       HTTP API address (default: :8080)
 -A, --addr-mqtt=addr:port
       MQTT broker address (default: :1883)
 -D, --database=database
       Database name (default: mqtt)
 -M, --mongo-url=url
       MongoDB connection URL (default: mongodb://localhost:27017)
       mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]
 -s, --addr-swagger=addr:port
       Swagger BaseURL -- change this if swagger is not working
       correctly
 -w, --websocket=path
       Websocket listening path -- default '/ws'

API documentation

HTTP

check docs/swagger.yaml for HTTP API documentation. Or use access the swagger UI by http://localhost:8080/swagger/index.html

Websocket

The default websocket url is ws://localhost:8080/ws.

Any MQTT package will be automatically forwarded to the websocket as follows:

{
    "topic": "temperature",
    "payload": "23.5"
}

Todo

  • Record Client ID
  • makefile
  • config file
  • swagger documention
  • refactor (split main into multiple files)
  • unit tests

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT This file was generated by swaggo/swag
Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT This file was generated by swaggo/swag

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址