【智控万物】Node RED 树莓派物联网之MQTT(Easy Iot)

2020-05-115768
AI 快速预览详细 收起
本文介绍了如何使用Node-RED和Easy IoT平台通过MQTT协议实现树莓派的物联网应用。首先介绍了MQTT协议的特点和优势,然后详细说明了如何在Node-RED中配置MQTT节点,并通过Easy IoT平台进行数据监控和实时反馈。文章还提供了具体的配置步骤和示例图,帮助读者快速上手物联网开发。
【MQTT】消息推送标准协议:MQTT
    随着物联网(Internet of Things,IoT)的兴起,机器之间(Machine-to-Machine,M2M)的大规模信息沟通成为重要的课堂,之前HTTP的请求/回答(Request/Response)模式不再合适,取而代之的是发布/订阅(Publish/Subscribe)模式。这就是轻量级、可扩展的MQTT(Message Queuing Telemetry Transport)可以施展拳脚的舞台。
    详细介绍:https://www.jianshu.com/p/3920f4701da0
【Easy Iot】
Easy IoT是一个国际化物联网服务平台 https://iot.dfrobot.com.cn/,可以对联网的传感器/执行器数据进行实时监控和反馈,统计和分析已经接收的数据,并向传感器/执行器发送数据,帮助实现控制效果。
【Node-red】
Node-RED 是构建物联网(IOT, Internet of Things)应用程序的一个强大工具,其重点是简化代码块的“连接”以执行任务。它使用可视化编程方法,允许开发人员将预定义的代码块(称为“节点”,Node)连接起来执行任务。连接的节点,通常是输入节点、处理节点和输出节点的组合,当它们连接在一起时,构成一个“流”(Flows)。
Node-red使用Easy Iot


【智控万物】Node RED 树莓派物联网之MQTT(Easy Iot)图2
MQTT配置,主题消息发布,主题订阅。
【智控万物】Node RED 树莓派物联网之MQTT(Easy Iot)图4

【智控万物】Node RED 树莓派物联网之MQTT(Easy Iot)图3

【智控万物】Node RED 树莓派物联网之MQTT(Easy Iot)图5

【智控万物】Node RED 树莓派物联网之MQTT(Easy Iot)图1


【智控万物】Node RED 树莓派物联网之MQTT(Easy Iot)图6

【简单演示】
【智控万物】Node RED 树莓派物联网之MQTT(Easy Iot)图7

