Serial Webserver
A NetBurner RTOS application that bridges serial communication with HTTP web services, allowing HTTP requests to be received and processed over a serial port connection.
Overview
The Serial Webserver demonstrates how to create a bidirectional communication bridge between a serial port and TCP/HTTP connections. This application enables HTTP requests to be sent over a serial connection and receive corresponding web responses back through the same serial interface.
It will receive and reply to HTTP requests over a serial port, using the NetBurner web server implementation. The example will display a Hello World message on the device's index page index.html
.
Key Features
- Serial-to-HTTP Bridge: Receives HTTP requests via serial port and forwards them to the built-in web server
- Bidirectional Communication: Splices data between serial and TCP connections in both directions
- Automatic Connection Management: Handles TCP connection creation and cleanup automatically
- Error Recovery: Automatically reopens serial connections on errors
- Built-in Web Server: Serves static content including HTML, CSS, and images
Technical Specifications
- Serial Port: Port 1 at 115200 baud
- HTTP Port: Standard port 80
- Buffer Size: Uses Ethernet buffer size for data transfer
- Network Stack: NetBurner RTOS with TCP/IP support
Application Architecture
The application follows a simple event-driven architecture:
- Initialization: Sets up network stack, enables diagnostics, and starts HTTP server
- Serial Monitoring: Waits for incoming serial data
- Connection Creation: Establishes TCP connection to local web server when data arrives
- Data Splicing: Uses
select()
to monitor both serial and TCP file descriptors
- Bidirectional Transfer: Forwards data between serial and TCP connections
- Error Handling: Closes and reopens connections on errors
HTTP Request Format
The application expects standard HTTP requests over the serial connection. A typical request format:
GET /INDEX.HTML HTTP/1.1\r\n\r\n
Important**: The web server requires a double carriage return line feed (\r\n\r\n
) to properly parse HTTP requests.
Expected Response
A successful request to the index page returns:
HTTP/1.0 200 OK
Pragma: no-cache
MIME-version: 1.0
Content-Type: text/html
Content-length: 231
<html>
<head><link rel="stylesheet" type="text/css" href="style.css"></head>
<body>
<a href="http://www.netburner.com"><img src="logo.jpg" width="200" border="0"></a>
<h1>Thank you for NetBurning!</h1>
</body>
</html>
Web Content
The application serves the following static files:
- index.html: Main page with NetBurner branding and welcome message
- style.css: Stylesheet defining Arial font family for the page
- logo.jpg: NetBurner logo image (referenced but not included in source)
Usage
- Flash the application to your NetBurner device
- Connect to the device's serial port (Port 1, 115200 baud)
- Send HTTP requests through the serial connection
- Receive HTTP responses back through the same serial connection
Development Notes
- System diagnostics are enabled for development (consider removing for production)
- The application uses blocking I/O operations
- Memory allocation uses
FAST_USER_VAR
for the splice buffer
Use Cases
This application is ideal for:
- Testing HTTP communication through serial interfaces
- Bridging legacy serial devices to modern web services
- Remote web server access through serial connections
Build Requirements
- NetBurner NBRTOS development environment
- Standard NetBurner libraries (init, system, iosys, serial, tcp, netinterface)
- Compatible NetBurner hardware platform