Difference between revisions of "Modbus and Bluetooth data sending to Node-RED"
Justas.Cip (talk | contribs) |
Justas.Cip (talk | contribs) |
||
(76 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
<span style="color: red;">The information in this page is updated in accordance with the <span style="color: #0054A6;"><b>RUTXXX_R_00_07_03</b></span> firmware version.</span> | <span style="color: red;">The information in this page is updated in accordance with the <span style="color: #0054A6;"><b>RUTXXX_R_00_07_03</b></span> firmware version.</span> | ||
− | Node-RED is a flow-based programming tool developed by IBM Emerging Technology and written in Node.js. It provides a browser-based editor for wiring together hardware devices, APIs, and online services using a visual programming interface | + | Node-RED is a flow-based programming tool developed by IBM Emerging Technology and written in Node.js. It provides a browser-based editor for wiring together hardware devices, APIs, and online services using a visual programming interface. |
This article provides an extensive configuration example with details on how to use Node-RED with Teltonika Routers via MQTT and HTTP protocols. | This article provides an extensive configuration example with details on how to use Node-RED with Teltonika Routers via MQTT and HTTP protocols. | ||
Line 16: | Line 16: | ||
*Linux Virtual Machine to host Node-RED server. | *Linux Virtual Machine to host Node-RED server. | ||
----- | ----- | ||
− | There are a couple of different use cases with Node-RED and Teltonika devices | + | There are a couple of different use cases with Node-RED and Teltonika devices and here are the connection topologies for these use cases. |
− | + | Topology 1 – MQTT gateway using either Node-RED or Teltonika device as MQTT broker. | |
− | + | ||
− | + | Topology 2 – Modbus data to server using either Node-RED or Teltonika device as MQTT broker. | |
− | + | ||
+ | Topology 3 – Bluetooth data to server using Teltonika device as MQTT broker. | ||
+ | |||
+ | Topology 4 – HTTP data to Node-RED server. | ||
==Node-RED installation and setup== | ==Node-RED installation and setup== | ||
Line 42: | Line 45: | ||
[[File:Server is running node red terminal.png|border|600px|class=tlt-border]] | [[File:Server is running node red terminal.png|border|600px|class=tlt-border]] | ||
---- | ---- | ||
− | Once you have the local server running, use the local IP and port number in your internet browser. In this case, we are using | + | Once you have the local server running, use the local IP and port number in your internet browser. In this case, we are using 127.0.0.1:1880: |
[[File:Use server address in web browser.png|border|500px|class=tlt-border]] | [[File:Use server address in web browser.png|border|500px|class=tlt-border]] | ||
Line 52: | Line 55: | ||
==MQTT Gateway== | ==MQTT Gateway== | ||
− | |||
− | |||
− | |||
===Using Teltonika device as an MQTT broker=== | ===Using Teltonika device as an MQTT broker=== | ||
---- | ---- | ||
− | |||
− | |||
− | |||
− | |||
− | |||
Router setup when using the router as a broker consists of two parts. First, we are going to set up a local broker. In order to do so, navigate to '''Services -> MQTT -> Broker''' and enable the broker. | Router setup when using the router as a broker consists of two parts. First, we are going to set up a local broker. In order to do so, navigate to '''Services -> MQTT -> Broker''' and enable the broker. | ||
Line 67: | Line 62: | ||
Once done, navigate to '''Services -> Modbus -> MQTT Gateway'''. Follow these steps for the configuration: | Once done, navigate to '''Services -> Modbus -> MQTT Gateway'''. Follow these steps for the configuration: | ||
− | + | *Enable the instance | |
− | + | *Host: since we are using a local broker on the router – input 127.0.0.1 | |
− | + | *Leave everything else as default, or adjust according to your needs | |
− | Leave everything else as default, or adjust according to your needs | ||
[[File:MQTT gateway settings node red local router.png|border|500px|class=tlt-border]] | [[File:MQTT gateway settings node red local router.png|border|500px|class=tlt-border]] | ||
Line 86: | Line 80: | ||
In the next screen configure settings accordingly: | In the next screen configure settings accordingly: | ||
− | + | *Name: RUT_broker for this example | |
− | + | *Server: 192.168.10.1 (Router's LAN IP address) | |
− | + | *Port: Default port 1883 | |
− | + | *Leave everything else as default or adjust to your needs | |
[[File:Mqtt broker on our router settings.png|border|500px|class=tlt-border]] | [[File:Mqtt broker on our router settings.png|border|500px|class=tlt-border]] | ||
---- | ---- | ||
Now we are going to go back to MQTT-out node configuration and adjust settings as shown below: | Now we are going to go back to MQTT-out node configuration and adjust settings as shown below: | ||
− | + | *Server: RUT_broker | |
− | + | *Topic: request | |
− | |||
− | |||
[[File:Mqtt out request node red.png|border|500px|class=tlt-border]] | [[File:Mqtt out request node red.png|border|500px|class=tlt-border]] | ||
Line 103: | Line 95: | ||
---- | ---- | ||
− | '''MQTT-in node''' - configure settings as shown below: | + | *'''MQTT-in node''' - configure settings as shown below: |
− | + | *Server: RUT_broker | |
− | + | *Action: Subscribe to single topic | |
− | + | *Topic: response | |
− | + | *QoS: 0 | |
− | + | *Output: auto-detect | |
− | |||
[[File:Mqtt in response node red.png|border|500px|class=tlt-border]] | [[File:Mqtt in response node red.png|border|500px|class=tlt-border]] | ||
Line 124: | Line 115: | ||
There is no need to configure '''debug''' node. Here is how the finished flowchart should look like: | There is no need to configure '''debug''' node. Here is how the finished flowchart should look like: | ||
− | [[File:Flowchart nodered local broker on router.png|border| | + | [[File:Flowchart nodered local broker on router.png|border|500px|class=tlt-border]] |
---- | ---- | ||
Line 140: | Line 131: | ||
===Using Node-RED as an MQTT broker=== | ===Using Node-RED as an MQTT broker=== | ||
---- | ---- | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
====Adjusting Node-RED configuration==== | ====Adjusting Node-RED configuration==== | ||
− | If you would like to use Node-RED as a broker, there are a couple of changes needed to be made. Similarly as shown before, | + | If you would like to use Node-RED as a broker, there are a couple of changes needed to be made. Similarly as shown before, we are going to need to set up local broker like this: |
[[File:Local broker settings nodered.png|border|500px|class=tlt-border]] | [[File:Local broker settings nodered.png|border|500px|class=tlt-border]] | ||
Line 161: | Line 145: | ||
Navigate to '''Services -> Modbus -> MQTT Gateway'''. Change the host IP to your Linux Virtual Machine IP address (192.168.10.139 in this example): | Navigate to '''Services -> Modbus -> MQTT Gateway'''. Change the host IP to your Linux Virtual Machine IP address (192.168.10.139 in this example): | ||
− | [[File:Using local node red broker just change the IP address of broker.png|border| | + | [[File:Using local node red broker just change the IP address of broker.png|border|400px|class=tlt-border]] |
To test the configuration, '''deploy''' the nodes again and send the message by clicking on the '''inject''' node. | To test the configuration, '''deploy''' the nodes again and send the message by clicking on the '''inject''' node. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Modbus Data to Server via MQTT protocol== | ==Modbus Data to Server via MQTT protocol== | ||
In this section, we are going to upload Modbus data to server on Node-RED. First of all, we are going to need Modbus data source, in this example we are using the same device as Modbus TCP Slave and Master. | In this section, we are going to upload Modbus data to server on Node-RED. First of all, we are going to need Modbus data source, in this example we are using the same device as Modbus TCP Slave and Master. | ||
− | |||
− | |||
− | |||
− | |||
===Device configuration=== | ===Device configuration=== | ||
Line 211: | Line 157: | ||
To start with, navigate to '''Services -> Modbus -> Modbus TCP slave'''. Press '''enable''' to enable the instance and you can leave everything else as '''default''': | To start with, navigate to '''Services -> Modbus -> Modbus TCP slave'''. Press '''enable''' to enable the instance and you can leave everything else as '''default''': | ||
− | [[File: | + | [[File:Networking rutos manual modbus modbus tcp slave v2.png|border|800px|class=tlt-border]] |
Next, navigate to '''Services -> Modbus -> Modbus TCP master'''. Adjust settings here accordingly: | Next, navigate to '''Services -> Modbus -> Modbus TCP master'''. Adjust settings here accordingly: | ||
− | + | *Enabled: on | |
− | + | *Name: Local_slave (input any preferred name) | |
− | + | *Slave ID: 1 | |
− | + | *IP address: 127.0.0.1 (since we are using local TCP slave - input the IP address if you are using external device as Modbus Slave) | |
− | + | *Port: 502 | |
− | |||
− | |||
Add new request and adjust settings according to your needs. For this example, we are going to pull device name from the registers, so our configuration looks like this: | Add new request and adjust settings according to your needs. For this example, we are going to pull device name from the registers, so our configuration looks like this: | ||
− | + | *Name: test (input any preferred name) | |
− | + | *Data type: ASCII (to get a string of text) | |
− | + | *Function: Read holding registers (3) | |
− | + | *First register number: 72 | |
− | + | *Register count/values: 3 | |
− | + | *Brackets: use brackets | |
− | + | *Press enable to enable the Modbus request | |
− | Press enable to enable the Modbus request | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | [ | + | [[File:Tcp master nodered.png|border|1000px|class=tlt-border]] |
Revision as of 09:45, 13 January 2023
Introduction
The information in this page is updated in accordance with the RUTXXX_R_00_07_03 firmware version.
Node-RED is a flow-based programming tool developed by IBM Emerging Technology and written in Node.js. It provides a browser-based editor for wiring together hardware devices, APIs, and online services using a visual programming interface.
This article provides an extensive configuration example with details on how to use Node-RED with Teltonika Routers via MQTT and HTTP protocols.
Configuration overview and prerequisites
Before we begin, let's overview the configuration that we are attempting to achieve and the prerequisites that make it possible.
Prerequisites:
- Teltonika RUTXXX router or TRBXXX gateway. We are going to use the RUTX11 in this example.
- At least one end device (PC, Laptop, Tablet, Smartphone) to configure the devices.
- Linux Virtual Machine to host Node-RED server.
There are a couple of different use cases with Node-RED and Teltonika devices and here are the connection topologies for these use cases.
Topology 1 – MQTT gateway using either Node-RED or Teltonika device as MQTT broker.
Topology 2 – Modbus data to server using either Node-RED or Teltonika device as MQTT broker.
Topology 3 – Bluetooth data to server using Teltonika device as MQTT broker.
Topology 4 – HTTP data to Node-RED server.
Node-RED installation and setup
We are going to set up Node-RED in Linux virtual machine. For Node-RED to work, you would need to install Node.js version 14.00 or higher, if you already have Node.js installed, verify Node.js version using this command:
node -v
If you do not have Node.js installed, run these commands to install it:
sudo apt install curl curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash – sudo apt-get install -y nodejs
Once we have Node.js installed, we can install Node-RED. Use this command to install:
sudo npm install -g –unsafe-perm node-red
Use the command node-red to start a local server. Here is how the terminal should look like if the server starts correctly:
Once you have the local server running, use the local IP and port number in your internet browser. In this case, we are using 127.0.0.1:1880:
For MQTT usage, we are going to need MQTT-specific nodes. Use the side menu to navigate to Manage Palette section and install these nodes:
- node-red-contrib-aedes
- node-red-contrib-mqtt-broker
MQTT Gateway
Using Teltonika device as an MQTT broker
Router setup when using the router as a broker consists of two parts. First, we are going to set up a local broker. In order to do so, navigate to Services -> MQTT -> Broker and enable the broker.
Once done, navigate to Services -> Modbus -> MQTT Gateway. Follow these steps for the configuration:
- Enable the instance
- Host: since we are using a local broker on the router – input 127.0.0.1
- Leave everything else as default, or adjust according to your needs
Node-RED setup when using Teltonika device as an MQTT broker
For this example, we are going to need MQTT-in and MQTT-out nodes. We are not going to need a broker node for now, since we are using our router as an MQTT broker. In order to send request and get response messages, we are also going to need inject and debug nodes. Drag required nodes onto the screen and click on them to configure accordingly:
- MQTT-out node - click on this node and then click on the pencil icon to configure Node-RED for Teltonika broker usage.
In the next screen configure settings accordingly:
- Name: RUT_broker for this example
- Server: 192.168.10.1 (Router's LAN IP address)
- Port: Default port 1883
- Leave everything else as default or adjust to your needs
Now we are going to go back to MQTT-out node configuration and adjust settings as shown below:
- Server: RUT_broker
- Topic: request
- MQTT-in node - configure settings as shown below:
- Server: RUT_broker
- Action: Subscribe to single topic
- Topic: response
- QoS: 0
- Output: auto-detect
- Inject node - here we only need to input a payload. To find required message format, refer to this article: Modbus TCP Master MQTT Gateway
For this example, we will try to get router's temperature, so we are going to use payload in this format: 0 65432 0 192.168.10.1 502 5 1 3 6 2
There is no need to configure debug node. Here is how the finished flowchart should look like:
In order to test the configuration, press Deploy in the top right corner:
Now press on Inject node and look for incoming message on the right side of the screen:
Here we can see that the router's temperature is 38.0 degrees.
Using Node-RED as an MQTT broker
Adjusting Node-RED configuration
If you would like to use Node-RED as a broker, there are a couple of changes needed to be made. Similarly as shown before, we are going to need to set up local broker like this:
In order for the broker to be available, add broker node to the flowchart. Now the flowchart should look like this:
Adjusting Teltonika device configuration
Navigate to Services -> Modbus -> MQTT Gateway. Change the host IP to your Linux Virtual Machine IP address (192.168.10.139 in this example):
To test the configuration, deploy the nodes again and send the message by clicking on the inject node.
Modbus Data to Server via MQTT protocol
In this section, we are going to upload Modbus data to server on Node-RED. First of all, we are going to need Modbus data source, in this example we are using the same device as Modbus TCP Slave and Master.
Device configuration
To start with, navigate to Services -> Modbus -> Modbus TCP slave. Press enable to enable the instance and you can leave everything else as default:
Next, navigate to Services -> Modbus -> Modbus TCP master. Adjust settings here accordingly:
- Enabled: on
- Name: Local_slave (input any preferred name)
- Slave ID: 1
- IP address: 127.0.0.1 (since we are using local TCP slave - input the IP address if you are using external device as Modbus Slave)
- Port: 502
Add new request and adjust settings according to your needs. For this example, we are going to pull device name from the registers, so our configuration looks like this:
- Name: test (input any preferred name)
- Data type: ASCII (to get a string of text)
- Function: Read holding registers (3)
- First register number: 72
- Register count/values: 3
- Brackets: use brackets
- Press enable to enable the Modbus request