创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(4)
云天
云天
作者
格式不成问题,但我从其它网站复制的,拷贝到node-RED,会出现原代码缺失{}[]等这些符号的问题
pATAq
pATAq
上述代码直接拷贝到 node-RED 会不会以为格式问题不识别
云天
云天
作者
[{"id":"b8cba949.172578","type":"tab","label":"流程1","disabled":false,"info":""},{"id":"6fc368b1.5ed4d8","type":"ui_tab","z":"","name":"TAB","icon":"dashboard","disabled":false,"hidden":false},{"id":"d3f0e284.fc0cf","type":"ui_group","z":"","name":"Group","tab":"6fc368b1.5ed4d8","order":1,"disp":true,"width":"6","collapse":false},{"id":"b8c4b9e9.251c68","type":"ui_base","theme":{"name":"theme-light","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"Arial Black,Arial Black,Gadget,sans-serif","edited":true,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#097479","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#4B7930","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"},"themeState":{"base-color":{"default":"#0094CE","value":"#0094CE","edited":false},"page-titlebar-backgroundColor":{"value":"#0094CE","edited":false},"page-backgroundColor":{"value":"#fafafa","edited":false},"page-sidebar-backgroundColor":{"value":"#ffffff","edited":false},"group-textColor":{"value":"#1bbfff","edited":false},"group-borderColor":{"value":"#ffffff","edited":false},"group-backgroundColor":{"value":"#ffffff","edited":false},"widget-textColor":{"value":"#111111","edited":false},"widget-backgroundColor":{"value":"#0094ce","edited":false},"widget-borderColor":{"value":"#ffffff","edited":false},"base-font":{"value":"Arial Black,Arial Black,Gadget,sans-serif"}},"angularTheme":{"primary":"indigo","accents":"blue","warn":"red","background":"grey"}},"site":{"name":"Node-RED Dashboard","hideToolbar":"false","allowSwipe":"false","lockMenu":"false","allowTempTheme":"true","dateFormat":"DD/MM/YYYY","sizes":{"sx":64,"sy":64,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}}},{"id":"d48cef4b.964868","type":"mqtt-broker","z":"","name":"","broker":"iot.dfrobot.com.cn","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"E1RcL1tZg","birthQos":"0","birthRetain":"true","birthPayload":"你好订阅","closeTopic":"E1RcL1tZg","closeQos":"0","closeRetain":"true","closePayload":"再见订阅","willTopic":"E1RcL1tZg","willQos":"0","willRetain":"true","willPayload":"意外退出订阅"},{"id":"6728a1ff.22b7c","type":"baidu-face-configurator","z":"","name":"","client_id":"YDGYNo2mlufGUA4mGYw9x30V","client_secret":"moMRp76G8ZF4W5pAf6l44swHcyRwtAfR"},{"id":"ca034400.572178","type":"ui_text","z":"b8cba949.172578","group":"d3f0e284.fc0cf","order":3,"width":0,"height":0,"name":"小鹿回答","label":"小鹿回答:","format":"{{msg.payload}}","layout":"row-left","x":720,"y":1140,"wires":[],"inputLabels":["内容"]},{"id":"b334c2b2.f7cac","type":"http request","z":"b8cba949.172578","name":"图灵对话","method":"POST","ret":"obj","paytoqs":false,"url":"http://openapi.tuling123.com/openapi/api/v2","tls":"","persist":false,"proxy":"","authType":"","x":340,"y":1140,"wires":[["2db96f9e.798a7"]]},{"id":"713631fc.36cb3","type":"json","z":"b8cba949.172578","name":"","property":"payload","action":"obj","pretty":false,"x":510,"y":1040,"wires":[["b334c2b2.f7cac"]]},{"id":"da8c44fd.f72a48","type":"inject","z":"b8cba949.172578","name":"信息","topic":"信息","payload":"{ \t\"reqType\":0, \"perception\": { \"inputText\": { \"text\": \"text6174\" }, \"inputImage\": { \"url\": \"imageUrl\" }, \"selfInfo\": { \"location\": { \"city\": \"北京\", \"province\": \"北京\", \"street\": \"信息路\" } } }, \"userInfo\": { \"apiKey\": \"06c515993ed74e8e9ae1aa63a80ab9ac\", \"userId\": \"sxs12345678\" } }","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1060,"wires":[["124d0b9a.c926e4"]]},{"id":"61ab0b78.653c34","type":"ui_button","z":"b8cba949.172578","name":"","group":"d3f0e284.fc0cf","order":12,"width":0,"height":0,"passthru":false,"label":"发送信息","tooltip":"","color":"","bgcolor":"","icon":"","payload":"{ \t\"reqType\":0, \"perception\": { \"inputText\": { \"text\": \"text6174\" }, \"inputImage\": { \"url\": \"imageUrl\" }, \"selfInfo\": { \"location\": { \"city\": \"北京\", \"province\": \"北京\", \"street\": \"信息路\" } } }, \"userInfo\": { \"apiKey\": \"06c515993ed74e8e9ae1aa63a80ab9ac\", \"userId\": \"sxs12345678\" } }","payloadType":"str","topic":"","x":120,"y":1000,"wires":[["124d0b9a.c926e4"]]},{"id":"2db96f9e.798a7","type":"change","z":"b8cba949.172578","name":"返回内容","rules":[{"t":"set","p":"payload","pt":"msg","to":"$lookup($lookup($lookup(payload, \"results\"),\"values\"),\"text\")\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":1140,"wires":[["ca034400.572178"]]},{"id":"124d0b9a.c926e4","type":"change","z":"b8cba949.172578","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"text6174","fromt":"str","to":"content","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1040,"wires":[["713631fc.36cb3"]]},{"id":"7673af3d.a49f1","type":"ui_text_input","z":"b8cba949.172578","name":"对话输入","label":"对话输入","tooltip":"","group":"d3f0e284.fc0cf","order":13,"width":0,"height":0,"passthru":true,"mode":"text","delay":"0","topic":"对话输入","x":120,"y":920,"wires":[["15bb209d.d5a61f"]]},{"id":"15bb209d.d5a61f","type":"function","z":"b8cba949.172578","name":"信息处理","func":"var content=flow.get('count');\nflow.set('content',msg.payload);\nmsg.payload='{ \t\"reqType\":0, \"perception\": { \"inputText\": { \"text\": \"text6174\" }, \"inputImage\": { \"url\": \"imageUrl\" }, \"selfInfo\": { \"location\": { \"city\": \"北京\", \"province\": \"北京\", \"street\": \"信息路\" } } }, \"userInfo\": { \"apiKey\": \"06c515993ed74e8e9ae1aa63a80ab9ac\", \"userId\": \"sxs12345678\" } }';\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":920,"wires":[["124d0b9a.c926e4"]]},{"id":"83cc1198.7a95","type":"mqtt in","z":"b8cba949.172578","name":"MQTT主题订阅","topic":"E1RcL1tZg","qos":"0","datatype":"auto","broker":"d48cef4b.964868","x":380,"y":460,"wires":[["5e03d2ae.1f4c2c"]]},{"id":"a2e2ba9f.cbcbc8","type":"mqtt out","z":"b8cba949.172578","name":"MQTT发布主题","topic":"E1RcL1tZg","qos":"0","retain":"true","broker":"d48cef4b.964868","x":380,"y":560,"wires":[]},{"id":"5e03d2ae.1f4c2c","type":"debug","z":"b8cba949.172578","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":460,"wires":[]},{"id":"d24e4c56.64ee3","type":"inject","z":"b8cba949.172578","name":"内容发布","topic":"内容发布","payload":"你好 世界","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":560,"wires":[["a2e2ba9f.cbcbc8"]]},{"id":"adb83e69.18fb3","type":"debug","z":"b8cba949.172578","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":740,"y":660,"wires":[]},{"id":"c3fbe67d.50899","type":"debug","z":"b8cba949.172578","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":660,"y":760,"wires":[]},{"id":"fbb92b43.8db318","type":"trigger","z":"b8cba949.172578","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"5","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":340,"y":680,"wires":[["adb83e69.18fb3"]]},{"id":"a8348382.34764","type":"inject","z":"b8cba949.172578","name":"","topic":"","payload":"reset","payloadType":"str","repeat":"2","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":680,"wires":[[]]},{"id":"2108a768.1cd4a","type":"exec","z":"b8cba949.172578","command":"hostname","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":340,"y":780,"wires":[["c3fbe67d.50899"],["c3fbe67d.50899"],["c3fbe67d.50899"]]},{"id":"222ab77b.57e0ac","type":"inject","z":"b8cba949.172578","name":"触发器","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":780,"wires":[["2108a768.1cd4a"]]},{"id":"698414fd.42d568","type":"debug","z":"b8cba949.172578","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1740,"y":360,"wires":[]},{"id":"553dd558.408588","type":"catch","z":"b8cba949.172578","name":"","scope":["faa7f519.6f60d8"],"uncaught":false,"x":1640,"y":240,"wires":[["a539cb23.cf2f4"]]},{"id":"a539cb23.cf2f4","type":"debug","z":"b8cba949.172578","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1820,"y":240,"wires":[]},{"id":"b57086c1.5e7388","type":"base64","z":"b8cba949.172578","name":"","action":"","property":"payload","x":340,"y":200,"wires":[["1f4a37d4.69a8ac"]]},{"id":"8ef15422.b75df8","type":"inject","z":"b8cba949.172578","name":"","topic":"","payload":"a","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":200,"wires":[["b57086c1.5e7388"]]},{"id":"1f4a37d4.69a8ac","type":"debug","z":"b8cba949.172578","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":220,"wires":[]},{"id":"359f924f.324cfe","type":"image","z":"b8cba949.172578","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":520,"y":280,"wires":[]},{"id":"af1d61e2.da1d1","type":"http request","z":"b8cba949.172578","name":"","method":"GET","ret":"bin","paytoqs":false,"url":"https://dummyimage.com/200x150/000/fff&text={{{payload}}}","tls":"","persist":false,"proxy":"","authType":"","x":480,"y":340,"wires":[["492d70cb.7fa64"]]},{"id":"58225c30.7b0324","type":"inject","z":"b8cba949.172578","name":"Generate next image","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":320,"wires":[["746b5307.33bf2c"]]},{"id":"746b5307.33bf2c","type":"function","z":"b8cba949.172578","name":"image counter","func":"var count = flow.get(\"count\")||0;\n\ncount++;\n\nnode.status({fill:\"blue\",shape:\"ring\",text:\"Image \" + count});\n\n// Save the new value back to context so it will be available next time\nflow.set('count',count);\n\n// Update the message payload and return - no need to create a new msg\nmsg.payload = \"Image \" + count;\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":320,"wires":[["af1d61e2.da1d1"]]},{"id":"492d70cb.7fa64","type":"image","z":"b8cba949.172578","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":true,"active":true,"pass":false,"outputs":0,"x":740,"y":320,"wires":[]},{"id":"4ce52bec.4461d4","type":"wfwatch","z":"b8cba949.172578","folder":"D://test","x":110,"y":100,"wires":[["c58a8d6e.8ee21"]]},{"id":"c58a8d6e.8ee21","type":"switch","z":"b8cba949.172578","name":"","property":"payload.changeType","propertyType":"msg","rules":[{"t":"eq","v":"create","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":330,"y":100,"wires":[["894ac1de.f7e0a"]]},{"id":"894ac1de.f7e0a","type":"change","z":"b8cba949.172578","name":"变量","rules":[{"t":"move","p":"payload.filePath","pt":"msg","to":"filename","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":100,"wires":[["8c69ed81.c6a4f"]]},{"id":"8c69ed81.c6a4f","type":"file in","z":"b8cba949.172578","name":"","filename":"","format":"","chunk":false,"sendError":false,"x":530,"y":40,"wires":[["60857acb.ec22c4"]]},{"id":"60857acb.ec22c4","type":"base64","z":"b8cba949.172578","name":"","action":"","property":"payload","x":700,"y":20,"wires":[["f14b543b.5e1ed8"]]},{"id":"f14b543b.5e1ed8","type":"change","z":"b8cba949.172578","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"image","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":80,"wires":[["3702a74e.628018"]]},{"id":"3702a74e.628018","type":"baidu-dynamic-body-num","z":"b8cba949.172578","name":"","baiduface":"6728a1ff.22b7c","image":"","show":true,"x":1060,"y":80,"wires":[["5a4fa738.b21f18","8e1f6e4d.deedd"]]},{"id":"5a4fa738.b21f18","type":"base64","z":"b8cba949.172578","name":"","action":"","property":"payload.image","x":1260,"y":80,"wires":[["cf3b4545.1dabb8"]]},{"id":"cf3b4545.1dabb8","type":"change","z":"b8cba949.172578","name":"转移变量","rules":[{"t":"move","p":"payload.image","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1400,"y":80,"wires":[["6792f9e6.650f28"]]},{"id":"6792f9e6.650f28","type":"image","z":"b8cba949.172578","name":"","width":"600","data":"payload","dataType":"msg","thumbnail":false,"pass":false,"outputs":0,"x":1560,"y":80,"wires":[]},{"id":"8e1f6e4d.deedd","type":"change","z":"b8cba949.172578","name":"转移变量","rules":[{"t":"move","p":"payload.person_num","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1260,"y":20,"wires":[["c9bf0a40.9c1308"]]},{"id":"c9bf0a40.9c1308","type":"debug","z":"b8cba949.172578","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1410,"y":20,"wires":[]},{"id":"2aeef2db.727b6e","type":"inject","z":"b8cba949.172578","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":20,"wires":[["5e7d457a.fb1b3c"]]},{"id":"5e7d457a.fb1b3c","type":"www-request","z":"b8cba949.172578","name":"客厅摄像机获取图片","method":"GET","ret":"bin","url":"http://192.168.31.203/ISAPI/Streaming/channels/201/picture?videoResolutionWidth=1920&videoResolutionHeight=1080","follow-redirects":true,"persistent-http":false,"tls":"","x":320,"y":20,"wires":[["60857acb.ec22c4"]]},{"id":"d25026f5.eb9f88","type":"image","z":"b8cba949.172578","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":1240,"y":340,"wires":[]}]
云天
云天
作者
- 没有更多了 -