Hosting a WebSite on a Disposable Vape Author: Bogdan Ionescu Date: 2025-09-13 Reading time: 6 min (1267 words) Tags: programming, arm, tools, electronics --- Preface This article is a conceptual presentation; the actual web server running on a disposable vape can be seen here. Content is identical between the demo and this article. Background Bogdan has collected disposable vapes for years, originally salvaging batteries. Modern disposable vapes are more advanced, often including USB-C and rechargeable batteries. Discovery: some vapes use a PUYA-branded flash microcontroller, specifically ARM Cortex-M0+ based chips (PY32 series). Appreciation for the vape manufacturer for labeling debug pins, assisting with development. Microcontroller Specs Identified chip: PUYA C642F15, likely PY32F002B, not PY32F002A. Specs: 24 MHz Cortex-M0+ core 24 KiB Flash storage 3 KiB RAM Few peripherals (mostly unused) Despite seemingly limited specs, capable of hosting a "blazingly fast" webserver. Getting Online The idea came after exploring semihosting on ARM microcontrollers (syscalls via debugger breakpoints). Most USB serial devices emulate 56k modems and use SLIP (Serial Line Internet Protocol) for transmitting IP packets. Linux and macOS support SLIP via utilities like slattach. Setup pipeline: Use pyOCD to forward semihosting through a telnet port. Use socat to create a virtual TTY linked to this port. Use slattach on the virtual TTY for SLIP communication. Configure IP address on SLIP network interface. To talk TCP/IP, used the lightweight uIP stack: Does not require an RTOS. Small footprint and easy to port. Comes with a minimal HTTP server example. Challenges with uIP due to ARM memory alignment requirements were solved by tweaking filesystem structure and using Perl for adjustments. Performance: "Blazingly Fast" Initial tests were slow (~1.5s ping, 20+ sec page load) due to inefficient byte-by-byte serial read/write. Optimization: Added ring buffer using the 3KiB RAM to cache host reads. Batched writes with escaping. Result: Ping latency down to ~20ms, no packet loss. Full page load in ~160ms. Memory usage balance: Storage (~20 KiB left) is enough for hosting static pages like this blog post or small server-side C programs. Added JSON API endpoint providing: Number of requests since last crash. Unique microcontroller ID. Resources Code for this project on GitHub --- Footnotes The MCU is closely related to PY32C642, confirmed by another project: py32c642vape. SLIP is an older protocol; later modems used PPP (Point-to-Point Protocol). --- Summary:** Bogdan Ionescu demonstrates hosting a web server on the modest hardware inside a disposable vape, leveraging an ARM Cortex-M0+ microcontroller. Using semihosting and SLIP over a debugger connection turned into an IP network, combined with a tiny TCP/IP stack (uIP), he achieves surprisingly responsive web hosting despite extreme resource constraints (24 MHz CPU, 24 KB flash, 3 KB RAM). This creative project re-purposes electronic waste into a functional embedded web server and explores the potential of embedded semihosting and retro-modem protocols for networking.