What is Node-Red?

The picture on the cover is a description on the nodered.org/ website.

From the user’s point of view, it is a visual programming tool for accessing devices. From a technical point of view, it is an event-driven, low code programming rule engine based on NodeJS development.

What are its advantages?

  1. Fast. As fast as five minutes to plug into a device.
  2. Simple to use. Drag and drop the wires to choreograph the process.
  3. It takes effect in real-time. Once the process is edited, click the Deploy button and it takes effect immediately.
  4. Many built-in protocols. Support HTTP/HTTPS/TCP/MQTT/WEBSOCKET protocol.
  5. Support for extensions. If the built-in components are not sufficient, they can be downloaded from the component library. If not, custom development components are supported.

When do I recommend it?

I’ve been using this tool since ’19, when they launched six months ago. I’ve summarized only the most desirable scenarios for you to consider using. Let me know in the comments if you’ve used it in other scenarios, thanks!

  1. In the construction of smart city iot platform or application.

Why is it particularly useful when it comes to smart city iot platforms or applications?

The reason is that in the construction of iot platform in smart city, both of the two docking modes need platform adaptation, rather than access party adaptation. The two docking modes are respectively

  • The device interconnects with the platform.
  • Platform To platform.

Why is the Internet of things platform we build adapted to each other? There is only one reason, that is, we are late construction, we can not ask others to adapt to us, they want to change the platform code or even the device code, why change? That wasn’t part of the program that was paid for. It would be nice to be able to push the data over.

If you can’t change it, accept it. In this case, it is very important to efficiently access the data pushed from various devices or platforms and convert it to our standard protocols. By integrating Node-Red into the platform, you can quickly solve this problem.

At this time someone asked, can’t I develop a rules engine myself? B: Sure. But if you want to use it, node-Red is recommended.

Why is it possible to emulate HTTP or Websocket interfaces?

The reason is fast. It takes only three steps to simulate an interface. This is due to space reasons, the following two examples of this article can be explored.

So how do you use it?

Here are two examples to illustrate how to use it. The process is actually quite simple. You can see it.

  1. Example 1: Implement the number variable *10 to be entered and print a log.
  2. Example 2: A simulated street lamp device reports random brightness and prints a log of brightness exceeding 90%.

Implement the number variable *10 to be entered and print a log

Below is the effect drawing. Follow this article step by step operation can be achieved.

Deployment can be done in two ways

  • The local installation

Local installation can refer to the official website. I won’t go into that here. Docker installation is recommended. Nodered.org/docs/gettin…

  • Docker installation

Make sure your Docker is started in case. Open the terminal and enter the following command. Since I have a macbook, I can just open the terminal.

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

Copy the code

Command execution.

When you see the printed log shown above, it means you’ve already deployed Node-Red.

Local access

The default address is http://127.0.0.1:1880 and when you open it you can see the image below. Originally there was a comment box in English. But I’ve deleted it. Do not care about it, it does not affect.

Start the editing process

Follow the GIF operation below.

  1. Drag the Inject component in and change the triggered message to
{"number":10}
Copy the code
  1. Drag the Funciton component in and double-click to open and write the JS script
msg.payload.number=msg.payload.number*10
return msg
Copy the code
  1. Drag the Debug component in and change its name to Print logs.
  2. Wire components.
  3. Click the deploy button in the upper right corner.
  4. Click the small button in front of inject component to trigger.

So that’s my first example.

The analog street lamp device reports random brightness and prints a log of brightness over 90%

Follow the GIF operation below.

  1. Drag the Inject component in and write the key of the triggered packet paypay. brightness. Set the value type to an expression and fill in $random()*100. Represents the random generation of numbers up to 100.

  2. Pull the Switch component in and double-click on it to open it. Add the.

  3. Drag the Debug component in and change the name to Too Bright Log.

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

  5. After the deployment is successful, click the small button in front of inject component to trigger. Multiple times and wait until the number is greater than 60 to see the log printed on the right console.

This is done.

conclusion

In the project of iot platform or application in the field of smart city, it is recommended to use Node-Red for integration to solve the problem of fast access to multi-source heterogeneous devices.