According to WIKI, HTTP POST is a request method supported by HTTP used by the World Wide Web. By design, the POST requests that a web server accepts the data enclosed in the body of the request message, most likely for storing it. It is often used when uploading a file or when submitting a completed web form.
Two sites are needed to make a POST. One is the device that initiates the POST – HTTP client, and the other is the device that accepts the POST – HTTP server.
In this article, we describe how to upload a file from a TCW/TCG device that supports HTTP POST to an HTTP server based on TC Monitor.
Until the release of this article, the following Teracom devices support HTTP POST: TCW210-TH, TCW220, TCW241, TCW260, TCW280, TCG120, TCG120-4, TCG140, and TCG140-4. All devices can upload their status using status.xml or status.json files.
1. Install TC Monitor
The first step is to install our remote monitoring and control software – TC Monitor. How to do this is explained well in the user manual.
2. Port forwarding
To be able to connect to the PC with TC Monitor installed from the Internet, the router should have a public static IP address. An appropriate port forwarding should be also arranged.
If the TCW device and PC with TC Monitor installed are on the same local network, port forwarding is not necessary.
3. Create a folder for the file(s)
It is recommended to create a new, dedicated, folder for the file(s) which will be uploaded. The new folder should be a sub-folder of
C:\Program Files (x86)\Teracom\TCMonitor\Server\Apache24\htdocs\public\
For example, we will use the following structure with sub-folders:
C:\Program Files (x86)\Teracom\TCMonitor\Server\Apache24\htdocs\public\test\TCWnnn\xml
4. PHP file
The PHP file organizes acceptance and recording the coming information into a file on the disk of the PC with TC Monitor installed.
Below we give examples of PHP files. One of the rewrites the new information into the same file, while the other one (Postloop.php) writes a new file on every POST with a timestamp in the file name.
The second variant can be used for a raw archive of the device status
4.1. Single file variant – post.php
The file can be downloaded from here.
4.2. Multi-file variant – postloop.php
The file can be downloaded from here.
5. Copy PHP file
Save a code given in 4.1 or 4.2 as a file in the subfolder created in point 3.
6. Generate an URL for the post
The URL should be in the following format:
yourserverIP:8181/customFolders/postloop.php
Where:
- YourserverIP is the IP address of PC with TC Monitor installed in the variant where the PC and TCW device are in the same local network. For example 192.168.32.30
YourserverIP is the public static IP address of the router. For example 212.25.45.120 - 8181 is the port that is used from TC Monitor
- customFolders is the part of the path to the sub-folder created in point 3 but without the path to the main directory. From the example above: test/TCWnnn/xml
And the right path according to the above explanation will be: 192.168.32.30:8181/test/TCWnnn/xml/postloop.php
7. URL
You can check the URL generated in point 6 putting it in the address bar of a standard browser.
If all is correct the following message will be received:
8. Set the TCW device
The URL generated in point 6 should be placed as server address in section “HTTP POST setup”:
9. Check HTTP POST
Click on the button “Test HTTP Post”.
If the HTTP/HTTPS POST is received and processed, “OK” will be shown close to the button.
Along with this, an XML file will be created in the same directory, where postloop.php is located. The file name will contain time information and will look like 20210226183830_status.xml.