{"id":19200362,"url":"https://github.com/wivwiv/mqtt-iot-platform","last_synced_at":"2025-07-20T05:33:13.904Z","repository":{"id":40857789,"uuid":"166817791","full_name":"wivwiv/mqtt-iot-platform","owner":"wivwiv","description":"IoT Platform 基于 Nest.js \u0026 Egg.js 与 EMQ X 开发","archived":false,"fork":false,"pushed_at":"2023-01-24T01:22:42.000Z","size":3211,"stargazers_count":64,"open_issues_count":43,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-09T02:43:48.044Z","etag":null,"topics":["acl","eggjs","emqx","iot","iot-platform","mqtt","mqtt-websocket","nestjs","websocket"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wivwiv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-21T13:21:41.000Z","updated_at":"2025-04-02T09:33:15.000Z","dependencies_parsed_at":"2023-02-13T08:30:45.374Z","dependency_job_id":null,"html_url":"https://github.com/wivwiv/mqtt-iot-platform","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/wivwiv/mqtt-iot-platform","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wivwiv%2Fmqtt-iot-platform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wivwiv%2Fmqtt-iot-platform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wivwiv%2Fmqtt-iot-platform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wivwiv%2Fmqtt-iot-platform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wivwiv","download_url":"https://codeload.github.com/wivwiv/mqtt-iot-platform/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wivwiv%2Fmqtt-iot-platform/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266071519,"owners_count":23871940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["acl","eggjs","emqx","iot","iot-platform","mqtt","mqtt-websocket","nestjs","websocket"],"created_at":"2024-11-09T12:32:15.806Z","updated_at":"2025-07-20T05:33:08.890Z","avatar_url":"https://github.com/wivwiv.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Egg.js Quick Start IoT Application Service Development\n\n\u003e 2020.02.10\n\u003e Important notice:\n\u003e Egg.js backend has stopped development, please use the background based on Nest.js framework, [Click here](./nest-backend/README.md)\n\n\n[中文文档](./README.zh-CN.md) | English Document\n\n## The IoT Platform in Nest.js is coming.\n\n[Click here](./nest-backend/README.md)\n\n- ACL/Auth Admin WEB and API\n- Message Publish WEB and API\n- Device Management WEB and API, include banned, proxy subscription, online status, kick off\n- Store messages via InfluxDB and analysis like [EMQ X + InfluxDB + Grafana MQTT IoT data visualization](https://wivwiv.com/post/emq-x-%E4%B8%8E-influxdb-grafana-%E7%89%A9%E8%81%94%E7%BD%91%E6%95%B0%E6%8D%AE%E5%8F%AF%E8%A7%86%E5%8C%96%E9%9B%86%E6%88%90%E6%96%B9%E6%A1%88/#more)\n- QoS 1/QoS 2 Acked and Deliver status track\n- EMQ X config generator like [https://nginxconfig.io](https://nginxconfig.io)\n- Cluster deployment, fully implemented through EMQ x broker open source\n\n\nUse Egg.js with the help of EMQ X Broker message middleware to quickly develop an IoT application server based on the MQTT protocol, and implement multiple protocols such as WebSocket and MQTT access communication.\n\nThis project is derived from [EMQ X Cloud](https://cloud.emqx.io?spm=wivwiv) technology and scheme verification.\n\nThis project integrates EMQ X Broker plug-ins and APIs through Egg.js to achieve communication access, connection authentication, status recording, and message persistence. It can be used as a web instant application, IM communication, and IoT communication model.\n\n\u003e This project is only for personal study/work verification EMQ X and MQTT functions.\n\nThe starting blog address (more EMQ X MQTT related integration solutions):\n- Seriously digging the W I V blog site: [https://wivwiv.com/](https://wivwiv.com/)\n\nMQTT experience access address:\n- MQTT TCP: `mqtt://broker.emqx.io:1883`\n- MQTT WebSocket: `ws://broker.emqx.io:8083/mqtt`\n- Online MQTT Pub/Sub: `http://tools.emqx.io/`\n\nAPI list view:\n- API list: `http://localhost:7001/api/`\n\n### function list\n\n- [x] Device management\n- [x] Device access control\n- [ ] Device publish and subscribe, rights management\n- [x] message persistence\n- [x] Message query\n- [x] Message delivery HTTP API\n- [ ] User Management\n- [ ] Multi-user support\n- [ ] docker-composes\n\n\n### MQTT Publish and Subscribe Model\n\n[MQTT](https://www.ibm.com/developerworks/cn/iot/iot-mqtt-why-good-for-iot/index.html) is a lightweight and flexible network protocol. Communication messages are organized by topic, such as:\n\n```\nchat/room/1\n\nchat/room/1/control\n\nchat/user/wivwiv\n\nsensor/10/temperature\n\nsensor/+/temperature\n\n```\n\nTopics are separated by `/`, supporting `+`, `#` wildcards:\n\n```\n'+': Wildcard a level, such as a/+, matching a/x, a/y\n\n'#': Wildcard multiple levels, such as a/#, matching a/x, a/b/c/d\n```\n\n\n### system structure\n\n- The device selects the appropriate access protocol to access the messaging middleware:\n  - Browser environment: WebSocket\n  - Node.js environment: MQTT, WebSocket\n  - Hardware equipment: MQTT, MQTT-SN, CoAP\n\n\n- Unified authentication for message middleware: call authentication service interface for connection authentication through EMQ X HTTP Auth plug-in\n\n- System switch device online status: call-related interface through EMQ X WebHook plugin\n\n- Message middleware performs ACL authentication when the device publishes a message, such as:\n  - xx devices only have subscription rights under yy topic\n  - Only x devices have publishing permissions under the y theme\n\n- Broker forwards messages to related topics, and the persistence service persists all messages to the database\n\n![](./docs/_assets/topology.png)\n\n\u003e The EMQ X Broker open-source version has no persistence function. This system uses the MQTT client to subscribe to the wildcard topic (#) on the server-side to write all messages to the database simultaneously (this method has performance and reliability issues).\n\nWhat are the advantages of writing WebSocket and TCP services directly with Node.js?\n\n- Performance issues: professional Broker;\n- Protocol support: multiple protocols access, commonly used MQTT, WebSocket, HTTP protocols are supported;\n- Complete functions: communication (publish and subscribe) permissions, device status management, and data persistence solutions are all available.\n\n\n### EMQ X Installation Configuration\n\n[EMQ X Download](http://emqtt.com/downloads) It is recommended to download the 3.0+ version.\n\n#### Connection authentication\n\nSee backend code for `controller.home.deviceConnectAuth`\n\nhttps://github.com/emqx/emqx-auth-http\n\nModify the configuration file:\n\n```\n## etc/plugins/emqx_auth_http.conf\nvi etc/plugins/emqx_auth_http.conf\n```\n\n```\n## HTTP Authentication Address\nauth.http.auth_req = http://127.0.0.1:7001/api/connect/auth\n\n## HTTP authentication method\nauth.http.auth_req.method = post\n\n## body parameter, if you want to customize, you can add it after the comma\nauth.http.auth_req.params = clientId=%c,username=%u,password=%P\n\n```\n\nNote: The authentication API responds with HTTP status 20X for authentication success, 40X for the authentication failure.\n\nThe plugin also has ACL capabilities.\n\n#### Online and offline status\n\nThe back-end code see `controller.home.deviceConnectStatus`\n\nhttps://github.com/emqx/emqx-web-hook\n\nModify the configuration file:\n\n```\n## etc/plugins/emqx_web_hook.conf\nvi etc/plugins/emqx_web_hook.conf\n```\n\n```\n## callback address\nweb.hook.api.url = http://127.0.0.1:7001/api/connect/status\n\n## Keep two, comment out the others\n\nweb.hook.rule.client.connected.1 = {\"action\": \"on_client_connected\"}\nweb.hook.rule.client.disconnected.1 = {\"action\": \"on_client_disconnected\"}\n\n```\n\n\n\nLaunch EMQ X:\n```\n./bin/emqx start\n```\n\nStart the HTTP authentication plugin:\n```\n./bin/emqx_ctl plugins load emqx_auth_http\n./bin/emqx_ctl plugins load emqx_web_hook\n```\n\nSimple management:\n\nVisit http://127.0.0.1:18083 EMQ X Management Console.\n\n#### Agent Subscription\n\nEMQ X supports multiple proxy subscriptions, which automatically subscribe to topics in a specific format for the device after the device is connected to control communication.\n\nOpen the EMQ X configuration file `etc/emqx.conf` and find the relevant configuration items of the Subscription Module. You can configure multiple automatic subscription items after the device is connected:\n\n```bash\n## Subscription Module\n\n## Enable subscription module\nmodule.subscription = on\n\n## Subscribe the Topics automatically when client connected.\nmodule.subscription.1.topic = $ client /% c\n## Qos of the subscription: 0 | 1 | 2\nmodule.subscription.1.qos = 0\n```\n\nSupports placeholders,% c is the clientId of the device, that is, each device will automatically subscribe to the `$ client /: clientId` main after a successful connection\n\n#### EMQ X Management Monitoring API\n\nhttps://docs.emqx.io/broker/latest/cn/rest.html\n\n### Device access\n\nJavaScript MQTT client recommends [MQTT.js](https://www.npmjs.com/package/mqtt). For specific usage examples, see `public/index.html` and` AutoRun.js`,\n\nAfter the system is running, you can view the communication effect after executing `node AutoRun.js` in multiple windows at the same time.\n\n\nQuick access code:\n\n```js\nconst mqtt = require ('mqtt')\n\nconst clientId = 'xxx'\nconst client = mqtt.connect ('mqtt://127.0.0.1:1883', {\n  clientId,\n  username: 'xxx',\n  password: 'xxx',\n})\n\nclient.on ('connect', () =\u003e {\n    console.log ('Device is connected')\n    // {topic1: qos, topic2: qos}\n    client.subscribe ({'room/+/cmd': 1, 'user/#': 0, '#': 0}, () =\u003e {\n      console.log ('Subscription succeeded')\n\n      setInterval (() =\u003e {\n        client.publish (`room/$ {clientId}/cmd`,` cmd message for ${clientId} `)\n\n        client.publish (`user/$ {clientId}`, `user message for ${clientId}`)\n\n        client.publish (`$client/${clientId}`, `Broker subscription message for $ {clientId}`)\n      }, 5000)\n    })\n})\n\nclient.on ('message', (topic, message) =\u003e {\n  console.log (`Received message topic: ${topic}, message: ${message.toString ())`)\n})\n```\n\n\n### Service startup configuration\n\nMongoDB connection:\n```js\n// config/config. *. js\nconfig.mongoose = {\n  url: 'mongodb: //127.0.0.1: 27017/egg_iot_with_mqtt',\n}\n```\n\nServer EMQ X connection:\n```js\n// config/config. *. js\nconfig.mqtt = {\n  address: 'mqtt://127.0.0.1: 1883',\n  queueSize: 4, // number of shared subscriptions\n  topic: '$queue/#', // Subscribe to topic, see MQTT protocol topic for details\n  // Certification Information\n  option: {\n    username: 'super_user_client',\n    password: '_this_is_secrect_',\n  },\n}\n```\n\n\n### Local development\n\n```bash\n$ npm i\n$ npm run dev\n$ open http://localhost:7001/\n```\n\n\n\n### Deployment\n\n```bash\n$ npm start\n$ npm stop\n```\n\n\n\n### Basic Demo\n\n```\nhttp://127.0.0.1:7001/index.html\n```\n\n\n\n### API Quick Tour\n\n```json\n[\n  {\n    \"path\": \"/api/payload\",\n    \"name\": \"View Message List\",\n    \"methods\": [\n      \"HEAD\",\n      \"GET\"\n    ]\n  },\n  {\n    \"path\": \"/api/payload/:id\",\n    \"name\": \"View message details\",\n    \"methods\": [\n      \"HEAD\",\n      \"GET\"\n    ]\n  },\n  {\n    \"path\": \"/api/payload/:id\",\n    \"name\": \"Delete message\",\n    \"methods\": [\n      \"DELETE\"\n    ]\n  },\n  {\n    \"path\": \"/api/devices\",\n    \"name\": \"Get Device List\",\n    \"methods\": [\n      \"HEAD\",\n      \"GET\"\n    ]\n  },\n  {\n    \"path\": \"/api/devices\",\n    \"name\": \"Create Device\",\n    \"methods\": [\n      \"POST\"\n    ]\n  },\n  {\n    \"path\": \"/api/devices/:id\",\n    \"name\": \"Get Device Details\",\n    \"methods\": [\n      \"HEAD\",\n      \"GET\"\n    ]\n  },\n  {\n    \"path\": \"/api/devices/:id\",\n    \"name\": \"Change Device\",\n    \"methods\": [\n      \"PUT\"\n    ]\n  },\n  {\n    \"path\": \"/api/devices/:id\",\n    \"name\": \"Remove Device\",\n    \"methods\": [\n      \"DELETE\"\n    ]\n  },\n  {\n    \"path\": \"/api/devices/:id/publish\",\n    \"name\": \"Send a message to the device\",\n    \"methods\": [\n      \"POST\"\n    ]\n  },\n  {\n    \"path\": \"/api/\",\n    \"name\": \"Get API\",\n    \"methods\": [\n      \"HEAD\",\n      \"GET\"\n    ]\n  },\n  {\n    \"path\": \"/api/connect/auth\",\n    \"name\": \"EMQ X Connection Authentication\",\n    \"methods\": [\n      \"POST\"\n    ]\n  },\n  {\n    \"path\": \"/api/connect/status\",\n    \"name\": \"EMQ X device status\",\n    \"methods\": [\n      \"POST\"\n    ]\n  }\n]\n```\n\n\n\n### koa-queries\n\n`/api/payload` and`/api/devices` use the [koa-queries] (https://www.npmjs.com/package/koa-queries) middleware, and you can customize the filter query list:\n\n- Refine search: `?${Key}__is=${value}`\n - http://localhost:7001/api/devices?clientId__is = 3457beb0-1e0b-11e9-a946-394b108d0c12\n\n-Fuzzy search: `?${Key}__like=${value}`\n - http://localhost:7001/api/devices?clientId__like= 3457beb0-1e0b-11e9-a946-394b108d0c12\n\n- Field nesting: `?${Key.subKey.subKey}__is=${value}`\n - http://localhost:7001/api/payload?raw.cmd.status__is=0\u0026isJSON__is=true\n\n\\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwivwiv%2Fmqtt-iot-platform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwivwiv%2Fmqtt-iot-platform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwivwiv%2Fmqtt-iot-platform/lists"}