IBM Node-RED 安装与使用教程
IBM Node-RED安装与使用教程
1.Node-RED
Node-RED 是构建物联网(IOT, Internet of Things)应用程序的一个强大工具,其重点是简化代码块的“连接”以执行任务。它使用可视化编程方法,允许开发人员将预定义的代码块(称为“节点”,Node)连接起来执行任务。连接的节点,通常是输入节点、处理节点和输出节点的组合,当它们连接在一起时,构成一个“流”(Flows)。
IBM Node-RED安装与使用教程
Node-RED最初是IBM在2013年末开发的一个开源项目,以满足他们快速连接硬件和设备到Web服务和其他软件的需求——作为物联网的一种粘合剂,它很快发展成为一种通用的物联网编程工具。重要的是,Node-RED已经迅速形成一个重要的、不断增长的用户基础和一个活跃的开发人员社区,他们正在开发新的节点,同时允许程序员复用Node-RED代码来完成各种各样的任务。
Node-Red是一个开源的可视化编程工具
Node-RED由IBM开发,主要用于连接连接计算机、传感器和在线服务等协议或组件,以简化它们之间的布线工作
Node-RED允许通过组合各部件来编写应用程序。这些部件也可以是硬件设备、Web API 、在线服务
2.Node-RED应用意义
2.1 Node-RED所属层次
Node-RED所属层次如下图:
IBM Node-RED安装与使用教程
主打的是业务逻辑层,但是也包含一些可视化展示层功能,第4部分有详细介绍
由此可见:
Node-RED并不是取代了代码,而是简化了代码
人们可以利用软件块和设备块更容易连线连成有用的系统,简化了开发
开发者也是想通过这个新颖的形式让人们更注重于创新,而不是正在重复地做什么
3.Node-RED安装【Docker版】
3.1 下载Node-RED Docker容器
Node-RED的1.0系列在Docker Hub上已经改名为nodered/node-red.
Node-RED的0.20.x在Docker Hub上仍然叫nodered/node-red-docker,
docker pull nodered/node-red
3.2 运行容器
kubernetes@kubernetes-virtual-machine:~$ docker run -it -p 1880:1880 --name nodered nodered/node-red
[email protected] start /usr/src/node-red
node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS “–userDir” “/data”
18 Mar 07:53:36 - [info]
18 Mar 07:53:36 - [info] Node-RED version: v1.0.4
18 Mar 07:53:36 - [info] Node.js version: v10.19.0
18 Mar 07:53:36 - [info] Linux 4.15.0-74-generic x64 LE
18 Mar 07:53:36 - [info] Loading palette nodes
18 Mar 07:53:37 - [info] Settings file : /data/settings.js
18 Mar 07:53:37 - [info] Context store : ‘default’ [module=memory]
18 Mar 07:53:37 - [info] User directory : /data
18 Mar 07:53:37 - [warn] Projects disabled : editorTheme.projects.enabled=false
18 Mar 07:53:37 - [info] Flows file : /data/flows.json
18 Mar 07:53:37 - [info] Creating new flow file
18 Mar 07:53:37 - [warn]
Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
18 Mar 07:53:37 - [info] Server now running at http://127.0.0.1:1880/
18 Mar 07:53:37 - [info] Starting flows
18 Mar 07:53:37 - [info] Started flows
客户端访问http://IP:1880,可以看到node-red 的工作界面,左侧是元素选择区,中间是画布区,右侧是信息/终端打印区,如下图:
IBM Node-RED安装与使用教程
4.使用Node-RED的准备工作
4.1 下载所需插件
操作顺序依次是:节点管理-控制面板-安装-搜索
IBM Node-RED安装与使用教程
4.2 搭建MQTT服务器
EMQ 是一个由国人开发的百万级分布式开源物联网 MQTT 消息服务器。
docker run --name emq -p 18083:18083 -p 1883:1883 -p 8084:8084 -p 8883:8883 -p 8083:8083 -d emqx/emqx
端口 所属协议
1883 MQTT 协议端口
8883 MQTT/SSL 端口
8083 MQTT/WebSocket 端口
8080 HTTP API 端口
18083 Dashboard 管理控制台端口
然后打开http://ip:18083即可打开界面
IBM Node-RED安装与使用教程
5.Node-RED的使用
5.1 输入与输出
1.首先拖进来输入和输出
IBM Node-RED安装与使用教程
2.配置输入节点
IBM Node-RED安装与使用教程
由于我当前选择的json模式,那需要编写一段json脚本
IBM Node-RED安装与使用教程
3.点击部署,并运行
IBM Node-RED安装与使用教程
可以看出上图输出是json模式
5.2 文件操作
这里以读文件举例
1.首先我在本地创建一个aaa.txt,并在里面写入“Hello Node-RED”
IBM Node-RED安装与使用教程
2.拖出来file in组件,注意这里演示的事读文件操作
IBM Node-RED安装与使用教程
3.拖出来function组件,用来编写文件路径
IBM Node-RED安装与使用教程
IBM Node-RED安装与使用教程
4.然后将输入和输出与其进行连接
IBM Node-RED安装与使用教程
5.部署运行即可输出文件中的内容
IBM Node-RED安装与使用教程
https://giphy.com/channel/rk2jh0
https://giphy.com/channel/yiwqn3
https://giphy.com/channel/ub7wnb
https://giphy.com/channel/ddng8m
https://giphy.com/channel/c5nb18
https://giphy.com/channel/y5mxgu
https://giphy.com/channel/9o6ei0
https://giphy.com/channel/of81u5
https://giphy.com/channel/1til2d
https://giphy.com/channel/g4rggi
https://giphy.com/channel/yarrqq
https://giphy.com/channel/8li0qm
https://giphy.com/channel/g5ew1y
https://giphy.com/channel/fyjfr3
https://giphy.com/channel/b778i1
https://giphy.com/channel/bzkijz
https://giphy.com/channel/uujd3q
https://giphy.com/channel/kn7wt7
https://giphy.com/channel/t1ksbc
https://giphy.com/channel/bgrz9h
https://giphy.com/channel/7392i1
https://giphy.com/channel/e9y29d
https://giphy.com/channel/ae7uwe
https://giphy.com/channel/c247kt
https://giphy.com/channel/vy48mm
https://giphy.com/channel/5ncn9m
https://giphy.com/channel/cv4ail
https://giphy.com/channel/9tibl1
https://giphy.com/channel/rq9aeh
https://giphy.com/channel/4cb1xn
https://giphy.com/channel/vpynnf
https://giphy.com/channel/jjz93s
https://giphy.com/channel/gpzx36
https://giphy.com/channel/xsywh7
https://giphy.com/channel/nnac6l
https://giphy.com/channel/ia82yi
https://giphy.com/channel/6pki8s
https://giphy.com/channel/c0lat2
https://giphy.com/channel/rpi2ww
https://giphy.com/channel/iplk9p
https://giphy.com/channel/ftvxne
https://giphy.com/channel/p5ss1j
https://giphy.com/channel/xgysja
https://giphy.com/channel/k7kubi
https://giphy.com/channel/lmeu2v
https://giphy.com/channel/ue4kf3
https://giphy.com/channel/zuru5h
https://giphy.com/channel/bu54lt
https://giphy.com/channel/2gdvou
https://giphy.com/channel/8rirvr
https://giphy.com/channel/91i4f0
https://giphy.com/channel/to5tm5
https://giphy.com/channel/8vllee
https://giphy.com/channel/vs71wn
https://giphy.com/channel/ed7ude
https://giphy.com/channel/65ygsa
https://giphy.com/channel/9rlbl7
https://giphy.com/channel/yfxi3y
https://giphy.com/channel/39hwze
https://giphy.com/channel/2m8qnh
https://giphy.com/channel/5zso6f
https://giphy.com/channel/7md95t
https://giphy.com/channel/q6r66x
https://giphy.com/channel/35t946
https://giphy.com/channel/wnv6fv
https://giphy.com/channel/o5gelm
https://giphy.com/channel/zg3a4j
https://giphy.com/channel/1at9rk
https://giphy.com/channel/ra9skb
https://giphy.com/channel/qxwpwz
https://giphy.com/channel/qrhwf2
https://giphy.com/channel/d01tk4
https://giphy.com/channel/1prweh
https://giphy.com/channel/mm51c4
https://giphy.com/channel/3ilh63
https://giphy.com/channel/lc98u0
https://giphy.com/channel/odecvx
https://giphy.com/channel/hpoaa8
https://giphy.com/channel/08meus
https://giphy.com/channel/wlvnnl
https://giphy.com/channel/396g5w
https://giphy.com/channel/53l6u3
https://giphy.com/channel/t0tudt
https://giphy.com/channel/hpv0nh
https://giphy.com/channel/yuvp7m
https://giphy.com/channel/37jtp3
https://giphy.com/channel/c73nk4
https://giphy.com/channel/fpung4
https://giphy.com/channel/8pf688
https://giphy.com/channel/82rtzs
https://giphy.com/channel/hxhwjp
https://giphy.com/channel/qcqc9p
https://giphy.com/channel/3xhgfw
https://giphy.com/channel/rujm2u
https://giphy.com/channel/egd2we
https://giphy.com/channel/3ye11o
https://giphy.com/channel/695728
https://giphy.com/channel/rrq5bx
https://giphy.com/channel/2938kq
https://giphy.com/channel/qi9ghf
https://giphy.com/channel/hy8vv5
https://giphy.com/channel/hta08j
https://giphy.com/channel/34ogtc
https://giphy.com/channel/izcr43
https://giphy.com/channel/9yohz7
https://giphy.com/channel/d51fxf
https://giphy.com/channel/tbkn2s
https://giphy.com/channel/byrxa5
https://giphy.com/channel/fsag6z
https://giphy.com/channel/yr8oxh
https://giphy.com/channel/oyjxbi
https://giphy.com/channel/988hj2
https://giphy.com/channel/jvvbms
https://giphy.com/channel/y4zkx9
https://giphy.com/channel/zcyr7i
https://giphy.com/channel/kx8i04
https://giphy.com/channel/0oft8k
https://giphy.com/channel/mamv1a
https://giphy.com/channel/wvefxv
https://giphy.com/channel/09n6yq
https://giphy.com/channel/lz57ut
https://giphy.com/channel/we0ctv
https://giphy.com/channel/117uqi
https://giphy.com/channel/88l5xn
https://giphy.com/channel/kv64s1
https://giphy.com/channel/x1xvx0
https://giphy.com/channel/ldl5bb
https://giphy.com/channel/20941o
https://giphy.com/channel/obx92z
https://giphy.com/channel/f61teo
https://giphy.com/channel/u28ut9
https://giphy.com/channel/dxf8wp
https://giphy.com/channel/bd4bji
https://giphy.com/channel/i413z9
https://giphy.com/channel/f70ncu
https://giphy.com/channel/xz2qzs
https://giphy.com/channel/iyiqz4
https://giphy.com/channel/r1zkc1
https://giphy.com/channel/hu7py0
https://giphy.com/channel/1bzqts
https://giphy.com/channel/vcc6uf
https://giphy.com/channel/t33ksk
https://giphy.com/channel/th2zj6
https://giphy.com/channel/6j9lis
https://giphy.com/channel/axaz3k
https://giphy.com/channel/u9d763
https://giphy.com/channel/a04br0
https://giphy.com/channel/izqluj
https://giphy.com/channel/89jpzi
https://giphy.com/channel/fb2s7b
https://giphy.com/channel/qviygg
https://giphy.com/channel/e0r8ry
https://giphy.com/channel/pyn174
https://giphy.com/channel/ze9vfi
https://giphy.com/channel/cbib6h
https://giphy.com/channel/5g2npw
https://giphy.com/channel/5plnv0
https://giphy.com/channel/r9c5j2
https://giphy.com/channel/dl4baz
https://giphy.com/channel/jq0ca0
https://giphy.com/channel/ecmued
https://giphy.com/channel/uxl0m6
https://giphy.com/channel/sj41s7
https://giphy.com/channel/sbrms4
https://giphy.com/channel/5qz7j5
https://giphy.com/channel/6sbkss
https://giphy.com/channel/po3d7d
https://giphy.com/channel/6lc77z
https://giphy.com/channel/w5qwv1
https://giphy.com/channel/dbfmbb
https://giphy.com/channel/ef88cv
https://giphy.com/channel/ouxe6k
https://giphy.com/channel/po9v26
https://giphy.com/channel/114pz0
https://giphy.com/channel/9v2og9
https://giphy.com/channel/kcub1m
https://giphy.com/channel/5loo0e
https://giphy.com/channel/zf7z9p
https://giphy.com/channel/q097f5
https://giphy.com/channel/zj8ysr
https://giphy.com/channel/mdckar
https://giphy.com/channel/5fz1hn
https://giphy.com/channel/fq13zy
https://giphy.com/channel/98vnt6
https://giphy.com/channel/4t073u
https://giphy.com/channel/snuemr
https://giphy.com/channel/syp838
https://giphy.com/channel/3evu8o
https://giphy.com/channel/50bb6j
https://giphy.com/channel/8508zl
https://giphy.com/channel/yo6hz3
https://giphy.com/channel/8sob7s
https://giphy.com/channel/0bv8xf
https://giphy.com/channel/y0jqtp
https://giphy.com/channel/bqgroy
https://giphy.com/channel/h4t0jr
https://giphy.com/channel/6xxpp1
https://giphy.com/channel/44ws2d
https://giphy.com/channel/r6azj6
https://giphy.com/channel/u5e4yd
https://giphy.com/channel/24ecc0
https://giphy.com/channel/cjr8st
https://giphy.com/channel/z2j419
https://giphy.com/channel/tilsek
https://giphy.com/channel/1i9iuy
https://giphy.com/channel/j0c7a4
https://giphy.com/channel/55umxx
https://giphy.com/channel/5kmebj
https://giphy.com/channel/9qmggw
https://giphy.com/channel/9d2qd0
https://giphy.com/channel/fqwhxn
https://giphy.com/channel/g4xd6l
https://giphy.com/channel/kmank2
https://giphy.com/channel/4t6sut
https://giphy.com/channel/r5966j
https://giphy.com/channel/33h4zi
https://giphy.com/channel/vms7jl
https://giphy.com/channel/g8z2gi
https://giphy.com/channel/cks3t9
https://giphy.com/channel/xnyqv8
https://giphy.com/channel/9efngn
https://giphy.com/channel/9icps4
https://giphy.com/channel/cbrj91
https://giphy.com/channel/1w4uco
https://giphy.com/channel/yr7czt
https://giphy.com/channel/j5632q
https://giphy.com/channel/slk1u9
https://giphy.com/channel/iw65ax
https://giphy.com/channel/jk7j61
https://giphy.com/channel/d2bt3i
https://giphy.com/channel/w94t5b
https://giphy.com/channel/y2md9f
https://giphy.com/channel/ay56y8
https://giphy.com/channel/qy9g6w
https://giphy.com/channel/qyvv6w
https://giphy.com/channel/kduk8u
https://giphy.com/channel/0x5hfx
https://giphy.com/channel/207gq9
https://giphy.com/channel/18vn3h
https://giphy.com/channel/rsb9bk
https://giphy.com/channel/73k7jt
https://giphy.com/channel/nox4lo
https://giphy.com/channel/vd7v8j
https://giphy.com/channel/0v9e0d
https://giphy.com/channel/ug03vd
https://giphy.com/channel/y62rp2
https://giphy.com/channel/3q0jj9
https://giphy.com/channel/ooe7gh
https://giphy.com/channel/as6rh7
https://giphy.com/channel/bkrj3s
https://giphy.com/channel/i1zj89
https://giphy.com/channel/l52j7n
https://giphy.com/channel/n4fo98
https://giphy.com/channel/fmqmwe
https://giphy.com/channel/07sofw
https://giphy.com/channel/dg4x7u
https://giphy.com/channel/vmlfen
https://giphy.com/channel/k0r1e7
https://giphy.com/channel/e84sl4
https://giphy.com/channel/0c4pic
https://giphy.com/channel/8ypq07
https://giphy.com/channel/1a46r6
https://giphy.com/channel/271zuh
https://giphy.com/channel/m1b3dm
https://giphy.com/channel/xnpw4n
https://giphy.com/channel/1im6m1
https://giphy.com/channel/40238i
https://giphy.com/channel/sqtyx7
https://giphy.com/channel/u7b7xc
https://giphy.com/channel/pz3eap
https://giphy.com/channel/xc53uk
https://giphy.com/channel/jfa751
https://giphy.com/channel/m44mk1
https://giphy.com/channel/q1rr76
https://giphy.com/channel/vmev3m
https://giphy.com/channel/4x4075
https://giphy.com/channel/6h6fjq
5.3 接口操作
1.找到http in和http response节点
IBM Node-RED安装与使用教程
2.编辑http in节点,输入接口路径url
IBM Node-RED安装与使用教程
3.将http in和http response整体连接
IBM Node-RED安装与使用教程
4.在部署之后在浏览器中运行
IBM Node-RED安装与使用教程
5.4 数据库操作
先提前创建数据表
IBM Node-RED安装与使用教程
1.拖出mysql组件并配置数据库信息
IBM Node-RED安装与使用教程
2.拖出function,编写select函数
IBM Node-RED安装与使用教程
代码段如下:
var selectTmp=“select data from NodeRED_source where name=’%s’”;
var newMsg = {
“topic”: util.format(selectTmp, msg.payload.name)
}
return newMsg;
3.连接并运行
IBM Node-RED安装与使用教程
IBM Node-RED安装与使用教程
5.5 数学公式操作
1.首先拖出计算节点
IBM Node-RED安装与使用教程
2.查看计算机点配置项
IBM Node-RED安装与使用教程
5.6 MQTT操作
1.查看当前mqtt主题有哪些
IBM Node-RED安装与使用教程
2.选取mqtt节点组件
IBM Node-RED安装与使用教程
其中mqtt in是订阅节点,mqtt out是发布节点
3.配置mqtt in节点,先选择服务器
IBM Node-RED安装与使用教程
然后配置服务器地址
IBM Node-RED安装与使用教程
http://www.5cocoi.com/muying/beiyun/2020-06-23/268618.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268616.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268615.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268613.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268611.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268608.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268605.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268604.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268603.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268602.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268600.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268599.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268598.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268593.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268591.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268587.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268585.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268584.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268583.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268579.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268568.html
http://www.5cocoi.com/muying/beiyun/2020-06-23/268566.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266688.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266629.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266622.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266620.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266618.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266616.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266613.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266609.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266608.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266604.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266602.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266596.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266593.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266590.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266588.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266586.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266583.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266581.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266578.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266576.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266573.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266572.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266569.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266567.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266566.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266561.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266557.html
http://www.5cocoi.com/muying/beiyun/2020-06-22/266555.html
4.配置主题
IBM Node-RED安装与使用教程
5.将mqtt out也同样配置
6.查看主题是否订阅成功
IBM Node-RED安装与使用教程
7,实现完整连线
IBM Node-RED安装与使用教程
8.部署运行
IBM Node-RED安装与使用教程
5.7 发邮件操作
1.找到邮件节点
IBM Node-RED安装与使用教程
2.配置邮件信息
IBM Node-RED安装与使用教程
3.连接
IBM Node-RED安装与使用教程
4.部署运行,查看邮件
IBM Node-RED安装与使用教程
5.8 可视化界面操作
1.查看dashboard区域
IBM Node-RED安装与使用教程
以上便是界面中的菜单,界面如下:
IBM Node-RED安装与使用教程
2.下面以创建自定义表单和绘制折线图为例,首先是创建表单,找到dashboard中的表单组件
IBM Node-RED安装与使用教程
填写表单信息+所属页面+调用主题
IBM Node-RED安装与使用教程
连接邮件
IBM Node-RED安装与使用教程
部署查看界面
IBM Node-RED安装与使用教程
由于表单太长,需要设置一下布局
一种是窗口设置
IBM Node-RED安装与使用教程
另一种是在布局layout中设置,推荐这一种
IBM Node-RED安装与使用教程
IBM Node-RED安装与使用教程
调整之后为:
IBM Node-RED安装与使用教程
输入信息并点击按钮,查看邮箱
IBM Node-RED安装与使用教程
3.折线图
找到随机数和折线图组件
IBM Node-RED安装与使用教程
配置折线图
IBM Node-RED安装与使用教程
配置输入节点的周期性,然后查看界面
IBM Node-RED安装与使用教程
IBM Node-RED安装与使用教程
6.Node-RED的不足分析
1、复杂的多功能物联网应用:纯拿Node-RED构建物联网应用,UI是瓶颈
2、基于流程的编程是一种并不总是最适合应用程序开发的编程模型:基于流程的编程是一个通用模型,不针对特定需求进行定位或优化,例如数据分析或交互界面开发
3、功能实现基础受限:Node-RED的基础技术是JavaScript,不能构建功能原型,常使用Node-RED进行整体控制
4、性能受限:极限数据操作性能不行