During what one might have called my degenerate heyday, I got to the point in my nicotine addiction where I was rinsing through enough disposable vapes to make even the most hardened environmentalist queasy. So colour me thoroughly disappointed that I could have been turning all those horrible little plumage devices into websites once they'd ran out of juice.
Don't believe me? Just check out ewaste.fka.wtf. That website is hosted on the microcontroller from a disposable vape, and it's surprisingly snappy. Some disposable vapes come with a surprising amount of tech packed into them, including screens and microcontrollers.
As BogdanTheGeek, the person who made the vape-powered site, says: "I wouldn’t want to be the lawyer who one day will have to argue how a device with USB-C and a rechargeable battery can be classified as 'disposable'."
The horsepower of these little devices might not be much, but it's enough to host a bona fide website. And sure, we're getting a lot of 503 errors at the moment, but that's because a ton of people must be visiting the site right now after learning about it.
The text contents of the website explain how it was achieved, but you can find another styled-up copy on BogdanTheGeek's blog. The long story is pretty complicated, but the short and simplified version is that the vape's Arm microcontroller powers the site and an old IP encapsulation protocol over USB delivers the code and uses a virtual terminal to interface with an external computer to get the web server up and running.
Apparently, "almost all USB serial devices actually emulate [dial-up] modems", and you can use the Serial Line Internet Protocol (SLIP) on Linux to send and receive IP packets. They got this SLIP code to use semihosting, which is "basically syscalls for embedded ARM microcontrollers" that is bi-directional.
Once all this was set up and BogdanTheGeek had done a bit of file system modification with Perl, the website was up and running.
Initially it was slow, "A simple page took over 20 seconds to load. That’s so bad, it’s actually funny, and I kind of wanted to leave it there."
We might think that slowness is just because of the hardware itself. After some detective work, BogdanTheGeek found that the PUYA ASIC had 24 KiB of flash and 3 KiB of RAM: "The extra flash meant that it was more likely a PY32F002B." The Arm Cortex M0+ in this microcontroller runs at just 24 MHz.
In fact, it turned out that the reason it was slow isn't because of this but because "the first implementation read and wrote a single character at a time … it was serialising the data byte by byte."
But "we have a whopping 3kiB of RAM to play with, so I added a ring buffer to cache reads from the host and feed them into the SLIP poll function. I also split writes in batches to allow for escaping."
The result: "Pings now take 20 ms, no packet loss and a full page loads in about 160 ms. This was using almost all of the RAM, but I could also dial down the sizes of the buffer to have more than enough headroom to run other tasks."
It's certainly a better use for the dead devices than clogging up landfill. So get thinking folks, what tiny sites do you want to host? Oh, and don't vape!