Modbus POE ETH Relay HTTP

From Waveshare Wiki
Jump to: navigation, search

Hardware Connection

  • Connect the Modbus POE ETH Relay to the LAN via a network cable, and supply power through the power port or the POE.

900px-Modbus-POE-ETH-Relay-details-3.jpg

Note: The above figure is powered by a PoE Ethernet port. If it is an ordinary network cable, it must be powered by an external power adapter, which can be powered by an external power supply in the range of 7~36V.

Software Preparation

Download the configuration and web page file and unzip it. The file contains the configuration file as well as the web page file for the test.

HTTP GET Demo

The demo configures the module as a GET server, where web pages send data to the module via HTTP GET requests to control the relay.

Device Settings

  • Open Vircom software and select the corresponding device settings, set the corresponding IP address and gateway. The working module should be a TCP server, which also supports TCP server functionality.
  • The port here is set to 8000, be careful not to conflict with the web access port 80.

Modbus POE ETH Relay HTTP 1.png

  • Click "More Advanced Options" and select the function of "Do not empty the serial port when TCP is established". Avoid data loss.

Modbus POE ETH Relay HTTP 2.png
Click "OK" to return to the previous interface, and click "Modify Settings" to make the configuration take effect.

Firmware and Configuration

  • Create a new httpd.txt document in the web page directory. If you don't have a web directory, you can just create a blank folder, and it's okay to have only one httpd.txt folder.

Modbus POE ETH Relay HTTP 4.png

  • Add the following content to httpd.txt. It is recommended to download the configuration file directly and copy the HTTP ->get ->httpd.txt file. Manually adding it may cause errors.
  • The first line is network packet filtering, where NFL stands for not filter. This line means to convert the data after two carriage returns and line breaks into hexadecimal and output it to the main control chip through the serial port. "#" indicates data converted to hexadecimal output.
  • The second line is the status line of the HTTP response. The third to fourth lines represent the message header of the HTTP response. The fifth line is blank. The sixth line "$" represents the data returned by the serial port, which is the response body.

Modbus POE ETH Relay HTTP 5.png

  • Click "Firmware and Configuration", select the root directory of the configuration page, and click "Download" to download the configuration file to the device.

Modbus POE ETH Relay HTTP 3.png

  • All module configurations have been completed.

GET Demo

  • Enter the following URL in the browser to open and send an HTTP GET request. Note to replace the IP address and port with actual settings.
  • Under normal circumstances, relay 1 flips. You can replace hexadecimal data with other relay operation instructions for testing.
http://192.168.8.205:8000/?data=010500005500F29A
  • Open the HTTP ->get ->get. html file in the downloaded configuration file using Notepad. Find the following line of code, change the IP address and port to actual parameters, and save them.
const url = `http://192.168.8.205:8000/?data=${cmd[buttonNumber]}`;
  • Double-click on get.html file to open the web page. It is recommended to use Google Chrome, as other browsers may encounter errors.

Modbus POE ETH Relay HTTP 6.png

  • Click the corresponding relay button to send a GET request to control the corresponding relay flip. At the same time, the Respone window displays the returned data.

Principle Introduction

  • The following image shows the captured data of a complete GET request. The first line of the configuration file is the filter setting, and the useful data between the filters is sent via serial port to the main control chip.

The filter is set to convert only the data between "data=" and "HTTP/1.1" to hexadecimal and output it via serial port to the main control chip, i.e., modbus command. Modbus POE ETH Relay HTTP 7.png

  • The following image shows the captured data of a complete GET response. The first five lines are the second to sixth lines of the configuration file.
  • The seventh line is the data returned by the serial port, which is the original Modbus response in hexadecimal data.

Modbus POE ETH Relay HTTP 8.png

  • As can be seen from the above analysis, the principle of HTTP GET is to filter GET requests through the httpd.txt configuration file, and send useful data between them through the serial port.
  • At the same time, add response status to the data returned by the serial port through the configuration file, and package the information packet header into a complete HTTP response before returning it.

HTTP POST Demo

The demo configures the module as a POST server, where web pages send data to the module via HTTP POST requests to control the relay.

Device Settings

  • Open Vircom software and select the corresponding device settings, set the corresponding IP address and gateway. The working module should be a TCP server, which also supports TCP server functionality.
  • The port here is set to 8000, be careful not to conflict with the web access port 80.

Modbus POE ETH Relay HTTP 1.png

  • Click "More Advanced Options" and select the function of "Do not empty the serial port when TCP is established". Avoid data loss.

Modbus POE ETH Relay HTTP 2.png
Click "OK" to return to the previous interface, and click "Modify Settings" to make the configuration take effect.

Firmware and Configuration

  • Create a new httpd.txt document in the web page directory. If you don't have a web directory, you can just create a blank folder, and it's okay to have only one httpd.txt folder.

Modbus POE ETH Relay HTTP 4.png

  • Add the following content to httpd.txt. It is recommended to download the configuration file directly and copy the HTTP ->post ->httpd.txt file. Manually adding it may cause errors.
  • The first line is network packet filtering, where NFL stands for not filter. This line means to convert the data between "data=" and "HTTP/1.1" in GET request into hexadecimal and output it to the main control chip through the serial port. "#" indicates data converted to hexadecimal output.
  • The second line is the status line of the HTTP response. The third to fourth lines represent the message header of the HTTP response. The fifth line is blank. The sixth line "$" represents the data returned by the serial port, which is the response body.

Modbus POE ETH Relay HTTP 9.png

  • Click "Firmware and Configuration", select the root directory of the configuration page, and click "Download" to download the configuration file to the device.

Modbus POE ETH Relay HTTP 3.png

  • All module configurations have been completed.

POST Demo

  • Open the HTTP ->get ->get. html file in the downloaded configuration file using Notepad. Find the following line of code, change the IP address and port to actual parameters, and save them.
const url = `http://192.168.8.205:8000/`;
  • Double-click on post.html file to open the web page. It is recommended to use Google Chrome, as other browsers may encounter errors.

Modbus POE ETH Relay HTTP 10.png

  • Click the corresponding relay button to send a POST request to control the corresponding relay flip. At the same time, the Respone window displays the returned data.

Principle Introduction

  • The following image shows the captured data of a complete POST request. The first line of the configuration file is the filter setting, and the useful data between the filters is sent via serial port to the main control chip.
  • The filter is set to convert the data after two carriage returns and line breaks into hexadecimal format and output it to the main control chip through the serial port, which is the Modbus command after the blank line.

Modbus POE ETH Relay HTTP 11.png

  • The following image shows the captured data of a complete POST response. The first five lines are the second to sixth lines of the configuration file.
  • The seventh line is the data returned by the serial port, which is the original Modbus response in hexadecimal data.

Modbus POE ETH Relay HTTP 8.png

  • As can be seen from the above analysis, the principle of HTTP POST is to filter POST requests through the httpd.txt configuration file, and send useful data between them through the serial port.
  • At the same time, add response status to the data returned by the serial port through the configuration file, and package the information packet header into a complete HTTP response before returning it.

FAQ

 Answer:

Configuring and downloading other firmware has overwritten the configuration interface web file, and it needs to be re downloaded Configuration interface web file
You can add httpd.txt, which supports both web configuration and HTTP functions.
Web-config-tool.png


 Answer:

httpd.txt must be in Windows (CR LF) document format, i.e. each line ends with CR LF. Unix (LF) format files will encounter errors without output.
It is recommended to download the configuration file and copy it before modifying it.


 Answer:

The POST complete request must be in one data packet. If it is separated into multiple data packets, it may cause an error and no output.