# node-mongodb-mqtt **Repository Path**: blaunicorn/node-mongodb-mqtt ## Basic Information - **Project Name**: node-mongodb-mqtt - **Description**: 获取emqtx免费版中传感器数据并webhook转存 mongodb和mysql中 - **Primary Language**: JavaScript - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-08-27 - **Last Updated**: 2022-12-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 介绍 ### 获取 emqtx 免费版中传感器数据并 webhook 转存 ### Express,Sequelize 和 MySQL 的 Node.js Rest API https://cloud.tencent.com/developer/article/1745399 ``` npm install express sequelize mysql2 cors --save ``` ### create a new repository on the command line ``` echo "# node-mongodb-mqtt" >> README.md git init git add README.md git commit -m "first commit" git branch -M main git remote add origin git@github.com:blaunicorn/node-mongodb-mqtt.git git remote add github git@github.com:blaunicorn/node-mongodb-mqtt.git git push -u origin main ``` ### push an existing repository from the command line ``` git remote add origin git@github.com:blaunicorn/node-mongodb-mqtt.git git remote add github git@github.com:blaunicorn/node-mongodb-mqtt.git git branch -M main git push -u origin main ``` 用 nodejs 搭建 webhooks 中转 中转建立在 81.70.104.105 端口号在 8027 mqtx 接收传感器数据 http://81.70.104.105:18083/#/ emqx 服务器 admin/public ``` 历史数据存 mongodb表 "mongodb://admin:123qwe@81.70.104.105:27017/testdb"; ``` ``` // 实时数据,提前每一个device_id最新的一条存入sql表,通过mqtt更新relay状态 // 数据表名/密码gva gva 2wi7N4AycJ7yGeCB http://81.70.77.41/ mqtts表 ``` ``` // 数据结构实例 {"device_id":"esp_device001_370098", "type":"温湿度传感器", "sun":1, "temp":2, "humi":3, "relay":0 } ``` ``` // webhook 返回的body数据 params: {}, query: {}, body: { username: 'undefined', topic: '$sys/370098/esp_device001/dp/post/json', timestamp: 1630051806952, qos: 0, publish_received_at: 1630051806952, pub_props: {}, peerhost: '42.102.115.245', payload: '{"device_id":"esp_device001_370098",\n' + '"type":"温湿度传感器",\n' + '"sun":1,\n' + '"temp":2,\n' + '"humi":3,\n' + '"relay":0\n' + '}', node: 'emqx@127.0.0.1', metadata: { rule_id: 'rule:496560' }, id: '0005CA8602EB3A89F44E16006CDC0006', headers: { username: 'undefined', protocol: 'mqtt', proto_ver: 4, properties: {}, peerhost: '42.102.115.245' }, flags: { retain: false, dup: false }, event: 'message.publish', clientid: 'mqttx_391be81f' }, ```