Tool Example

Browser UART Viewer

Serve a small local browser page that tails the serial adapter and keeps demo logs readable.

Board LPCXpresso51U68 EVB OM40005
Status Verified

Run It

Use these commands from the COS workspace when the board and serial adapter are attached.

python3 -m pip install pyserialpython3 tools/uart_viewer.py --device <serial-device> --baud 9600visit http://127.0.0.1:8765

What To Look For

  • The tool opens from localhost.
  • Serial text streams without a terminal window.
  • Logs can be saved from the browser for documentation.
#!/usr/bin/env python3
import serial
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer

import os

PORT = os.environ["CLEVEROS_SERIAL"]
BAUD = 9600
BUFFER = []

class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        if self.path == "/stream":
            self.send_response(200)
            self.send_header("Content-Type", "text/plain; charset=utf-8")
            self.end_headers()
            self.wfile.write("\n".join(BUFFER[-200:]).encode("utf-8"))
            return

        self.send_response(200)
        self.send_header("Content-Type", "text/html; charset=utf-8")
        self.end_headers()
        self.wfile.write(b"<pre id='log'></pre><script>setInterval(async()=>{log.textContent=await fetch('/stream').then(r=>r.text())},500)</script>")

def read_serial():
    with serial.Serial(PORT, BAUD, timeout=1) as uart:
        while True:
            line = uart.readline().decode("utf-8", errors="replace").rstrip()
            if line:
                BUFFER.append(line)

# Production version in COS/tools/uart_viewer.py adds pause, clear, save-log, and status controls.