Example Path: examples/Web/SerialWeb
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: Opens a TCP connection to the local web server on demand and closes it when the response completes, so each serial request is served on a fresh connection
- Error Recovery: Reopens the serial port on error, and drops the TCP connection if the peer closes or resets it
- 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
- Connection Teardown: Closes the TCP connection when the web server finishes its response (a read of 0 bytes) or on error, so it is ready to open a fresh connection for the next request
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: <length of the page>
<!DOCTYPE html>
<html lang="en">
<head>
...
<title>NetBurner Serial Web Example</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- The branded Serial Web example page: header, an overview of the
serial<->HTTP bridge, a welcome card, and the footer. -->
</body>
</html>
Web Content
The application serves the following static files:
- index.html: Branded example page (header, an overview of the serial<->HTTP bridge, a welcome card, and footer)
- style.css: NetBurner Design System stylesheet
- logo.png: NetBurner logo (white-knockout wordmark sized for the dark header)
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