Serial Port Packets to network.


Can send received and sent packets to a server?

Yes! Finally SerialTool allow you to send serial com port traffic for a specific port directly to the network.
You can choose between these different methods:

  • TCP - SerialTool links devices via TCP/IP, securely transmitting serial port data to a server. It ensures reliable, ordered communication between SerialTool and server. It's like a phone call with acknowledgment.
    You can test these functionalities using a free cross-platform software called PacketSender to evaluate the TCP connection.
    Limited to 5 packets for FREE version.

  • UDP - SerialTool uses UDP to swiftly send serial data to a server without the complexities of TCP's handshake. Ideal for hyper-fast communication, it sacrifices some reliability for speed. It's like quick messages—convenient but less guaranteed.
    You can test these functionalities using a free cross-platform software called PacketSender to evaluate the UDP connection.
    Limited to 5 packets for FREE version.

  • HTTP/HTTPS POST - SerialTool offers the flexibility to utilize the HTTP/HTTPS POST method for transmitting data to a web server. This method mimics the act of submitting an online form, where data is encapsulated in the HTTP request and securely sent to the server. Whether it's sending sensor readings, user input, or any other form of data, SerialTool's HTTP/HTTPS POST feature streamlines the process. This approach enables seamless integration with various web-based applications, allowing data to be efficiently processed, stored, or acted upon by the server. By leveraging this method, SerialTool enhances its capabilities and connectivity, opening doors to a wide range of possibilities for real-time data interaction with web servers.
    A PHP code snippet is provided to test both POST and GET calls.
    Standard ports are 80 for HTTP and 443 for HTTPS.
    Supported on PRO version only.

  • HTTP/HTTPS GET - SerialTool facilitates data transmission to web servers using the HTTP GET method. Similar to typing a URL in a browser, SerialTool constructs an HTTP request with data parameters and appends them to the URL. When the request reaches the server, it processes the parameters and responds accordingly. This method is convenient for fetching information or triggering actions on the server side. By employing the HTTP GET method, SerialTool enables seamless integration with web-based systems, allowing for efficient data retrieval and interaction with remote servers. This functionality broadens the tool's capabilities, making it a versatile choice for various applications requiring web-based data exchange and interaction.
    A PHP code snippet is provided to test both POST and GET calls.
    Standard ports are 80 for HTTP and 443 for HTTPS.
    Supported on PRO version only.

PHP code snippet for HTTP/HTTPS POST and GET packet sending

HTTP/HTTPS GET usage from SerialTool

• Select "HTTP/HTTPS Get" as "Protocol"
• Set "https://yourwebsite.com/receive_test.php?value1=1" as "Server Address"
• Press [Send Test Packet] button

If the receive_test.php is loaded and functioning on your server, you should receive a message in the SerialTool message box stating:

#RES>OK - Written: XX bytes in received_packet.txt

HTTP/HTTPS POST usage from SerialTool

• Select "HTTP/HTTPS Post" as "Protocol"
• Set "https://yourwebsite.com/receive_test.php?myvalue=1" as "Server Address"
• Press [Send Test Packet] button

If the receive_test.php is loaded and functioning on your server, you should receive a message in the SerialTool "Connection Test" message box stating:

#RES>OK - Written: XX bytes in received_packet.txt

The result is a file called received_packet.txt located in the same folder where you loaded the PHP script and shoud look like this:

                    
                      @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
                      @   SerialTool received packets log file
                      @   Date: 2023-08-23
                      @   Time: 20:00:00
                      @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
                       Message received from IP [111.110.109.108] at 2023-08-23 20:00:00 [POST DATA 16 bytes] 0001020304050607
Message received from IP [111.110.109.108] at 2023-08-23 20:00:01 [GET DATA] Key: myvalue, Value: 1

PHP script
                        
<?php                          
/*
 ____________________________________________________________________________
║                                                                            ║
║  Application Name  : SerialTool                                            ║
║  Author            : SerialTool Dev Team                                   ║
║  IDE:              : php                                                   ║
║  File Generated    : 23/08/2023                                            ║
║                                                                            ║
╚════════════════════════════════════════════════════════════════════════════╝

 Usage: path/to/this/file/receive_test.php
 Logfile will be on the same directory with the name received_packet.txt

*/
   // Set your local time here
  date_default_timezone_set("Europe/Rome");

  // Prepare Header to HOST Incoming Data
  $MessagePayload = "";
  $MessagePayload .= " Message received from IP [" . $_SERVER['REMOTE_ADDR']. "] at " . date('Y-m-d H:i:s');

  // ----------------------------------------------
  // Receive the POST or GET data
  // ----------------------------------------------
  if ($_SERVER['REQUEST_METHOD'] === 'POST') {
      // The request method is POST
      $MessagePayload .= " [POST DATA ";
      $MessagePayload .= strlen(file_get_contents('php://input')) . " bytes] ";
      $MessagePayload .= file_get_contents('php://input') . PHP_EOL;;      
  } elseif ($_SERVER['REQUEST_METHOD'] === 'GET') {
      // The request method is GET      
      $MessagePayload .= " [GET DATA] ";      
      foreach ($_GET as $key => $value) {
          $MessagePayload .=  "Key: $key, Value: $value" . PHP_EOL;          
      }
  } else {
      // Handle other HTTP methods as needed
      $MessagePayload .= " [UNSUPPORTED HTTP METHOD] 
"; } // ---------------------------------------------- // Save Message to file // ---------------------------------------------- $LOG_Paypload = ""; $LogFilePath = "received_packet.txt"; if (file_exists($LogFilePath) === false){ // Put header $currentTimestamp = time(); $currentDate = date('Y-m-d', $currentTimestamp); // Format date as 'YYYY-MM-DD' $currentTime = date('H:i:s', $currentTimestamp); // Format time as 'HH:MM:SS' $LOG_Paypload .= "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" . PHP_EOL; $LOG_Paypload .= "@ SerialTool received packets log file" . PHP_EOL; $LOG_Paypload .= "@ Date: $currentDate" . PHP_EOL; $LOG_Paypload .= "@ Time: $currentTime" . PHP_EOL; $LOG_Paypload .= "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" . PHP_EOL ; } $logDay = date('d'); $logMonth = date('F'); $logYear = date('Y'); $logTime = date('H:i:s'); // Add Payload $LOG_Paypload .= $MessagePayload . PHP_EOL; $iResult = file_put_contents($LogFilePath, $LOG_Paypload, FILE_APPEND); if ($iResult === false){ echo "#RES>KO
"; } else{ echo "#RES>OK - Written: " . $iResult . " bytes in " . $LogFilePath . "
"; } ?>