成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Process MQTT data with Node-RED

原創 精選
Techplur
This article will introduce the complete operation process for accessing the MQTT server by using Node-RED, filtering and processing the MQTT data before sending it to the ??MQTT broker??. Users may q

Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.

It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single click.

Besides some basic network service application nodes, such as HTTP and WebScoket, Node-RED provides access support to the ??MQTT?? protocol. Currently, it provides an MQTT subscription node and a release node. The subscription node is used for data input, while the release node can be used for data output.

This article will introduce the complete operation process for accessing the MQTT server by using Node-RED, filtering and processing the MQTT data before sending it to the ??MQTT broker??. Users may quickly understand how to use Node-RED for simple stream processing of MQTT data.


Install Node-RED

Node-RED, installed either on your PC, or devices such as Raspberry Pi, or cloud servers, can be quickly installed and used. Here are two common methods for installation:

Use ??npm?? for global installation:

npm install -g --unsafe-perm node-red

Use ??Docker?? for installation:

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


Run

If you use npm for global installation, and after you are prompted that the installation is successful, you can start the Node-RED immediately by simply running the node-red command globally.

Whether Docker or npm is used, after successful startup, we only need to open the browser and enter the current address plus 1880 port number to open the browser editor page of Node-RED. For example, if running locally, open the browser and enter ??http://127.0.0.1:1880??. When you see the page shown in the following figure, it means that Node-RED has been successfully started:

Node-RED


Use MQTT in Node-RED

This article will introduce the free public ??MQTT broker??? provided by EMQ, which is created on the basis of ??MQTT Cloud - EMQX Cloud??. the access information of the server is as follows:

In the following functional demonstration, we will provide a simple use case of using Node-RED to process the received JSON data containing temperature and humidity information, then make a rule judgment on the temperature value, and send the currently changed temperature value again through MQTT when the temperature changes.


Connect MQTT server

First, drag and drop a node of MQTT into the page in the menu bar on the left. After double-clicking the node, a configuration page for editing MQTT node will appear on the right, then create a new connection information according to the content prompts, fill in other connection information of MQTT, and click on the Done button to save the node information.

Node-RED MQTT in node


Process MQTT data

Data access: Drag and drop a JSON node into the page, and we can configure an Action in the configuration page of JSON node. Then we set it as Always Convert to Javascript Object. As we can't be sure whether the received data is a JSON format data or a JSON string, the first step is to perform JSON conversion on the received messages. After configuration, we connect this node with the MQTT in node.

Data filtering: after we configure and format the received message data, drag and drop a filter node into the page. After double-clicking the node, configure the rules in the configuration page. Select a Mode first and set it as a block unless value changes. The filtering rule is that the value of the currently received data needs to be changed. At present, the data is in JSON format, and what we should judge is a certain value in the JSON data, so we need to set the value as msg.payload.temperature in Property. After the configuration is completed, click the Done button to save the configuration of data filtering node, and finally connect the node with the JSON node after the previous configuration.

Using template: after filtering the data, drag and drop a template node into the page, and double-click the node to configure the template content, so that the filtered data can be output through the template. Of course, the filtered data can be directly output by skipping this step.

Node-RED template node


Publish the processed MQTT data

Finally, send the processed data by MQTT after the above data processing and filtering, drag and drop an MQTT out node into the page, fill in the same connection information as MQTT in node, configure a Topic for users to receive data, save it, then connect it with the template node, and click the Deploy button in the upper right corner to deploy the current rule application online.


Test

After finishing the function arrangement of the whole stream data processing, we use ??MQTT 5.0 client - MQTT X?? to test and validate the usability of this function. We create a new connection, connect it with the MQTT cloud service address previously configured in Node-RED, and then enter the Topic in the MQTT in node to send a message, so that Node-RED can receive the MQTT data we have sent.

Then we subscribe to a Topic configured in MQTT X node to receive the processed message data. When a message data containing temperature and humidity information is sent, we can receive a message sent according to the message template we set, but we can't receive it again if it is sent again.

As the temperature value has not changed at this time, and when we modify the temperature value again, we will find that we have received another message reminding us that the temperature value has changed.


Summary

Now we have completed the whole process for installing and connecting with MQTT cloud service by using Node-RED, and filtering and processing MQTT message data, and finally sending the processed data message.

The interaction and use of Node-RED, that is, using UI to describe general business logic, can lower the threshold for non-professional developers to get started. TO use a visual tool to quickly create the required complex execution tasks, users may build complex tasks through simple node connection, which is very helpful, especially for some IoT application scenarios.

Written by Shifan Yu from EMQ

責任編輯:龐桂玉 來源: 51CTO
相關推薦

2023-10-06 23:36:50

2022-02-16 09:01:33

編程工具Node-RED編輯器

2021-04-18 20:46:30

工具代碼編程

2022-01-10 09:44:06

鴻蒙HarmonyOS應用

2018-11-03 16:29:48

Red HatKDE桌面環境

2021-06-03 08:14:01

NodeProcessJavaScript

2009-02-27 17:16:12

LinuxRed Hat桌面

2018-08-17 06:13:16

物聯網協議MQTTMQTT-SN

2022-08-30 21:47:03

MQTT ProtoOthers

2023-07-27 15:04:10

Node.js核心API

2009-03-30 14:26:15

LinuxRed Hat收購

2012-06-29 09:30:14

Red HatPaaS 平臺

2009-02-18 10:20:50

Red HatSun市值

2011-03-15 16:12:45

iptablesRed Hat

2009-03-30 14:36:52

LinuxRed Hat桌面

2022-08-31 15:09:03

PythonOthers

2023-08-25 09:17:38

2022-09-26 11:30:40

MQTT協議客戶端協議

2020-12-07 12:47:22

MQTT鴻蒙hi3861

2020-11-18 11:36:35

鴻蒙系統
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 不卡一二区| 神马九九 | jvid精品资源在线观看 | h片在线免费观看 | 欧美一级网站 | 成人在线精品视频 | 午夜激情在线 | 精品国产一区二区在线 | 亚洲九色 | 成人一区二区电影 | 2020亚洲天堂 | 天天射天天干 | 精品国产一区二区三区久久 | 91免费福利视频 | 在线观看www高清视频 | 欧美色欧美亚洲另类七区 | 久久久国产亚洲精品 | 国产成人精品一区二区三区四区 | 中文字幕日韩欧美一区二区三区 | 国产一区二区视频免费在线观看 | 成人在线一区二区三区 | 国产日韩精品一区 | 成人免费视频在线观看 | 亚洲综合久久网 | 日韩免费福利视频 | 91精品国产综合久久久动漫日韩 | 国产精品久久久久久久久久久久 | 成人国产精品 | 久久免费观看一级毛片 | 精品国产aⅴ | 午夜精品一区二区三区三上悠亚 | 91影院| 97av在线| 国产视频一区二区 | 中国一级毛片免费 | 亚洲二区在线 | 色呦呦网站 | 国产一级电影网 | 亚洲国产黄色av | 国产激情一区二区三区 | 国产精品视频播放 |