IoT product vision: node-red you don't know

What is node-red?

The picture on the cover is an introduction on the official website nodered.org/ .

From the user's point of view, it is a tool dedicated to visual programming of access devices .
From a technical point of view, it is an event-driven low-code programming rule engine developed based on nodejs.

What are its advantages?

  1. quick. As fast as 5 minutes, you can connect to a device.
  2. Simple to use. Drag and drop the connection to complete the process arrangement.
  3. Effective in real time. After editing the process, click the deploy button, and it will take effect immediately.
  4. There are many built-in protocols. Support HTTP/HTTPS/TCP/MQTT/WEBSOCKET protocol.
  5. Extensions are supported. If the built-in components are not enough, you can download them from the component library. If it is not enough, you can support custom development components.

Under what circumstances do I recommend using it?

I've been using this tool since '19, when they released it half a year ago. I have summarized only the most needed scenarios, and you can consider using them. If you have used it in other scenarios, please let me know in the comment area, thank you!

  1. When building a smart city IoT platform or application.

Why is it particularly useful in a smart city IoT platform or application?

The reason is that when building an IoT platform in a smart city, both connection methods require platform adaptation, not the access party adaptation. The two connection methods are

  • Device docking platform.
  • Platform docking platform.

Why do the IoT platforms we build adapt to each other? There is only one reason, that is, we built it later, and there is no way to ask others to adapt to us . They want to change the code of the platform or even the code of the device. Why should they change it? The previous project gave money but did not include this item. It would be nice to be able to push the data.

If you can't change it, accept it. In this case, it is very important to efficiently access the data pushed by various devices or platforms and convert it into our standard protocol. At this time, if you integrate node-red into the platform, you can quickly solve this problem.

At this time, someone asked, can't I develop a rule engine by myself? of course. But if you want to use it right away, node-red is recommended.

为什么模拟http接口或websocket接口也用得到呢?

原因就是快。只需要三步就可以模拟一个接口。这个由于篇幅原因,下面看完本文的两个例子可以自己摸索一下。

那么怎么使用呢?

下面我们通过两个示例来讲解一下怎么使用。这个过程其实非常简单。你们一看就会。

  1. 例子1: 实现将输入的number变量*10并打印日志。
  2. 例子2: 模拟路灯设备上报随机亮度并将超过90%的亮度的打印日志。

实现将输入的number变量*10并打印日志

下面图是效果图。跟着本文一步步操作既可以实现。

image.png

部署可以有两种方式

  • 本地安装

本地安装可以参考一下官网。这里就不多说。推荐docker安装。 nodered.org/docs/gettin…

  • docker安装

确定你的docker是启动的情况下。打开终端,输入下面命令。由于我的是macbook,所以可以直接打开终端。

docker run -it -p 1880:1880 -v node_red_data:/data --name mynodered nodered/node-red

复制代码

命令执行。

image.png

image.png

当你看到打印上图显示的日志时就意味着你已经成本部署好node-red了。

本地访问

默认地址是 http://127.0.0.1:1880 打开之后你可以看到下面这个图。原本还有个英文的注释框。但是我已经删掉了。大家不要在意,不影响。

image.png

开始编辑流程

跟着下面的gif操作。

202203262251.gif

  1. 将inject组件拖进来,并将触发时的报文修改为
{"number":10}
复制代码
  1. 将funciton组件拖进来,并双击打开写下js脚本
msg.payload.number=msg.payload.number*10
return msg
复制代码
  1. 将debug组件拖进来,修改名称为打印日志。
  2. 将组件连线。
  3. 点击右上角部署按钮。
  4. 点击inject组件的前方的小按钮就能触发。

到这里就完成了第一个例子。

模拟路灯设备上报随机亮度并将超过90%的亮度的打印日志

跟着下面的gif操作。

Screen-2022-03-27-001745.gif

  1. 将inject组件拖进来,并将触发时的报文的key写入payload.brightness,value类型选择为表达式并填入$random()*100。表示随机生成100以内的数字。

  2. Drag the switch component in, and double-click to open it, it will be payloadadded later in the property .brightness, and the condition will be set to > 60.

  3. Drag the debug component in and change the name to High Brightness Log.

  4. Click the Deploy button in the upper right corner.

  5. After the deployment is successful, click the small button in front of the inject component to trigger. To click a few more times, wait until the number > 60 to see the log printed on the right console.

This is done.

Summarize

When in the project of IoT platform or application in the field of smart city, it is recommended to use node-redintegration to solve the problem of fast access to multi-source heterogeneous devices.

IoT Vision Logo.png

Guess you like

Origin juejin.im/post/7079449350534856711