Node-Red MongoDB
參考來源
https://leeluchowdaryravi.wordpress.com/2018/02/26/node-red-sensors-store-data-in-mongodb-database-and-exploring-thingspeak-mqttool/
MongoDB與Studio 3T 儲存檔案位置
http://alex9ufoexploer.blogspot.com/2018/11/mongodb-studio-3t.html
UI ON,OFF 按鈕輸出 ON ,OFF payload 發行到到MQTT broker.mqtt-dashboard.com : 1883
Topic 為 alex9ufo/mongodb/LED
訂閱 Topic : alex9ufo/mongodb/LED 主題送至MongodB 儲存到 D:\Mongodb\data目錄下
MongoDbIOT 伺服器 Collections 為IOT
1)啟動Mongodb 安裝目錄為 D:\Mongodb
a.bat 批次檔
d:
cd D:\Mongodb\bin
mongod --dbpath d:\MongoDB\data\db
2) Studio 3T 使用 Studio 3T 作為管理 MongoDB 的方法
最新10筆資料function
msg.limit = 10;
msg.skip = 0;
msg.sort = {"_id": -1}
return msg;
Json的內容 "_id", "payload" 二個欄位
{
"_id" : ObjectId("5ffad9eda72c080c0421ba8d"),
"payload" : "OFF"
}
MongoDB節點設定
1) Save 儲存紀錄(record)
2) Find 查詢紀錄(record)
Node-Red 程式
[{"id":"e644df1.2a90c2","type":"mqtt out","z":"27b256ba.2bff8a","name":"MongoLED","topic":"alex9ufo/mongodb/LED","qos":"1","retain":"","broker":"e4d9b72d.d14398","x":250,"y":60,"wires":[]},{"id":"ce5e629e.b0ec3","type":"mqtt in","z":"27b256ba.2bff8a","name":"MongoLED","topic":"alex9ufo/mongodb/LED","qos":"1","datatype":"auto","broker":"e4d9b72d.d14398","x":100,"y":140,"wires":[["99c257df.71e118","c8b5e7f0.6c4d58"]]},{"id":"99c257df.71e118","type":"ui_text","z":"27b256ba.2bff8a","group":"ac0f1141.eb50e","order":63,"width":"0","height":"0","name":"","label":"LED Status","format":"{{msg.payload}}","layout":"row-center","x":270,"y":200,"wires":[]},{"id":"300cba7b.f67f86","type":"ui_button","z":"27b256ba.2bff8a","name":"","group":"ac0f1141.eb50e","order":61,"width":"0","height":"0","passthru":false,"label":"ON","tooltip":"","color":"","bgcolor":"","icon":"","payload":"ON","payloadType":"str","topic":"","x":90,"y":40,"wires":[["e644df1.2a90c2"]]},{"id":"dcb72cf1.f01c5","type":"ui_button","z":"27b256ba.2bff8a","name":"","group":"ac0f1141.eb50e","order":62,"width":"0","height":"0","passthru":false,"label":"OFF","tooltip":"","color":"","bgcolor":"","icon":"","payload":"OFF","payloadType":"str","topic":"","x":90,"y":100,"wires":[["e644df1.2a90c2"]]},{"id":"c8b5e7f0.6c4d58","type":"mongodb out","z":"27b256ba.2bff8a","mongodb":"7faa7c87.42e514","name":"","collection":"IOT","payonly":true,"upsert":false,"multi":false,"operation":"store","x":340,"y":140,"wires":[]},{"id":"76030ade.7f7e44","type":"mongodb in","z":"27b256ba.2bff8a","mongodb":"7faa7c87.42e514","name":"","collection":"IOT","operation":"find","x":220,"y":300,"wires":[["68a9fd33.b402d4","4cdc7aff.a11b94"]]},{"id":"68a9fd33.b402d4","type":"debug","z":"27b256ba.2bff8a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":490,"y":360,"wires":[]},{"id":"3c744d.2d382bb4","type":"function","z":"27b256ba.2bff8a","name":"最新5筆資料","func":"msg.limit = 10;\nmsg.skip = 0;\nmsg.sort = {\"_id\": -1}\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":310,"y":240,"wires":[["76030ade.7f7e44"]]},{"id":"3f02bea7.f78692","type":"ui_button","z":"27b256ba.2bff8a","name":"","group":"ac0f1141.eb50e","order":65,"width":0,"height":0,"passthru":false,"label":"檢視最新10筆資料","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":130,"y":240,"wires":[["3c744d.2d382bb4"]]},{"id":"4cdc7aff.a11b94","type":"ui_table","z":"27b256ba.2bff8a","group":"ac0f1141.eb50e","name":"","order":65,"width":0,"height":0,"columns":[],"outputs":0,"cts":false,"x":490,"y":300,"wires":[]},{"id":"e4d9b72d.d14398","type":"mqtt-broker","name":"","broker":"broker.mqtt-dashboard.com","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"ac0f1141.eb50e","type":"ui_group","name":"LED","tab":"834e019a.2dfbb","order":1,"disp":true,"width":"8","collapse":true},{"id":"7faa7c87.42e514","type":"mongodb","hostname":"127.0.0.1","port":"27017","db":"MongoDbIOT","name":""},{"id":"834e019a.2dfbb","type":"ui_tab","name":"MongoDB","icon":"dashboard","disabled":false,"hidden":false}]
沒有留言:
張貼留言