<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://foothillsbuilds.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://foothillsbuilds.com/" rel="alternate" type="text/html" /><updated>2026-11-29T20:32:01-06:00</updated><id>https://foothillsbuilds.com/feed.xml</id><title type="html">Foothills Builds</title><subtitle>Builds, life, and adventure in the Rocky Mountain Foothills. ESP32 firmware, electronics, woodwork and homestead projects, written up as I go.</subtitle><author><name>Foothills Builds</name></author><entry><title type="html">My robot vacuum runs Linux. Here is how I got in.</title><link href="https://foothillsbuilds.com/blog/my-robot-vacuum-runs-linux/" rel="alternate" type="text/html" title="My robot vacuum runs Linux. Here is how I got in." /><published>2026-11-16T00:00:00-06:00</published><updated>2026-11-29T19:06:15-06:00</updated><id>https://foothillsbuilds.com/blog/my-robot-vacuum-runs-linux</id><content type="html" xml:base="https://foothillsbuilds.com/blog/my-robot-vacuum-runs-linux/"><![CDATA[<h1 id="my-robot-vacuum-runs-linux-here-is-how-i-got-in">My robot vacuum runs Linux. Here is how I got in.</h1>

<p>In <a href="/blog/robot-vacuum-without-the-cloud/">the first post</a> I talked about my robot vacuum that lives off the cloud and promised to come back and explain how I got in. The short version is almost boring: the robot runs Linux, basically a little single board computer with wheels and a dustbin, and once I got access to it I handed myself the keys to even more.</p>

<p>Once you know there is a whole Linux machine under the lid, cleaning your floors with a camera and a map of your home, it is hard not to want to see what it is actually doing in there. So I opened it up. What follows is how I went from a sealed appliance to a root shell, and what that taught me about how much the thing trusts the world around it.</p>

<h2 id="the-service-port">The service port</h2>

<p>Let’s start with the boring door. The one I used on purpose.</p>

<p>Almost every circuit board that leaves a factory has a service port. The factory needs a way to load the first software and check the thing boots before it goes in a box. Connect to it and you can watch the robot start up, and on a lot of boards talk to it while it runs. Nothing secret about the idea. Routers, smart plugs and most other gadgets have one too.</p>

<p>On the X10 there is no plug sitting ready. On the outside, under a taped-over flap next to the Reset and Wi-Fi buttons, there is a micro USB port. And behind a small window, hidden under some plastic, sits the board’s own debug port, bare pads with no connector fitted. That debug port is a serial console, a plain text window into the robot, and once I had wires on it, it was my way in. Finding it took a while. There is another port on the board with a connector already fitted, the obvious one, and I wasted time on that first. The right one I only pinned down with an oscilloscope on the pads and a bit of AI help translating the Chinese labels, and then I had to solder my own wires straight onto it. It still looked dead at first, until it turned out it just wanted one specific word before it would listen.</p>

<p><img src="/assets/img/robot-vacuum/service-area-micro-usb.jpg" alt="The micro USB port next to the Reset and Wi-Fi buttons, under a peeled-back tape flap" class="shot" /></p>

<p>A few things before you think about opening yours. The warranty is gone the moment you do. Photograph every cable before you unplug anything. And this is not a clip-off-the-cover job - the debug port ships unsoldered, so there is some soldering involved, not just a screwdriver.</p>

<p><img src="/assets/img/robot-vacuum/debug-port-wired.jpg" alt="The debug port on the board, wired up with two jumper wires to a serial adapter" class="shot" /></p>

<p>Here is the part that made the rest possible. The boot check is real, and then it stops. The bootloader and the kernel are verified. The rest of the system, the part that actually runs the robot, is not. So the robot can have a proper signature check and still be wide open once you are past that gate. That gap is the whole reason a change I write to its storage survives a reboot.</p>

<h2 id="getting-root">Getting root</h2>

<p>Remember the port that looked dead. It was not dead. It was waiting for one word.</p>

<p>For a few evenings I had it wired up and it just echoed what I typed and ignored every command. The thing it wanted turned out to be three letters: <code class="language-plaintext highlighter-rouge">fiq</code>. Type that into the console and it flips into <a href="https://github.com/rockchip-linux/kernel/blob/develop-5.10/drivers/soc/rockchip/fiq_debugger/fiq_debugger.c">Rockchip’s fiq_debugger</a>, a debug mode built into the chip family these robots use. Not really a secret, a documented feature, meant for debugging, and it hands you kernel-level access over the serial port. From dead port to inside the robot, just 3 bytes.</p>

<p>A debugger still is not a shell. It lets you poke at a running system, but not log into it. For that I needed its storage, and the robot handed that over just as easily. Its brain sits on an eMMC chip, basically a soldered-down SD card, and the bootloader has a mode called UMS, USB mass storage. One command, <code class="language-plaintext highlighter-rouge">reset ums</code>, and the robot offered its whole 7 GB to me over that micro USB, like a dumb thumb drive. The entire filesystem, with read and write access.</p>

<p>Before I changed anything I took a backup of the whole chip. That image is my insurance if I start breaking things. If anything bricks the robot, I write the backup back over the same USB connection and it boots as if nothing happened.</p>

<p>Then the way we got a door that survives every reboot. The running system is never checked, so the robot boots a changed version without issue. With the storage sitting there over USB, you can mount the system partition read-write and change files straight on the robot. I switched on a login that ships disabled, one commented-out line in its startup config, set a root password, unmounted, and powered it off and on again.</p>

<p>This time the console met me with a login prompt, and the password was mine. Root. <code class="language-plaintext highlighter-rouge">uid=0</code>, the account that can do anything on a Linux box. On my vacuum.</p>

<p>One shell on the serial wire is nice, but it means staying soldered to the board. So the last move was a way in over the network. I put a quick cross-compiled <code class="language-plaintext highlighter-rouge">dropbear</code> SSH server on <code class="language-plaintext highlighter-rouge">/userdata</code>, the one partition the robot carries across a firmware update. A reboot does not clear it, and neither does one of eufy’s own updates. From then on I had a root shell over Wi-Fi, the wires came off, and the robot went back together like nothing happened.</p>

<p>A quick warning if you plan to do this on your own bot. These steps are specific to this model and this firmware. Offsets and layout may shift between versions, and one bad write to the wrong partition turns a working vacuum into a piece of expensive electronic waste with no undo. So whatever you plan to do, do yourself a favor and take a backup first.</p>

<h2 id="making-it-mine">Making it mine</h2>

<p>Root was never the point. It was the key. The thing I actually wanted is the one from the first post: a vacuum that cleans the place without reporting home, and keeps the map of my home at home. Getting root is what made that possible, so that story ran first and this one, how I got there, second.</p>

<p>The first thing root buys you is sight. The robot runs two buses of its own - one streaming over 500 channels of telemetry, the other carrying the commands that actually move it - and both only listen on the robot, never on the network. That is the real reason root came first. From a shell on the box I could finally watch it think, every topic live, with its own tools. The cloud out there only ever saw a small fraction of those channels. I could see all of them, and better, I could join in and manipulate them.</p>

<p>Once I could speak the robot’s own language, cutting out the manufacturer’s cloud was the obvious next step. I pointed its connection at my MQTT broker and gave it the answers it was waiting for. The robot never noticed the difference. That is where <a href="https://github.com/dhumpf/x10-ctl">the little program from the first post</a> comes from: the robot’s own map and controls, served on my network, with nothing phoning home.</p>

<p>That is also when I realised the debug port had been the hard way in. Once the robot was on my broker, I realised I did not need any of it. The robot trusts whatever cloud it is paired with, nearly all the way. It basically opens a root console to whichever broker it is paired to.</p>

<p>But it is worth sitting with what that means. The robot’s safety leans on one assumption: that nobody else ever gets to be the cloud it talks to. I asked eufy back in August, and never got a reply on whether that is intended or a bug they will eventually fix.</p>]]></content><author><name>Foothills Builds</name></author><summary type="html"><![CDATA[How I got a root shell on my robot vacuum through its debug port, why its boot check does not stop you, and the one other way in once it trusts your broker.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://foothillsbuilds.com/assets/img/robot-vacuum/debug-port-wired.jpg" /><media:content medium="image" url="https://foothillsbuilds.com/assets/img/robot-vacuum/debug-port-wired.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">My robot vacuum cleans without the cloud now</title><link href="https://foothillsbuilds.com/blog/robot-vacuum-without-the-cloud/" rel="alternate" type="text/html" title="My robot vacuum cleans without the cloud now" /><published>2026-11-06T00:00:00-06:00</published><updated>2026-11-29T19:06:15-06:00</updated><id>https://foothillsbuilds.com/blog/robot-vacuum-without-the-cloud</id><content type="html" xml:base="https://foothillsbuilds.com/blog/robot-vacuum-without-the-cloud/"><![CDATA[<h1 id="my-robot-vacuum-cleans-without-the-cloud-now">My robot vacuum cleans without the cloud now</h1>

<p>I bought a robot vacuum (<a href="https://web.archive.org/web/20211027075416/https://www.dhumpf.de/?p=66">again…</a>). The new one is a bit more modern. It cleans well, maps every room and wall in my home, and talks to a server I don’t control, with no button anywhere that says “stop doing that”. This is, yet again, the story of keeping the robot and cutting the cloud.</p>

<p>I did it once again, and it actually works. The robot runs entirely on my own network now, cleans exactly as before, and has no way to reach the vendor. The map and the app live on the robot itself, on my network, not on anyone’s cloud. The code I wrote to control it is linked at the end.</p>

<h2 id="why-bother">Why bother</h2>

<p>Three reasons.</p>

<p>Privacy. The robot knows the layout of the apartment or house it cleans. It also has a camera, and could possibly send pictures anywhere it reaches on the internet. I would like that to stay at home.</p>

<p>The cloud can disappear. If the company shuts the server down, a lot of smart devices simply stop, even though the hardware is fine. I do not want a vacuum with an expiry date set by someone else.</p>

<p>Control. I want my home automation to talk to the vacuum directly, on the LAN, without an app account or anything else as the man in the middle.</p>

<h2 id="what-it-was-sending-home">What it was sending home</h2>

<p>Before I touched anything, I watched what the robot talked to for about a week on a separate network. Just a router and DNS logs: which names it looked up, which addresses it hit, how often. A couple of short packet captures on top. I looked at the outside, the envelope, not what was inside.</p>

<p>You do not need to crack open the device for this. You watch the door, what is going in (and out), not the house. The traffic is encrypted, which cuts both ways: nobody in between can read it, and neither can I. I see who it talks to, when, and how much. Unfortunately not what.</p>

<p>In that week it reached a handful of servers, the real surprise was where. Anker is the parent brand, so I expected Asia. But almost all of it stayed in North America, on Amazon’s AWS cloud in the US: the data, the login and cleaning API, the updates, even the always-on message broker.</p>

<p>That broker is <code class="language-plaintext highlighter-rouge">aiot-mqtt-us.anker.com</code>. The robot holds it open and keeps talking even while parked on the dock doing nothing. It is the first thing to go quiet once the robot is on my own network.</p>

<p>And it was not only chatting. Every clean, the robot sent a floorplan, named room by room, plus a list of the furniture it recognised and where each piece stood. The layout of the apartment, sitting on someone else’s server.</p>

<p>Some of this is totally normal and expected. A cloud robot leans on the cloud for its app, and time and update checks are routine for anything online. The point was never whether it talks. It was whether I want it to, and to whom.</p>

<h2 id="the-photos-it-had-kept">The photos it had kept</h2>

<p>While working on the robot, I found something I did not expect. It had been taking photos while cleaning and saving them to its own storage. There is no switch in the app to stop it. Even with the data-sharing setting (“User Experience Optimization”) turned off, it still took around 80 photos every run.</p>

<p>To be clear what this is and is not: on my unit the photos stayed on the robot and were never uploaded. That is milder than <a href="https://youtu.be/qOjiCbxP5Lc">what Paul Moore showed on eufy cameras in 2022</a>, where images went to the cloud even with cloud features off. Mine stayed local. Still not what “off” should mean, and once the robot is on my own network with no way out, those files go nowhere anyway.</p>

<p>After that, this was not just about convenience any more.</p>

<h2 id="taking-it-local">Taking it local</h2>

<p>I did not use an off-the-shelf tool for this, because there simply was none. I wrote my own little app. With the AI tools around today this is not a huge task any more, as long as you have clear guidelines and a sense of the structure. Watching the robot’s connections, the commands going in and out, gave me a way to reuse the software that was already running and controlling the robot. On top of that sits the app that exposes the local interface, and that part is mine. The live map reuses the open Valetudo format. Valetudo itself did not support this robot when I checked, and I found its footprint too big to run on the bot anyway, so I took only the map format. The code is linked below.</p>

<p><img src="/assets/img/robot-vacuum/local-ui-map.png" alt="The local web UI running on the robot, map tab, floor plan blurred" class="shot" /></p>

<p>This part is the what and the why. Getting in comes in part 2, kept general on purpose, because the steps differ per model and firmware and old ones can brick a robot. How I got the robot to listen to me and hand me an ssh shell in the first place is its own story, for the next blog.</p>

<p>What I lost is less than I expected. Most commands work locally, and with Home Assistant on top I have everything I actually use under my own control: cleaning, rooms, the live map, scheduling. From there I could wire up automations, say start it when everyone is out, or run the kitchen after dinner. A few of the robot’s own commands would probably still need the cloud, but I did not miss any yet. No app account in the middle any more.</p>

<p>One thing I am honestly not sure about: the camera-based obstacle avoidance. It feels a little off at times, and I never worked out whether it leaned on the cloud to begin with. Given what the camera was quietly up to, I am not sure I mind.</p>

<h2 id="you-can-get-most-of-this-without-rooting-anything">You can get most of this without rooting anything</h2>

<p>You do not need to root anything to be a lot more private. Three steps, anyone can do them.</p>

<p>Put smart devices on their own network. Most routers have a guest or IoT (Internet of Things) network. If one device is ever compromised, it cannot reach your laptop.</p>

<p>Block the internet for devices that do not need it. A temperature sensor does not need to reach another continent. Watch first: a DNS filter like Pi-hole or AdGuard Home, which many people already run for ads, logs most of the names each device looks up. Then decide.</p>

<p>Choose before you buy. Before a device enters the house, check whether it can run locally at all: local control, open-firmware support, or Home Assistant without a cloud account. Picking the right device is far easier than fighting the wrong one for days, or even weeks.</p>

<p>But that is not always the way to go. Some devices genuinely need the internet - for a basic feature, for the right time so encrypted connections work, or for security updates. Block everything and you break things. Separate, watch, then block only what you are sure about. Or accept the loss of something and keep it offline.</p>

<h2 id="was-it-worth-it">Was it worth it</h2>

<p>For me, definitely. Several weekends and evenings, against a robot that will keep cleaning no matter what happens to the company behind it, and now its map, its camera and all the other sensors (does it even have a microphone? I should probably check that…) do not land on anybody else’s cloud. Do I miss anything yet? Not really. I would do it again, right away, if only out of curiosity. Whether it is worth it for you depends on how much you want a vacuum that has only one master of disaster.</p>

<p>Next time: how I got in, and what it took to make the robot trust me instead of the cloud. Part 2 is up: <a href="/blog/my-robot-vacuum-runs-linux/">My robot vacuum runs Linux. Here is how I got in.</a></p>

<p>The code is on GitHub: <a href="https://github.com/dhumpf/x10-ctl">dhumpf/x10-ctl</a>.</p>]]></content><author><name>Foothills Builds</name></author><summary type="html"><![CDATA[A robot vacuum that mapped my home and talked to a vendor cloud now runs entirely on my own network. What it was sending out before, what it had quietly saved to its own disk, and how to get better privacy without opening anything.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://foothillsbuilds.com/assets/img/robot-vacuum/local-ui-map.png" /><media:content medium="image" url="https://foothillsbuilds.com/assets/img/robot-vacuum/local-ui-map.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Running my own firmware on cloud plugs, without opening them all</title><link href="https://foothillsbuilds.com/blog/running-my-own-firmware-on-a-cloud-plug/" rel="alternate" type="text/html" title="Running my own firmware on cloud plugs, without opening them all" /><published>2026-09-15T00:00:00-06:00</published><updated>2026-11-29T19:06:15-06:00</updated><id>https://foothillsbuilds.com/blog/running-my-own-firmware-on-a-cloud-plug</id><content type="html" xml:base="https://foothillsbuilds.com/blog/running-my-own-firmware-on-a-cloud-plug/"><![CDATA[<h1 id="running-my-own-firmware-on-cloud-plugs-without-opening-them-all">Running my own firmware on cloud plugs, without opening them all</h1>

<p>I bought four cheap WiFi smart plugs on Amazon. They work fine, they also talk to Tuya’s cloud in China, and there is no button anywhere that says “stop doing that”. This is the story of getting them to run firmware I chose, without opening all of them for a reflash, and what it cost to get there.</p>

<p>Short version: it works. Two of the four now run OpenBeken, an open firmware for these chips, and they have no way to reach the vendor any more. Getting there took quite a few rounds of work, and a good chunk of those were wrong turns.</p>

<p><img src="/assets/img/cloud-plug/plug-opened-serial.jpg" alt="The plug opened on the bench, case in two halves, board wired up for serial" />
<em>The one plug I opened. Case cracked, board out, serial wires on the UART pads - the oracle everything else was checked against</em></p>

<h2 id="why-bother">Why bother</h2>

<p>Two reasons. The plug phones home and I cannot turn that off, which is the real one. The other is that doing it without soldering sounded like fun.</p>

<p>The usual way to free a device like this is to open it, find the serial pads, and flash it over a wire. That works, I have done it, and it also means a screwdriver, a soldering iron, and a plug that no longer closes properly if it is ultrasonically welded, as these are. I wanted to know whether the network was enough, and if there was any backdoor to get that working.</p>

<h2 id="what-you-need-before-you-start">What you need before you start</h2>

<ul>
  <li><strong>The device on your own cloud account.</strong> Everything here is done to hardware I bought, paired to my own account in the vendor cloud. That is the whole basis. <code class="language-plaintext highlighter-rouge">localKey</code> is handed to the owner by the account. <code class="language-plaintext highlighter-rouge">secKey</code> is not. The device still has to be in the account, although only for the initial access.</li>
  <li><strong>A full flash dump of one unit.</strong> I cracked one plug open and read its flash over serial. You need one oracle at least, a known-good copy to check every answer against. That one unit gives you the firmware layout, the pin map, and a reference image to test against.</li>
  <li><strong>Somewhere to watch it think.</strong> The Tuya WiFi module is a separate board soldered onto the main PCB, and it has debug pads that print log lines. Without them you are guessing. With them, the device tells you which check it failed, which is worth more than any amount of clever reasoning.</li>
  <li><strong>A way back.</strong> Assume you will break it. I broke the same plug three times in one evening. Each time the fix was a two minute reflash over serial, because I had the original firmware backed up and a serial console already attached.</li>
</ul>

<p><img src="/assets/img/cloud-plug/plug-module-probe.jpg" alt="Close up of the board edge on, showing the WiFi module as a separate board soldered onto the main PCB, with serial jumpers attached" />
<em>The WiFi module is its own board soldered onto the main PCB. The debug pads that print the log lines are on it</em></p>

<h2 id="the-shape-of-the-thing">The shape of the thing</h2>

<p>Every device like this has some update path. It has to, as the vendor needs to be able to ship fixes and provision it in the factory. On these plugs there are two: one over the internet via the vendor cloud, and one over the local network.</p>

<p>The local one is the interesting one. It is authenticated with a key the vendor issues at activation and hands to the owning account. So as the owner, you can hand the plug a firmware image over your own network and it will take it, check it, and install it. That is not a hole someone forgot to close. It is the update mechanism, used by its owner, for the thing it was built to do.</p>

<p>What made it hard was not authentication. It was format.</p>

<h2 id="where-the-days-of-reverse-engineering-went">Where the days of reverse engineering went</h2>

<p>The image is wrapped in a container with a header describing it. The header has a dozen fields. Get one wrong and the device either refuses politely, or accepts it and quietly bricks itself. I went down the brick path several times.</p>

<p>A few that were genuinely interesting:</p>

<p><strong>The self-referential checksum.</strong> One header field holds a checksum that covers a range including the field itself. So the value must equal the checksum of data containing that value. You cannot search for it - there are four billion candidates. But CRC32 is linear in a useful way, which means you can solve for it directly with a bit of algebra. Thirty-two test values and some elimination, no guessing, no device round trips.</p>

<p><strong>The compression is picky.</strong> The bootloader decompresses the image with a cut-down decompressor built for tiny memory. It allows a dictionary - the window of recent data the compressor can refer back to - of exactly 4 KB, which happens to be the smallest the format can express. Compress with any normal setting and the device rejects the stream without saying why. There is exactly one option.</p>

<p><strong>The bug that broke the plug all three times.</strong> This one is my favorite, because the answer was pure arithmetic.</p>

<p>The install writes the new firmware in chunks. I set the chunk size to 4 KB, which looked obviously fine: flash erases in 4 KB sectors, so one chunk should be exactly one sector.</p>

<p>But this chip does not store my bytes the way I hand them over. Every 32 bytes of data gets 2 bytes of checksum written alongside it, all the way through. So 4 KB of <em>mine</em> is not 4 KB once it lands. It is 128 groups of 32 bytes, each grown to 34, and 128 x 34 is 4352 bytes. A sector holds 4096. My chunk was 256 bytes too big for the sector it was supposed to fit in.</p>

<p>Erasing happens a whole sector at a time. So when the next chunk erased its sector, it wiped the 256 bytes the previous chunk had spilled into it. Every chunk quietly ate the tail of the one before.</p>

<p>The write reported complete, every byte accounted for, and the result was shredded in 256-byte bites throughout. The device then failed its final integrity check, which is the only reason I noticed.</p>

<p>The fix is one number: a chunk whose real size lands on a whole sector. 64 KB becomes 69632 bytes, which is exactly 17 sectors, so nothing spills.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>4 KB  -&gt; 4352 bytes  = 1.06 sectors   corrupts
64 KB -&gt; 69632 bytes = 17 sectors     works
</code></pre></div></div>

<h2 id="how-i-actually-found-that">How I actually found that</h2>

<p>Not by being clever. By noticing something that was <em>not</em> in the log.</p>

<p>An earlier attempt had failed with <code class="language-plaintext highlighter-rouge">Read patch fail</code>, repeated thousands of times. The attempt after I fixed the write destination had none at all - and still failed. That absence was the clue: if every read succeeded, decompression was fine, so the damage had to be happening after the data was decoded. That pointed at the write path, and the write path is where the arithmetic above lives.</p>

<p>This turned out to be the pattern for the whole project. The answers that held up came from arithmetic in the binary or from something missing in a log. The answers that fell apart came from a story that fit the symptom.</p>

<h2 id="the-part-where-the-ai-assistance-failed">The part where the AI assistance failed</h2>

<p>I chased most of this down while using a lot of AI assistance for the heavy lifting, and kept a log of every round as we went. It still needs a human to keep track - knowing what is settled, and sending the prompt that points to the exact problem and issue to solve rather than reiterating on already solved problems. Before chasing anything, search the notes and the captured logs for it first, as even with all the previous log files somewhere in the context the AI fails to see the bigger picture and tries to solve problems again that were already chased down a day or two ago.</p>

<p>The worst example: it concluded the whole approach was impossible and wrote that up in detail. A log file from the previous day, sitting on disk the entire time, showed the device doing the exact thing it had just declared impossible.</p>

<h2 id="a-trap-at-the-very-end">A trap at the very end</h2>

<p><strong>The open firmware does not fall back.</strong> I assumed that if it could not join a network it would open its own access point so I could fix it. It does not. It opens an access point only when <em>no</em> network is configured. A <em>wrong</em> network means it retries forever, unreachable. This is deliberate, and the source code comments the trap twice, five lines apart, in the tone of people who have been asked about it a lot. One of the two guards a compile flag called <code class="language-plaintext highlighter-rouge">SPECIAL_UNBRICK_ALWAYS_OPEN_AP</code>.</p>

<p>The escape is a safe mode: power cycle it in quick succession, cutting power each time before the boot is marked successful. Five failures get recorded and the sixth boot comes up in safe mode, which opens the access point. Six short cycles did it, and it saved a serial reflash.</p>

<h2 id="where-it-ended-up">Where it ended up</h2>

<p>Two of the four run OpenBeken. They sit on a separate IoT VLAN and WiFi with no route to the internet, the relays respond to a plain HTTP request, and their cloud connections are not configured and never will be. The pin mapping - which pin is the relay, which is the button, which is the LED - came out of the device’s own configuration data, so nothing was guessed.</p>

<p>Total case openings for that unit: one, back in August, to take the original dump. Everything since has been over the network.</p>

<p>Since writing this, I tried it on three more plugs that had never been opened. Two went through exactly as described. On the third the mechanism worked just as well, but I handed it the wrong input file, so it took the image, wrote it, and bricked. Getting that one back will require some soldering and flashing after all.</p>

<p>Four plugs bought, two in service. The third is bricked and comes back once I open it and wire up serial. The fourth is the oracle, and it never goes back in its case - these are ultrasonically welded, and getting the module off was a one-way trip.</p>

<h2 id="what-i-would-tell-someone-starting-this">What I would tell someone starting this</h2>

<ul>
  <li>Take a full dump of one unit first. Everything else gets easier.</li>
  <li>Get the device’s log output working before you change anything. It will tell you which check failed, and that is the entire game.</li>
  <li>Have the original firmware and a serial adapter ready <em>before</em> the first write, not after. Recovery is routine when prepared and miserable when not.</li>
  <li>When something fails, look for what is missing from the log, not just what is in it.</li>
  <li>Write down what you concluded and when. Then actually read it before concluding the opposite.</li>
</ul>

<p>The installer is at <a href="https://github.com/dhumpf/et10-openbeken">et10-openbeken</a>. It does the network write, the pin setup, and the MAC restore once both values are in the two JSON files. <code class="language-plaintext highlighter-rouge">localKey</code> comes from the tinytuya wizard after the plug is on your Smart Life account and that account is linked to an IoT project. <code class="language-plaintext highlighter-rouge">secKey</code> does not. The consumer app API returns it, and signing that request takes a key recovered from the Smart Life app. <a href="https://github.com/nalajcie/tuya-sign-hacking">tuya-sign-hacking</a> already extracts that key from an older Tuya Smart build.</p>

<p>One thought I will leave here, without going further: on these devices, whoever holds the account holds the firmware. You own it, so you can reflash it.</p>]]></content><author><name>Foothills Builds</name></author><summary type="html"><![CDATA[A smart plug that only talked to a vendor cloud now runs OpenBeken, installed over the network. Over two weeks, a lot of wrong turns, and one bug that came down to sector arithmetic.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://foothillsbuilds.com/assets/img/cloud-plug/plug-opened-serial.jpg" /><media:content medium="image" url="https://foothillsbuilds.com/assets/img/cloud-plug/plug-opened-serial.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">My boiler monitor kept going quiet, and the network was fine.</title><link href="https://foothillsbuilds.com/blog/cellular-fallback-real-world/" rel="alternate" type="text/html" title="My boiler monitor kept going quiet, and the network was fine." /><published>2026-07-23T00:00:00-06:00</published><updated>2026-11-29T19:06:15-06:00</updated><id>https://foothillsbuilds.com/blog/cellular-fallback-real-world</id><content type="html" xml:base="https://foothillsbuilds.com/blog/cellular-fallback-real-world/"><![CDATA[<h1 id="my-boiler-monitor-kept-going-quiet-and-the-network-was-fine">My boiler monitor kept going quiet, and the network was fine.</h1>

<p>The whole point of the boiler monitor is that it tells someone when the fire goes out.
That is its entire job: read a few temperatures, watch the pumps, and send an alert before the house gets cold.
So the failure that actually got my attention was not a bad reading or a crash. It was the alerting going quiet.
I found out the way you never want to find out: my brother texted me to say he had not gotten a Telegram alert.</p>

<p>A monitor you cannot trust to speak up is worse than no monitor at all, because you have quietly stopped watching yourself. The surprise, when I dug in, was that the device was still running and sending metrics, just not sending any alerts. This post is about chasing down a memory problem, and what it takes to keep a small device honest and online without a road trip out there.</p>

<h2 id="the-setup">The setup</h2>

<p>A while back I wrote up <a href="/blog/why-i-built-owb/">why I built a wood boiler monitor</a> for my brother Theo. If you want the backstory, the sensors, and the why, you should read that one.</p>

<p>This one is going to be way more technical, about the part I skipped: keeping the thing connected.</p>

<p>Some context for this story: it is a LILYGO T-SIM7080-S3 sitting out at an outdoor wood boiler, a drive from my place, so I do not get to walk over and poke it when something breaks.
It has two ways off the property: WiFi, which is on Starlink, and LTE straight through the onboard SIM7080G modem, which should in theory be the backup if the power (and with it the WiFi) goes down.
Data goes out as MQTT over TLS, with Telegram alerts on top via the API and a firmware update check every few hours.</p>

<h2 id="why-wifi-is-primary-and-lte-is-only-the-backup">Why WiFi is primary and LTE is only the backup</h2>

<p>The WiFi at the boiler is bad. It sits around -88 dBm, which on paper is the kind of number where you expect constant drops.
In practice it holds. Weak but steady beats strong but flaky, and once the ESP32 is associated the link is pretty stable.</p>

<p>LTE loses on a few things that matter out there:</p>

<ul>
  <li><strong>Data cost.</strong> The IoT SIM is about $15 (CAD) a year for 1 GB, which is actually plenty for readings every 60 seconds plus firmware updates. But WiFi is free and unmetered, so there is no reason to spend a metered budget while it is up.</li>
  <li><strong>Latency.</strong> WiFi is instant once associated; cellular is not. A cold modem has to power up, attach to the network, bring up the link… That is seconds of work before the first byte moves, and on the weak signal even more.</li>
  <li><strong>Signal.</strong> Out there, you cannot really take a phone call if you are not in range of the cell booster or using WiFi Calling. So our little monitor has a hard time finding service as well.</li>
</ul>

<p>So the rule is simple: use WiFi whenever it is up, and only fail over to LTE when WiFi is genuinely gone. The failure I built the fallback <em>for</em> is not usually the WiFi itself. It is a power or Starlink outage taking out the whole house, and cellular is the one path that does not care because it does not go through the house. Whether that theory survived contact with reality is something I will come back to at the end.</p>

<h2 id="the-sim7080g-and-where-the-time-actually-goes">The SIM7080G, and where the time actually goes</h2>

<p>On paper the SIM7080G is lovely. Low power, Cat-M and NB-IoT, a built-in TCP and MQTT stack so the ESP32 does not have to run the TLS itself. In practice, the modem is a second computer bolted to the first one that you talk to over a serial port in a 1990s command language (the AT commands below), and that is where a disproportionate amount of debugging and testing time went.</p>

<p><strong>Powering it up is not “set a pin high.”</strong> You cannot just enable the module and start talking. The modem wants a specific power-up cycle, and then it still comes up on its own schedule. My bring-up code just pulses and retries until the chip answers, bounded by a time budget so a dead modem fails cleanly instead of hanging the task long enough to trip the watchdog (and reset the main microcontroller):</p>

<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">while</span> <span class="p">(</span><span class="o">!</span><span class="n">modem</span><span class="p">.</span><span class="n">testAT</span><span class="p">(</span><span class="mi">1000</span><span class="p">))</span> <span class="p">{</span>
  <span class="n">esp_task_wdt_reset</span><span class="p">();</span>
  <span class="k">if</span> <span class="p">(</span><span class="n">millis</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span> <span class="o">&gt;</span> <span class="n">WAKE_BUDGET_MS</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// 60 s</span>
    <span class="n">Log</span><span class="o">::</span><span class="n">error</span><span class="p">(</span><span class="n">TAG</span><span class="p">,</span> <span class="s">"Modem AT timeout"</span><span class="p">);</span>
    <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
  <span class="p">}</span>
  <span class="k">if</span> <span class="p">(</span><span class="o">++</span><span class="n">retry</span> <span class="o">&gt;</span> <span class="mi">6</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">Log</span><span class="o">::</span><span class="n">info</span><span class="p">(</span><span class="n">TAG</span><span class="p">,</span> <span class="s">"PWRKEY pulse"</span><span class="p">);</span>
    <span class="n">digitalWrite</span><span class="p">(</span><span class="n">PIN_MODEM_PWR</span><span class="p">,</span> <span class="n">LOW</span><span class="p">);</span>  <span class="n">delay</span><span class="p">(</span><span class="mi">100</span><span class="p">);</span>
    <span class="n">digitalWrite</span><span class="p">(</span><span class="n">PIN_MODEM_PWR</span><span class="p">,</span> <span class="n">HIGH</span><span class="p">);</span> <span class="n">delay</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span>
    <span class="n">digitalWrite</span><span class="p">(</span><span class="n">PIN_MODEM_PWR</span><span class="p">,</span> <span class="n">LOW</span><span class="p">);</span>
    <span class="n">retry</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
  <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>The pulse timing is not arbitrary; the datasheet wants a pull of roughly that length, and shorter ones were flakier when I tried them.</p>

<p><strong>The URC that silently vanishes.</strong> This one cost me almost a full weekend. The SIM7080 runs its own MQTT client, and inbound messages arrive as an unsolicited result code on the serial line:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>+SMSUB: "owb/cmd","{\"reboot\":true}"
</code></pre></div></div>

<p>The library I use for the AT interface (TinyGSM) has a URC handler for the SIM7080, but it does not know about <code class="language-plaintext highlighter-rouge">+SMSUB:</code>. So the line arrives, the library does not recognize it, and it gets quietly dropped into the void. From the outside everything looks fine: you subscribe, the broker confirms, the broker delivers, and nothing ever reaches your callback function. No error. Just silence on the inbound path.</p>

<p>The current fix is to stop relying on the library for this and drain the serial port every loop, matching the <code class="language-plaintext highlighter-rouge">+SMSUB:</code> line and parsing it by hand:</p>

<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// Format: +SMSUB: "&lt;topic&gt;","&lt;payload&gt;"</span>
<span class="kt">char</span><span class="o">*</span> <span class="n">p</span> <span class="o">=</span> <span class="n">line</span> <span class="o">+</span> <span class="mi">8</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="o">*</span><span class="n">p</span> <span class="o">!=</span> <span class="sc">'"'</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="n">p</span><span class="o">++</span><span class="p">;</span>
<span class="kt">char</span><span class="o">*</span> <span class="n">topicStart</span> <span class="o">=</span> <span class="n">p</span><span class="p">;</span>
<span class="kt">char</span><span class="o">*</span> <span class="n">topicEnd</span> <span class="o">=</span> <span class="n">strchr</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="sc">'"'</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">topicEnd</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="o">*</span><span class="n">topicEnd</span> <span class="o">=</span> <span class="sc">'\0'</span><span class="p">;</span>
<span class="c1">// ... same again for the payload between the next pair of quotes ...</span>
<span class="n">MQTTClient</span><span class="o">::</span><span class="n">dispatchInbound</span><span class="p">(</span><span class="n">topicStart</span><span class="p">,</span> <span class="n">payloadStart</span><span class="p">,</span> <span class="n">payloadLen</span><span class="p">);</span>
</code></pre></div></div>

<p>Two gotchas hide in that innocent-looking parse. First, a URC does not wait for a quiet moment. One can land in the middle of another command’s response, so the same <code class="language-plaintext highlighter-rouge">+SMSUB:</code> matcher has to run inside the wait loop for every AT command too, or you drop inbound messages the moment the device is busy publishing.</p>

<p>Second, an empty payload (some commands from my app arrive with no body at all) has a degenerate <code class="language-plaintext highlighter-rouge">"topic",""</code> form that a naive parser throws away. Handling those zero-length payloads had to be explicit.</p>

<p><strong>The worst failure is the one that looks healthy.</strong> There is a state the SIM7080G gets into where every status register you would think to check comes back green. The modem is registered, signal strength is fine, the MQTT session reports connected. And <code class="language-plaintext highlighter-rouge">+SMSUB:</code> URCs just stop arriving. Nothing in the status tells you the inbound path is dead, because as far as the modem is concerned it is not.</p>

<p>There is no command (or at least I did not find one so far) that fixes this behaviour. The only thing that reliably brings it back is a hard power-cycle of the modem itself. As of now, a watchdog watches the inbound path specifically: if the modem claims to be healthy but has gone silent past a specific threshold, it hard-resets the whole thing.</p>

<h2 id="tls-is-the-expensive-part">TLS is the expensive part</h2>

<p>Everything leaves the boiler encrypted: MQTT over TLS, Telegram over HTTPS, OTA over HTTPS. On a laptop or smartphone that is free. On an ESP32 with something like 512 KB of RAM to share across the entire program, TLS is the single most expensive thing the firmware does. One <code class="language-plaintext highlighter-rouge">WiFiClientSecure</code> handshake wants roughly 30 KB of heap, and mbedtls (the TLS library underneath) needs a good chunk of that to be <em>contiguous</em>, not just free somewhere. The S3 does have 8 MB of slower PSRAM to offload bigger buffers to, but the handshake wants its working memory in internal RAM, so PSRAM does not buy a way out here.</p>

<p>That contiguous part is the whole trap. I wrote about heap fragmentation in the <a href="/blog/why-i-built-owb/">boiler post</a> already - the parking-lot version where you have plenty of total free memory but not one block big enough for the next thing. TLS is where that bites hardest.</p>

<p>The mistake I made first was a fresh <code class="language-plaintext highlighter-rouge">WiFiClientSecure</code> for every connection. It only works for a little while. But every make-and-destroy cycle leaves the heap a little more fragmented, and after a handful of them there is no 30 KB block left for the next handshake even though there is plenty of free memory in total. The device does not crash cleanly; it just stops being able to connect.</p>

<p>The fix is boring and it is the right one: allocate the TLS client once, as a static, and reuse it for the life of the program. One for MQTT, one for Telegram:</p>

<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">WiFiClientSecure</span> <span class="n">TelegramModule</span><span class="o">::</span><span class="n">_secClient</span><span class="p">;</span> <span class="c1">// one instance, reused forever</span>
</code></pre></div></div>

<p>No per-connection, so no fragmentation from that path.</p>

<p>The catch with reusing it is that the client holds TLS state between connections, and some of that state is sticky in a way that messes things up again. If a handshake fails partly, <code class="language-plaintext highlighter-rouge">WiFiClientSecure</code> keeps the mbedtls context around with whatever cert pointers it had. Call <code class="language-plaintext highlighter-rouge">setCACert</code> or <code class="language-plaintext highlighter-rouge">setCertificate</code> again on that still-allocated context and it is silently ignored: the next handshake reuses the stale config. On the broker side you get</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>peer did not return a certificate
</code></pre></div></div>

<p>which is really confusing the first time, because you are very much setting a certificate. The fix is to <code class="language-plaintext highlighter-rouge">stop()</code> the client before setting the cert again:</p>

<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">_wifiClient</span><span class="p">.</span><span class="n">stop</span><span class="p">();</span> <span class="c1">// release the mbedtls context first</span>
<span class="n">_wifiClient</span><span class="p">.</span><span class="n">setCertificate</span><span class="p">(</span><span class="n">_clientCert</span><span class="p">);</span>
<span class="n">_wifiClient</span><span class="p">.</span><span class="n">setPrivateKey</span><span class="p">(</span><span class="n">_clientKey</span><span class="p">);</span>
</code></pre></div></div>

<p>And when fragmentation wins anyway, because after weeks of uptime it just does, there is one last resort. If the allocation has failed 3 times in a row and the largest free block has dropped under the threshold, the firmware stops fighting and reboots itself:</p>

<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">if</span> <span class="p">(</span><span class="n">_retryCount</span> <span class="o">&gt;=</span> <span class="mi">3</span> <span class="o">&amp;&amp;</span> <span class="n">ESP</span><span class="p">.</span><span class="n">getMaxAllocHeap</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">40000</span><span class="p">)</span> <span class="p">{</span>
  <span class="n">Log</span><span class="o">::</span><span class="n">error</span><span class="p">(</span><span class="n">TAG</span><span class="p">,</span> <span class="s">"TLS alloc failed 3x with low heap - rebooting to defrag"</span><span class="p">);</span>
  <span class="n">ESP</span><span class="p">.</span><span class="n">restart</span><span class="p">();</span>
<span class="p">}</span>
</code></pre></div></div>

<p>A deliberate reboot out there costs a few seconds nobody really notices. A broken device that needs a drive to power-cycle costs an afternoon. Rebooting on purpose is the cheap and fail-safe option, and that idea comes back in the next part.</p>

<h2 id="so-what-was-actually-going-wrong">So what was actually going wrong</h2>

<p>Here is the part that took me a while to accept: the connection was fine.</p>

<p>WiFi associated with its usual weak-but-steady signal, the MQTT client seemed to be connected. And still nothing going out. Same problem the modem had a couple of sections up, only one level higher: the whole device was confidently offline. It believed it was online, and it had run out of memory to actually send anything.</p>

<p>That is what memory fragmentation does over long uptime. Not a clean crash, not a disconnect you can catch. Just a slow slide until the next thing that needs a contiguous block - a publish buffer, a TLS handshake for reconnect - cannot get one. The client still says connected, because the socket is still open. The publish just fails quietly, because there is no room to build the message. From the outside, it is silence.</p>

<p>You cannot fix that by trusting anything the device says about itself, because everything it says is “fine.” So the firmware stops trusting it. If the MQTT client claims to be connected but nothing has successfully gone out past a specific threshold (as of now 10 minutes), a watchdog tears the session down and reconnects from scratch:</p>

<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">if</span> <span class="p">(</span><span class="n">_lastSuccessMs</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="n">now</span> <span class="o">-</span> <span class="n">_lastSuccessMs</span> <span class="o">&gt;</span> <span class="n">WATCHDOG_MS</span><span class="p">))</span> <span class="p">{</span> <span class="c1">// 10 min</span>
  <span class="n">Log</span><span class="o">::</span><span class="n">warn</span><span class="p">(</span><span class="n">TAG</span><span class="p">,</span> <span class="s">"Watchdog: no activity - forcing reconnect"</span><span class="p">);</span>
  <span class="n">_client</span><span class="p">.</span><span class="n">disconnect</span><span class="p">();</span>
  <span class="n">_wifiClient</span><span class="p">.</span><span class="n">stop</span><span class="p">();</span>
<span class="p">}</span>
</code></pre></div></div>

<p>And behind it sits the heap floor from the last section. When that forced reconnect tries to handshake and there is no contiguous block left for it, the low-heap reboot fires, the device comes back with a clean heap, and it reconnects in a few seconds. The reboot is not the failure; it is the recovery.</p>

<p>It is not elegant, but it is honest about the constraint it lives under, and the alerts start flowing again on their own.</p>

<p>I did also harden the actual network path while I was in here, because a remote device deserves belt and suspenders. There is TCP keepalive on the socket (<code class="language-plaintext highlighter-rouge">setsockopt</code> with a 30 second idle, 10 second probes, 3 strikes) so a genuinely half-dead link gets noticed in tens of seconds instead of never. And a hard 10 second cap on every blocking HTTPS call so a slow Telegram send cannot sit in the main loop long enough to starve the MQTT keepalive. Those were real improvements. But I want to be straight about it: they were not what had gone wrong. What had gone wrong was memory fragmentation.</p>

<h2 id="has-the-fallback-ever-actually-fired">Has the fallback ever actually fired?</h2>

<p>Time to make good on the promise from the top. I put a lot of hours into the cellular path; the modem section up there is the short version of a long fight. So here is the fair question: out at the real boiler, has any of it ever actually saved the day?</p>

<p>As far as I can tell, no. Not once.</p>

<p>That is less depressing than it sounds. The fallback only does anything when WiFi is gone, and the ugly-but-stable WiFi out there almost never goes fully away. The few times it might have, I was not watching, and a quiet successful failover does not send up an alert to say it earned its keep last night. A backup path that works perfectly is invisible.</p>

<p>So how do you test something that almost never fires on its own? You force it. The cleanest trick I found is to point the WiFi config temporarily at an SSID that does not exist (newer firmware versions have a wifi.enabled switch for it in the config). The device tries, fails, gives up on WiFi, and walks through its failover: standby, activating, modem up, and then it starts pushing metrics over LTE. I have done that on the bench and once on site, standing next to it, and both times the mechanism did what it should.</p>

<p>But I want to be honest about what that does and does not prove.</p>

<ul>
  <li>I forced it. A real outage, or a half-associated access point, might not look as clean as flipping to a fake SSID.</li>
  <li>The time I tested on site, nothing happened to be alerting. So the exact path I should care about most was only tested on the bench.</li>
  <li>Cellular coverage out there is bad. The backup link has weak signal at exactly the spot it would have to work, and more testing and maybe some antenna optimization are still pending because of that.</li>
</ul>

<p>Since I cannot count on ever seeing it fire, I built it to fail safe instead of to look good. Activation runs on a timer: if the modem cannot get online within about thirty minutes, it hard-resets and drops back to standby rather than sitting there silent. There is also a hysteresis on the transitions so it does not flap between WiFi and LTE. The rule I settled on is that a fallback I cannot watch has to have a worst case of “quietly gives up and retries,” never “bricks the one device I would have to drive out to reach.”</p>

<p>So, in theory it works, and I have bench-proved the pieces work. I have not watched it carry a real alert through a real outage. It is insurance I have partly, not fully, and some more tests and optimizations are coming.</p>

<h2 id="where-this-goes-next">Where this goes next</h2>

<p>The to-do list out of all this is short. Do real failover testing at the site, which mostly means dealing with the bad cellular coverage before the fallback is worth trusting. And keep watching the heap over long uptime, because “reboot before you go quiet” is a safety net, not a fix, and I would rather it fragmented slower in the first place. I already send the free heap and maximum allocatable block out via MQTT and it seems to have stabilized. The longest uptime so far was around 14 days, until I pushed a firmware update and rebooted the device. And the memory metrics looked healthy by then.</p>

<p>None of it is solved. It runs, it has not missed a real alert since the fix, and I keep finding new ways it can quietly let me down.</p>

<p>I also had the idea of integrating LoRaWAN and putting a central hub with better WiFi and cellular uplink somewhere else. But that is just theory for now and would be another device and failure domain to take care of.</p>

<p>The firmware is all open if you want to see how any of this actually looks in code: <a href="https://github.com/Thesada/thesada-fw">thesada-fw on GitHub</a>, and how the connection fallback works is written up in the <a href="https://thesada.io/firmware/architecture/connectivity">connectivity docs</a>.</p>]]></content><author><name>Foothills Builds</name></author><summary type="html"><![CDATA[A remote ESP32 on a wood boiler kept going silent, and the link was not the problem. It was running out of memory. How I stopped a monitor from quietly failing at its one job.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://foothillsbuilds.com/assets/img/owb/owb_attached_sensors_at_boiler.png" /><media:content medium="image" url="https://foothillsbuilds.com/assets/img/owb/owb_attached_sensors_at_boiler.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Pool Controller</title><link href="https://foothillsbuilds.com/blog/pool-controller/" rel="alternate" type="text/html" title="Pool Controller" /><published>2026-07-08T00:00:00-06:00</published><updated>2026-11-29T19:06:15-06:00</updated><id>https://foothillsbuilds.com/blog/pool-controller</id><content type="html" xml:base="https://foothillsbuilds.com/blog/pool-controller/"><![CDATA[<h1 id="pool-controller">Pool Controller</h1>

<p><em>Archive repost from my old blog (2020). Original snapshot on the
<a href="https://web.archive.org/web/20211027062700/https://www.dhumpf.de/?p=173">Wayback Machine</a>.</em></p>

<p>At my parents’ house there’s a pool in the garden with an older controller for
the filter pump and solar heating. Underground pipes pump the water from the
skimmer and floor drain into the house, push it through the sand filter, heat
it if needed - depending on how much solar heat is available - and return it to
the pool through a few meters of pipe and the inlet nozzles.</p>

<p>The old controller is dead simple: a mechanical timer, an input for a
temperature sensor, an output for the circulation pump of the heat exchanger,
and a contactor-switched output for the filter pump. Most of the time, though,
the pump gets switched on by hand - which means a walk down into the basement.</p>

<hr />

<h2 id="the-concept">The concept</h2>

<p>I wanted the new controller to be WiFi-capable and still cover everything the
old one did. I started with a rough concept, then turned it into circuit
schematics and designed boards for them.</p>

<p>There are actually two schematics and two boards: a base module built around a
Wemos D1 mini, and a small DC-DC converter board (6-35V to 5V) that solders
onto it.</p>

<p><img src="/assets/img/pool-controller/base-module-schematic.png" alt="Base module schematic" />
<em>The base module schematic - Wemos D1 mini, optocoupler inputs, a ULN2003 driving the outputs</em></p>

<p><img src="/assets/img/pool-controller/base-module-pcb.png" alt="Base module board layout" />
<em>The base module board layout</em></p>

<p><img src="/assets/img/pool-controller/dcdc-converter-schematic.png" alt="DC-DC converter schematic" />
<em>The DC-DC converter schematic, built around a TPS5430</em></p>

<p><img src="/assets/img/pool-controller/dcdc-converter-pcb.png" alt="DC-DC converter board layout" />
<em>The DC-DC converter board layout</em></p>

<hr />

<h2 id="the-build">The build</h2>

<p>I had the boards manufactured at JLCPCB. The DC-DC converters came back already
assembled; the base modules I populated myself.</p>

<p><img src="/assets/img/pool-controller/dcdc-boards-panel.jpg" alt="Panel of DC-DC converter boards" />
<em>A panel of DC-DC converter boards, assembled at the fab</em></p>

<p><img src="/assets/img/pool-controller/dcdc-board-assembled.jpg" alt="A single DC-DC converter board" />
<em>One DC-DC converter board - 6-35V in, a clean 5V out</em></p>

<p><img src="/assets/img/pool-controller/base-boards-bare.jpg" alt="The bare base-module boards" />
<em>The bare base-module boards, back from the fab and ready to populate</em></p>

<p>Of course I made a mistake in the first revision - already fixed in the
schematics above: the two optocoupler-isolated inputs were wired wrong on the
Wemos board, so it reset itself continuously (D3/D4 pulled to ground through
the pulldowns). I patched it with a bit of enameled wire near the two
optocouplers.</p>

<p>Once a board was populated, I flashed the Wemos with a Tasmota build.</p>

<p><img src="/assets/img/pool-controller/module-assembled.jpg" alt="The assembled module with the Wemos D1 mini" />
<em>The assembled module with the Wemos D1 mini plugged in, sitting in its DIN-rail case</em></p>

<p>From there it went into a small distribution box, along with two auxiliary
relays, a contactor, and a 24V power supply. The
display, a button to switch the display on and off, and a potentiometer for
setting the target temperature went into drilled and cut-out sections of the
housing. The display flickers at a high frequency, so there’s always one black
line in photos - the eye doesn’t notice it. A button for manually switching the
filter pump on and off went into one of the cable entries on the box.</p>

<hr />

<h2 id="the-result">The result</h2>

<p><img src="/assets/img/pool-controller/distribution-box.jpg" alt="The finished controller in the distribution box" />
<em>The finished controller - Eaton contactor, two auxiliary relays, a 24V supply, and the display showing live temperatures</em></p>

<p>The filter pump can now be switched three ways: by push button, through the web
interface, and on a schedule with Tasmota. Depending on the water temperature
and whether the solar system has excess heat to give, the circulation pump of
the heat exchanger switches on as well.</p>]]></content><author><name>Foothills Builds</name></author><summary type="html"><![CDATA[A WiFi controller for my parents' pool - filter pump and solar heating, from concept to a DIN-rail module running Tasmota. Archive repost from 2020.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://foothillsbuilds.com/assets/img/pool-controller/distribution-box.jpg" /><media:content medium="image" url="https://foothillsbuilds.com/assets/img/pool-controller/distribution-box.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Why my ESP32 firmware speaks Lua</title><link href="https://foothillsbuilds.com/blog/why-my-esp32-firmware-speaks-lua/" rel="alternate" type="text/html" title="Why my ESP32 firmware speaks Lua" /><published>2026-05-15T00:00:00-06:00</published><updated>2026-11-29T19:06:15-06:00</updated><id>https://foothillsbuilds.com/blog/why-my-esp32-firmware-speaks-lua</id><content type="html" xml:base="https://foothillsbuilds.com/blog/why-my-esp32-firmware-speaks-lua/"><![CDATA[<h1 id="why-my-esp32-firmware-speaks-lua">Why my ESP32 firmware speaks Lua</h1>
<p><em>(and why I did not write my own little language)</em></p>

<p>The wood boiler firmware does not just read sensors. It decides
when to escalate, when to send alerts, when to back off and
wait. Those decisions are the part most likely to change. The
sensor wiring is settled. The MQTT plumbing is settled. The rules
keep moving and can change from time to time.</p>

<p>At the beginning of the project the rules lived in C++ like
everything else. Every time I wanted a different threshold, a
different hysteresis, a different combination of conditions for
the device, I rebuilt the firmware, pushed it as an OTA, and
waited for the device to fetch and reboot. That is fine for a
one-off. It is a trap if every deployment needs its own decision
tree, and just not what I wanted.</p>

<p>The honest options were:</p>

<ol>
  <li><strong>Roll my own little language.</strong> A purpose-built rule format,
parsed by code I would write. Very steep learning curve. And
also a months-long side quest I do not need.</li>
  <li><strong>YAML config plus a hard-coded evaluator.</strong> Similar to
ESPHome’s approach. Works well for the cases the evaluator
covers. Falls apart the moment you want a condition the
evaluator can’t handle. Just not as flexible as I had it in my
mind.</li>
  <li><strong>An embedded scripting language.</strong> Drop a real interpreter
into the firmware, expose the things the device can already
do, let scripts decide. Kind of the approach I have as a
systems specialist in front of me almost daily.</li>
</ol>

<p>Option three is where this ends up. The question was which
language.</p>

<p>I picked Lua. Three reasons:</p>

<ul>
  <li>It is designed to be embedded. The whole point of Lua, since
it was designed in 1993, is to live inside someone else’s C
program. It is not fighting to be the firmware. It is fitting
under it.</li>
  <li>The footprint fits within the ESP32 - Lua 5.3 compiles to
roughly 150 KB. The interpreter, the standard library, the
bindings I wrote on top, all of it lands in flash without
crowding out the parts that actually need to be there.</li>
  <li>Lua leaves the door open for Blockly. Down the road I would 
like somebody who is not a programmer to be able to wire up
rules visually. Blockly already has a Lua code generator. 
The block view emits Lua. The firmware runs Lua. The seam is already cut.</li>
</ul>

<p>I considered some alternatives. Berry, from Tasmota, is smaller
and lovely. The Blockly path would need a custom generator
though, and Tasmota is the only big production user. MicroPython
would mean replacing the firmware, not embedding in it. There
were some more, but all the picks had some trade-offs. Lua had
the fewest for what I wanted.</p>

<p>The rest of this post is what it looks like once the interpreter
is in there - what the API exposes, what a real rule looks like,
and what I had to do to make hot-reload not blow up in my face
(and saved me some field trips).</p>

<h2 id="where-the-scripts-live">Where the scripts live</h2>

<p>Two files on the device’s flash:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/scripts/main.lua    - runs at boot, and again on every reload
/scripts/rules.lua   - the one I actually iterate on
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">main.lua</code> runs every time the Lua state comes up. It is for the
setup the script needs each time the interpreter starts fresh:
registering EventBus subscriptions, MQTT topic handlers, helper
functions. Stuff I rarely edit. <code class="language-plaintext highlighter-rouge">rules.lua</code> is the policy I
actually change - thresholds, conditions, the response logic. The
split is editorial, not technical. Either file can pull in more
via <code class="language-plaintext highlighter-rouge">dofile("/scripts/other.lua")</code> if two is not enough.</p>

<p>Editing happens through the device’s web UI if I am on the same
network, over the serial port if I am sitting in front of it, or
through the MQTT shell from the
<a href="/blog/mqtt-cli-esp32/">previous post</a> if I am
anywhere else. Whichever path I take, the file lands on LittleFS
and the device gets a reload trigger:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;prefix&gt;/cmd/lua/reload
</code></pre></div></div>

<p>The device is already subscribed to that topic at boot. Any
payload at all flips the switch. The interpreter tears down its
state, opens a fresh one, re-registers every native binding,
re-executes both scripts, and is back online inside a few
hundred milliseconds. No reboot, no OTA, no driving anywhere, no
field-flashing a microcontroller in the snow at -20 with
freezing fingers.</p>

<p>There is one detail that took me an evening to get right and
that I will come back to: anything <code class="language-plaintext highlighter-rouge">rules.lua</code> subscribes to on
the EventBus or on MQTT during one run has to be invisible to the
next run, or the device ends up firing old logic against new
state. The fix is a generation counter. More on that in the
gotchas.</p>

<h2 id="what-lua-can-do-inside-the-firmware">What Lua can do inside the firmware</h2>

<p>The interpreter is sandboxed - no file system access beyond
LittleFS, no network sockets, no shell-out. What it does have is
a set of bindings into the parts of the firmware that already
exist:</p>

<table>
  <thead>
    <tr>
      <th>Module</th>
      <th>What it gives the script</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">Log</code></td>
      <td><code class="language-plaintext highlighter-rouge">Log.info(msg)</code>, <code class="language-plaintext highlighter-rouge">Log.warn(msg)</code>, <code class="language-plaintext highlighter-rouge">Log.error(msg)</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">MQTT</code></td>
      <td><code class="language-plaintext highlighter-rouge">MQTT.publish(topic, payload)</code>, <code class="language-plaintext highlighter-rouge">MQTT.subscribe(topic, fn)</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">EventBus</code></td>
      <td><code class="language-plaintext highlighter-rouge">EventBus.subscribe(event, fn)</code> - the in-process pub/sub</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">Config</code></td>
      <td><code class="language-plaintext highlighter-rouge">Config.get("a.b.c")</code> - dot-notation read from device config</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">Node</code></td>
      <td><code class="language-plaintext highlighter-rouge">Node.restart()</code>, <code class="language-plaintext highlighter-rouge">Node.uptime()</code>, <code class="language-plaintext highlighter-rouge">Node.ip()</code>, <code class="language-plaintext highlighter-rouge">Node.setTimeout(ms, fn)</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">JSON</code></td>
      <td><code class="language-plaintext highlighter-rouge">JSON.decode(str)</code> - parse to Lua table</td>
    </tr>
  </tbody>
</table>

<p>That table is what Lua sees out of the box. The interesting part
is that other modules can register more bindings of their own.
The Telegram module exposes a <code class="language-plaintext highlighter-rouge">Telegram.broadcast(text)</code> to send
to every configured chat, plus <code class="language-plaintext highlighter-rouge">Telegram.send(chat_id, text)</code> for
a specific one. The GNSS module exposes the last fix as a table. The shape of the API
depends on which modules are compiled into the build. I will come
back to how that wiring works.</p>

<p>In practice almost every rule uses three things: subscribe to an
event, decide whether to act, publish or alert. So most of
<code class="language-plaintext highlighter-rouge">rules.lua</code> ends up looking like this:</p>

<div class="language-lua highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">EventBus</span><span class="p">.</span><span class="n">subscribe</span><span class="p">(</span><span class="s2">"sensor.temperature"</span><span class="p">,</span> <span class="k">function</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
  <span class="k">if</span> <span class="n">data</span><span class="p">.</span><span class="n">value</span> <span class="o">&gt;</span> <span class="n">Config</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"alerts.overtemp_threshold"</span><span class="p">)</span> <span class="k">then</span>
    <span class="n">Log</span><span class="p">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">"overtemp: "</span> <span class="o">..</span> <span class="n">data</span><span class="p">.</span><span class="n">value</span><span class="p">)</span>
    <span class="n">Telegram</span><span class="p">.</span><span class="n">broadcast</span><span class="p">(</span><span class="s2">"Boiler overtemp: "</span> <span class="o">..</span> <span class="n">data</span><span class="p">.</span><span class="n">value</span> <span class="o">..</span> <span class="s2">" C"</span><span class="p">)</span>
  <span class="k">end</span>
<span class="k">end</span><span class="p">)</span>
</code></pre></div></div>

<p>Five lines, three bindings, one real alert. The script never has
to know that <code class="language-plaintext highlighter-rouge">Telegram.broadcast</code> ends up in an HTTPS POST, or
that <code class="language-plaintext highlighter-rouge">Config.get</code> walks a JSON tree, or that the <code class="language-plaintext highlighter-rouge">data</code> table
came from a C++ event marshalled to Lua. The firmware does the
work. The script makes the decisions.</p>

<h2 id="modules-bring-their-own-bindings">Modules bring their own bindings</h2>

<p><code class="language-plaintext highlighter-rouge">Log</code>, <code class="language-plaintext highlighter-rouge">MQTT</code>, <code class="language-plaintext highlighter-rouge">EventBus</code>, <code class="language-plaintext highlighter-rouge">Config</code>, <code class="language-plaintext highlighter-rouge">Node</code>, and <code class="language-plaintext highlighter-rouge">JSON</code> are the
core surface. They are always there because they are always
there in the firmware. The interesting bit is how the optional
modules - Telegram, GNSS, the various sensor drivers - extend the
Lua API without the script engine knowing anything about them.</p>

<p>Every module registers its bindings at boot. The signature looks
like this:</p>

<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">ScriptEngine</span><span class="o">::</span><span class="n">addBindings</span><span class="p">([](</span><span class="n">lua_State</span><span class="o">*</span> <span class="n">L</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">static</span> <span class="k">const</span> <span class="n">luaL_Reg</span> <span class="n">telegramLib</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span>
    <span class="p">{</span><span class="s">"send"</span><span class="p">,</span>      <span class="n">lua_telegram_send</span><span class="p">},</span>
    <span class="p">{</span><span class="s">"broadcast"</span><span class="p">,</span> <span class="n">lua_telegram_broadcast</span><span class="p">},</span>
    <span class="p">{</span><span class="nb">nullptr</span><span class="p">,</span> <span class="nb">nullptr</span><span class="p">}</span>
  <span class="p">};</span>
  <span class="n">luaL_newlib</span><span class="p">(</span><span class="n">L</span><span class="p">,</span> <span class="n">telegramLib</span><span class="p">);</span>
  <span class="n">lua_setglobal</span><span class="p">(</span><span class="n">L</span><span class="p">,</span> <span class="s">"Telegram"</span><span class="p">);</span>
<span class="p">});</span>
</code></pre></div></div>

<p>The script engine keeps a small static list of these registrar
functions. On boot, after the Lua state is created and the core
bindings are loaded, every registrar gets called in turn. On hot
reload, the list survives because it lives outside the Lua
state. The new state gets the same set of bindings, automatically.</p>

<p>The upshot is that the API a <code class="language-plaintext highlighter-rouge">rules.lua</code> script sees is exactly
the set of features compiled into that particular build. A
firmware with the Telegram module compiled in has <code class="language-plaintext highlighter-rouge">Telegram.*</code>.
A firmware without it does not. The script does not have to
guess - if <code class="language-plaintext highlighter-rouge">Telegram</code> is nil, the feature is not present in this
build, and the script can decide whether to fall back or just
fail loud.</p>

<p>This is the part I like the most. The Lua API and the C++ module
set are the same surface, exposed twice. The compile-time choice
of “what is in this build” is also the run-time choice of “what
can scripts see.” No drift, no separate registry, no extra
config file mapping one to the other.</p>

<h2 id="gotchas-the-ones-that-took-an-evening-each">Gotchas, the ones that took an evening each</h2>

<h3 id="stale-callbacks-after-reload">Stale callbacks after reload</h3>

<p>The naive version of hot reload tears down the Lua state and
builds a new one. What it does not tear down is the C++ side of
every <code class="language-plaintext highlighter-rouge">EventBus.subscribe</code> and <code class="language-plaintext highlighter-rouge">MQTT.subscribe</code> the old script
made. Those subscriptions live on the firmware side of the
fence. They still fire. And they still hold references into a
Lua state that no longer exists.</p>

<p>The first time I hit this, the device kept publishing alerts
from a rule I had just deleted. Reloaded the script, alerts kept
coming. Reloaded again, two copies of the alert. The old
callbacks were firing in addition to the new ones.</p>

<p>The fix is a generation counter. Think of it as a version number
that goes up by one every time the script is reloaded. Every
subscription the script makes gets stamped with the version that
was current at the time. When an event fires, the firmware
checks the stamp on the subscription against the current
version. If the stamps do not match, the subscription is from an
old script and gets ignored. The new script’s subscriptions,
stamped with the new version, are the only ones that run.</p>

<p>Nothing has to be unwired by hand. Old subscriptions just stop
having any effect, and they fall away on their own as the script
keeps running.</p>

<h3 id="parsing-scripts-without-blowing-the-heap">Parsing scripts without blowing the heap</h3>

<p>The other one is more boring but just as important. Lua’s
parser, by default, wants the whole script handed to it in one
piece. That means finding a single free slab of RAM big enough
to hold the file. On the older ESP32-WROOM (the classic chip,
no extra RAM on board) with a heap that is already busy, that
slab is exactly the thing that is not available. The device
runs out of memory partway through parsing a perfectly fine
script. On the newer ESP32-S3 with its extra PSRAM, the same
script loads without trouble.</p>

<p>The fix is to feed the parser the file in small pieces. Lua
supports this directly - hand it a reader function and it will
ask for bytes as it needs them, in whatever size chunk you want
to give it. A 256-byte buffer is enough. The script can be any
size, and the parser never sees more than a sliver at a time.</p>

<p>Same fix every embedded Lua project ends up writing. Worth
mentioning because the alternative is a confusing “everything
works on the S3, nothing works on the WROOM” bug that does not
look like a Lua problem at all.</p>

<h2 id="what-is-next">What is next</h2>

<p>The script engine has been quietly running on the production
wood boiler for weeks. Rules get edited from the couch. Alerts
get tuned without rebuilding. The firmware does what it has
always done. The decisions on top of it now live in a file I can
edit from anywhere.</p>

<p>The next piece I would like to land is the block-based editor.
Pick blocks from a palette, drop them on a canvas, see a rule
emerge, push it to the device. Blockly emits Lua. The device
runs Lua. That bridge is short. I will write that one up when it
works.</p>

<p>The scripting API as it stands today is in the <a href="https://thesada.io/firmware/lua-scripting">Lua scripting docs</a>.</p>]]></content><author><name>Foothills Builds</name></author><summary type="html"><![CDATA[Embedding Lua 5.3 in thesada-fw so rules change without a reflash, and the door stays open for block-based programming later. The reasoning, the API, the gotchas.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://foothillsbuilds.com/assets/img/owb/thesada_bot_screenshot_cropped.png" /><media:content medium="image" url="https://foothillsbuilds.com/assets/img/owb/thesada_bot_screenshot_cropped.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">I built a shell for my ESP32 over MQTT</title><link href="https://foothillsbuilds.com/blog/mqtt-cli-esp32/" rel="alternate" type="text/html" title="I built a shell for my ESP32 over MQTT" /><published>2026-04-28T00:00:00-06:00</published><updated>2026-11-29T19:06:15-06:00</updated><id>https://foothillsbuilds.com/blog/mqtt-cli-esp32</id><content type="html" xml:base="https://foothillsbuilds.com/blog/mqtt-cli-esp32/"><![CDATA[<h1 id="i-built-a-shell-for-my-esp32-over-mqtt">I built a shell for my ESP32 over MQTT</h1>
<p><em>(so I could stop driving out to fix things)</em></p>

<p>The wood boiler firmware runs at my brother Theo’s place in rural
Alberta. I am twenty minutes away. Not far. But “twenty minutes”
stops being the unit when I want to nudge an alert threshold and
check whether it actually fires, then nudge it again.</p>

<p>It also stops being the unit when I am not home. A few weekends ago
I was in southern Alberta visiting friends, three hours away, and
one of the boiler alerts failed to fire when it should have. I
pulled the iPad out of the car, opened VS Code Web, tunneled into
my code server at home, and walked through the device’s logs and
config from a kitchen table. The fix took about ten minutes. The
drive to “fix it properly” would have been six hours round trip.</p>

<p>The honest options before any of this existed were:</p>

<ol>
  <li>SSH. No. It is a microcontroller. There is no SSH.</li>
  <li>Push a firmware update with the new value baked in. Wait for the
device to fetch it. Hope it boots.</li>
  <li>Drive out and edit the config over USB.</li>
</ol>

<p>None of those felt right for “change one number.” Option 2 is
heavy. Option 3 burns at least an hour for the round trip plus the
fix, more when I am not in town. So I did what felt obvious in
hindsight: I gave the firmware a shell, and I plumbed it through
the MQTT broker the device was already talking to.</p>

<p>That decision is the whole post. Once your device has a broker,
your broker is already a bidirectional channel. If you only ever
publish from the device, you are using half of it.</p>

<h2 id="the-pivot">The pivot</h2>

<p>Every ESP32 in the field is already opening a TLS connection to
the broker. It publishes telemetry, listens for retained config
blobs, shows up on the Home Assistant dashboard. Adding a CLI to
that picture is not a new connection, not a new port, not a new
firewall rule on Theo’s router. It is just two more topics on the
broker the device is already attached to.</p>

<p>The shape ended up being:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;prefix&gt;/cli/&lt;command&gt;   &lt;- I publish here, device executes
&lt;prefix&gt;/cli/response    &lt;- device publishes here, I read
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">&lt;prefix&gt;</code> is the device’s MQTT root, like <code class="language-plaintext highlighter-rouge">thesada/owb</code>. The
device subscribes once at boot to <code class="language-plaintext highlighter-rouge">&lt;prefix&gt;/cli/+</code>. The plus is
the single-level wildcard: <code class="language-plaintext highlighter-rouge">cli/fs.cat</code>, <code class="language-plaintext highlighter-rouge">cli/config.dump</code>,
<code class="language-plaintext highlighter-rouge">cli/restart</code>, <code class="language-plaintext highlighter-rouge">cli/ota.check</code>, all hit the same handler, and the
handler just looks at the last topic segment to figure out which
command was invoked. The payload is the argument, plain bytes,
whatever the command needs.</p>

<p>The response goes back on a single fixed topic, <code class="language-plaintext highlighter-rouge">cli/response</code>,
as JSON. One line, easy to parse, easy to print. The topic shape
gives the device-level isolation for free: another device’s
broker credentials cannot publish into my device’s <code class="language-plaintext highlighter-rouge">cli/</code>,
because the broker ACL only lets each device read and write under
its own prefix.</p>

<p>QoS 0, retain false. Commands are not replayed on reconnect. If
the device was offline when I sent it, that command is gone, and
that is the behavior I want. The last thing I need is a device
that comes back from a power cycle and reboots itself again
because there was a stale <code class="language-plaintext highlighter-rouge">cli/restart</code> sitting in retained
storage.</p>

<h2 id="what-it-looks-like">What it looks like</h2>

<p>Here is a normal poke at the device from my laptop.
<code class="language-plaintext highlighter-rouge">mosquitto_pub</code> and <code class="language-plaintext highlighter-rouge">mosquitto_sub</code> are the only tools, plus a
second terminal pane to watch responses come back.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Terminal 1: subscribe to the response topic</span>
<span class="nv">$ </span>mosquitto_sub <span class="nt">-h</span> mqtt.example.lan <span class="nt">-t</span> <span class="s1">'thesada/owb/cli/response'</span> <span class="nt">-v</span>

<span class="c"># Terminal 2: ask the device what config it is running</span>
<span class="nv">$ </span>mosquitto_pub <span class="nt">-h</span> mqtt.example.lan <span class="nt">-t</span> <span class="s1">'thesada/owb/cli/config.dump'</span> <span class="nt">-m</span> <span class="s1">''</span>

<span class="c"># Terminal 1 prints (formatted for readability):</span>
thesada/owb/cli/response  <span class="o">{</span>
  <span class="s2">"ok"</span>: <span class="nb">true</span>,
  <span class="s2">"output"</span>: <span class="o">[</span>
    <span class="s2">"{"</span>,
    <span class="s2">"  </span><span class="se">\"</span><span class="s2">wifi</span><span class="se">\"</span><span class="s2">: { </span><span class="se">\"</span><span class="s2">ssid</span><span class="se">\"</span><span class="s2">: </span><span class="se">\"</span><span class="s2">...</span><span class="se">\"</span><span class="s2"> },"</span>,
    <span class="s2">"  </span><span class="se">\"</span><span class="s2">mqtt</span><span class="se">\"</span><span class="s2">: { </span><span class="se">\"</span><span class="s2">broker</span><span class="se">\"</span><span class="s2">: </span><span class="se">\"</span><span class="s2">...</span><span class="se">\"</span><span class="s2"> },"</span>,
    <span class="s2">"  </span><span class="se">\"</span><span class="s2">alerts</span><span class="se">\"</span><span class="s2">: { </span><span class="se">\"</span><span class="s2">temp_high</span><span class="se">\"</span><span class="s2">: 92, </span><span class="se">\"</span><span class="s2">temp_crit</span><span class="se">\"</span><span class="s2">: 98 }"</span>,
    <span class="s2">"}"</span>
  <span class="o">]</span>
<span class="o">}</span>

<span class="c"># Read a Lua script off the device's flash</span>
<span class="nv">$ </span>mosquitto_pub <span class="nt">-h</span> mqtt.example.lan <span class="nt">-t</span> <span class="s1">'thesada/owb/cli/fs.cat'</span> <span class="se">\</span>
    <span class="nt">-m</span> <span class="s1">'/scripts/rules.lua'</span>

<span class="c"># Push an updated script back</span>
<span class="nv">$ </span>mosquitto_pub <span class="nt">-h</span> mqtt.example.lan <span class="nt">-t</span> <span class="s1">'thesada/owb/cli/fs.write'</span> <span class="se">\</span>
    <span class="nt">-f</span> /scripts/rules.lua

<span class="c"># Trigger an OTA check now (instead of waiting for the next interval)</span>
<span class="nv">$ </span>mosquitto_pub <span class="nt">-h</span> mqtt.example.lan <span class="nt">-t</span> <span class="s1">'thesada/owb/cli/ota.check'</span> <span class="nt">-m</span> <span class="s1">'--force'</span>

<span class="c"># Reboot</span>
<span class="nv">$ </span>mosquitto_pub <span class="nt">-h</span> mqtt.example.lan <span class="nt">-t</span> <span class="s1">'thesada/owb/cli/restart'</span> <span class="nt">-m</span> <span class="s1">''</span>
</code></pre></div></div>

<p>Now, the honest part. None of those commands are MQTT-specific.
They are the same shell commands I already had wired up over
serial, for the days I am sitting next to a board with a USB
cable. <code class="language-plaintext highlighter-rouge">fs.cat</code>, <code class="language-plaintext highlighter-rouge">fs.write</code>, <code class="language-plaintext highlighter-rouge">config.dump</code>, <code class="language-plaintext highlighter-rouge">ota.check</code>,
<code class="language-plaintext highlighter-rouge">restart</code>, plus a couple of dozen others I have not bored you
with yet. Once I started thinking about a remote shell, the
“build a new API for it” instinct was the wrong one. Why
reinvent the wheel? The serial shell already had a parser, an
output format, error handling. I just gave it a second input and
output channel.</p>

<p>So there is one set of commands. Sitting at the bench with a USB
cable, I type into the serial console. Sitting on a kitchen
table in southern Alberta with an iPad, I publish to MQTT. Same
words, same arguments, same response format. That is what I
mean by “unified” - not a clever framework, just a deliberate
choice not to fork the API.</p>

<p>The Lua piece deserves its own post. Alert logic lives in
<code class="language-plaintext highlighter-rouge">/scripts/rules.lua</code> on the device’s filesystem, not in the C++
firmware. So “tweak an alert threshold” is <code class="language-plaintext highlighter-rouge">fs.cat</code>, edit,
<code class="language-plaintext highlighter-rouge">fs.write</code>, done. No recompile, no OTA, no reboot.</p>

<h2 id="why-this-matters">Why this matters</h2>

<p>The pitch sounds clean. The lived experience taught me what the
shell is actually for. Three quick stories.</p>

<p><strong>The alert that did not fire.</strong> This is the southern Alberta
one I mentioned at the top. The boiler hit a temperature that
should have triggered a Telegram alert. It did not. From the
iPad I pulled the current <code class="language-plaintext highlighter-rouge">rules.lua</code>, scanned the comparison
logic, found a unit mismatch I had introduced in the previous
session (Celsius vs the raw sensor scale, my fault), wrote a
corrected script back, and asked the device to restart so the
Lua engine reloaded clean. Ten minutes from “that is wrong” to
“that is fixed and live.”</p>

<p><strong>The Telegram heap problem.</strong> Telegram is delightful as an
alert channel and slightly less delightful when its TLS
handshake decides to allocate during a heap-tight moment. I had
a window where the device would publish telemetry fine, then
drop MQTT during a Telegram send, because the Telegram client
had eaten the headroom MQTT needed to keep its own TLS session
alive. I caught the pattern by hand from the shell, dumping
heap stats while triggering test alerts, until the shape of the
failure was obvious. The fix was a heap floor in the Telegram
module: if free heap is below the floor when an alert wants to
fire, MQTT keeps priority and the alert waits a beat. That fix
exists because of an evening of remote poking, not because I
predicted it.</p>

<p><strong>The almost-brick.</strong> This is the Murphy story. I pushed a
config change that quietly broke WiFi reconnect after a sleep
cycle. Device rebooted, came up, never made it back to the
broker, and I could not talk to it anymore. From the shell,
obviously, because the shell goes through the broker. Theo
cycled the power on my instructions, the device booted from the
previous good config, I fixed my mistake, and moved on. A trip
avoided, but a trip narrowly avoided.</p>

<p>That last one is where the watchdog story starts. Every time I
have nearly bricked a device remotely, the next firmware build
has gained a defensive feature. There is a preventive reboot if
free heap stays below a threshold for sixty seconds, on the
theory that whatever has the heap that low is probably not
going to give it back, and a clean boot from flash is
recoverable while a wedge over a shrinking heap is not. There
is the Telegram heap floor I mentioned. And once it became
clear the bigger boards had PSRAM sitting unused while the main
heap fought TLS for room, I started moving the chunky-but-cold
buffers (the CA certificate, OTA download buffers) into PSRAM
so the working heap had its breathing room back. The shell
makes me bolder. The watchdogs and the PSRAM moves catch me
when bolder turns into sloppy.</p>

<h2 id="what-this-unlocks">What this unlocks</h2>

<p>The remote shell changed how I work on the firmware in a way I
did not anticipate when I built it. The first version of any
feature is a draft. The shell lets the second, third, fifth
version happen at the speed of editing a Lua script and
pressing publish, instead of the speed of a build, an OTA, a
reboot, and a wait-and-see. That tightens the loop enough that
the device feels almost as iterable as the app running on my
laptop, even though it is twenty minutes away in a shed.</p>

<p>The other thing I did not anticipate is what happens when there
are several of them. I am planning to build something on top of
this MQTT API for fleet management - imagine the same <code class="language-plaintext highlighter-rouge">cli/*</code>
API, but instead of me typing <code class="language-plaintext highlighter-rouge">mosquitto_pub</code> against a single
device, a web dashboard shows me every device, lets me push a
config change to all of them at once, watches drift between
what is running and what should be running. The shell is the
primitive. The dashboard is the next layer. More on that when
it is ready.</p>

<h2 id="takeaway">Takeaway</h2>

<p>If your microcontroller talks to an MQTT broker, your broker is
already a bidirectional channel. You can keep using half of it -
device pubs, server reads, end of story. Or you can ask: what
would my future self thank me for being able to do remotely, six
months from now, when the device is in a shed I do not feel
like driving to?</p>

<p>For me the answer was a shell. For your project it might be
something else. But the shape - “use the existing connection,
expose your existing tools over it, do not invent a new API” -
probably travels.</p>

<p>The full command list is in the <a href="https://thesada.io/firmware/cli-reference">CLI reference</a>.</p>]]></content><author><name>Foothills Builds</name></author><summary type="html"><![CDATA[A CLI over MQTT means I can read files, push config, trigger updates, and reboot a microcontroller from anywhere. Here is what that looks like.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://foothillsbuilds.com/assets/img/owb/owb_in_case.png" /><media:content medium="image" url="https://foothillsbuilds.com/assets/img/owb/owb_in_case.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Why I Built My Own Wood Boiler Monitor</title><link href="https://foothillsbuilds.com/blog/why-i-built-owb/" rel="alternate" type="text/html" title="Why I Built My Own Wood Boiler Monitor" /><published>2026-04-16T00:00:00-06:00</published><updated>2026-11-29T19:06:15-06:00</updated><id>https://foothillsbuilds.com/blog/why-i-built-owb</id><content type="html" xml:base="https://foothillsbuilds.com/blog/why-i-built-owb/"><![CDATA[<h1 id="why-i-built-my-own-wood-boiler-monitor">Why I Built My Own Wood Boiler Monitor</h1>

<p>My brother Theo heats his place with an outdoor wood boiler in rural Alberta.
It’s a Central Boiler E-Classic 2400, sitting on a concrete pad about 20 meters (60 feet)
from the house. 1,287 liters (340 gallons) of water capacity, 76 kW (260,000 BTU/hr) max output. Two hydronic loops run from it - one to the house, one to
the barn - each with its own circulator pump. The house has a natural gas
furnace as backup, but it stays shut off when the boiler is running.</p>

<p><img src="/assets/img/owb/boiler_on_pad_wide.png" alt="The boiler on its concrete pad in winter" />
<em>The E-Classic 2400 on its pad, about 20 meters (60 feet) from the house</em></p>

<p>The problem is simple: when the fire goes out overnight, you don’t find out
right away. What happens is the furnace fan keeps blowing, trying to push heat
that isn’t there anymore. You wake up at 3am because the air coming out of the
vents is lukewarm and the fan hasn’t stopped running. Then you get dressed,
walk out in the dark at way below -30C (-22F), and reload the firebox.</p>

<p>It’s not catastrophic - between the boiler, the pipes, and the heat
exchangers, the system holds well over 1,287 liters of water at around 80C (176F).
That’s a lot of thermal energy. Everything is at least somewhat insulated, and
the house has natural gas backup if it gets really cold. But it’s the kind of thing
where you’d rather get a notification on your phone than find out because
you’re cold.</p>

<p>Theo asked if there was something that could just monitor the temperatures and
alert when things drop. I said I’d build one.</p>

<hr />

<h2 id="before-the-monitor">Before the monitor</h2>

<p>Theo tried pointing a WiFi camera at the boiler’s control panel to read the
temperature display remotely. It sort of worked, but the image was hard to
read, and it didn’t alert you when something was wrong. You still had to
remember to check.</p>

<p>The property runs on Starlink - surprisingly fast and
<a href="https://youtu.be/KsQL8Oq-ixI?si=pQhLACpfRLE8VMU7">more stable than you’d expect</a>,
but power outages happen more often out there than in town. When the power
goes, the internet goes with it. Any monitoring solution that depends on a
server in the house or a cloud service is only as reliable as the weakest
link in the chain - and there are a lot of links between a boiler in the yard
and a phone on a nightstand.</p>

<p>So whatever I built needed to work on its own. Read sensors, decide when
something is wrong, and send the alert directly - WiFi if it’s available,
cellular if it’s not.</p>

<hr />

<h2 id="the-build">The build</h2>

<p>I started about two months ago with a LILYGO T-SIM7080-S3 - an ESP32-S3
board with an onboard LTE modem for cellular fallback. A few DS18B20
temperature probes in stainless steel housings, and a CT clamp on each pump’s
power line. The temperature probes tell you what the water is doing. The
current clamps tell you whether the pumps are actually running. That was
Theo’s ask - temperatures and alerts. The pump monitoring was my idea. Seemed
like useful information to have.</p>

<p><img src="/assets/img/owb/owb_assembeled_without_case.png" alt="All the components laid out" />
<em>Work in progress - the LILYGO board, CT clamps, temperature probes, and wiring before assembly</em></p>

<p>The first version was bare minimum. Read sensors, publish to MQTT, send a
Telegram message when the supply temperature drops below a threshold. It
worked within a couple of evenings.</p>

<p>Then I kept going. Not because I had to - the basic version was already doing
what Theo needed. But each thing I added made it more interesting:</p>

<ul>
  <li>I wanted to change config without reflashing - JSON config on the filesystem</li>
  <li>I wanted to update firmware remotely - OTA updates over HTTPS</li>
  <li>I wanted flexible alert rules without recompiling - Lua scripting engine</li>
  <li>I wanted to see what’s happening live - web dashboard, MQTT for Home
Assistant, shell over serial and MQTT</li>
  <li>I wanted it to work on different hardware - a module system where each board
gets a different combination of sensors</li>
</ul>

<p><img src="/assets/img/owb/owb_in_case.png" alt="The board assembled in its waterproof project case" />
<em>Work in progress - assembled in a waterproof project case, ready to mount</em></p>

<p>Two months in, it’s a real firmware platform. Not because I planned it that
way - because each feature was fun to build and I could reuse it on the next
board.</p>

<p><img src="/assets/img/owb/owb_attached_sensors_at_boiler.png" alt="Sensors attached at the boiler" />
<em>Work in progress - temperature probes and CT clamps installed on the supply and return lines</em></p>

<hr />

<h2 id="what-i-learned">What I learned</h2>

<p><strong>WiFi reaches further than I expected.</strong> The boiler is in a sheet metal
enclosure, which I assumed would kill the signal. The LILYGO board sits
outside in a waterproof project case, and the WiFi signal is around -88 dBm -
on paper that’s terrible. In practice, it holds. I added the cellular module
expecting to need it for WiFi failures, but it mostly triggers during power
outages and Starlink hiccups instead.</p>

<p><strong>Cellular adds complexity.</strong> The IoT SIM costs about $15 a year for 1GB,
more than enough for telemetry. But the SIM7080 modem and its AT command
interface are finicky. Connection timing, registration delays, TLS handshake
quirks. I’d say a disproportionate amount of firmware time went into making
cellular reliable. Worth it for the fallback, but not free.</p>

<p><strong>Power outages are the real failure mode.</strong> Not WiFi, not the boiler itself.
When the power goes, everything goes - router, Starlink, the boiler’s own
circulation pumps. The board has a small LiPo battery - enough to send a “power is out” alert
and keep monitoring for a while until things come back or someone notices.</p>

<p><strong>Heap management on embedded is its own discipline.</strong> The ESP32-S3 has about
512KB of working memory (RAM) for everything - your code, your variables, your
network buffers, everything the program is actively doing. Once you add TLS
encryption, MQTT messaging, OTA update buffers, a Lua scripting engine, a web
dashboard, and a cellular modem driver, that memory gets fragmented. Think of
it like a parking lot where cars keep arriving and leaving - eventually you
have enough total space but not enough in one contiguous block for the next
car. The S3 also has 8MB of slower PSRAM which helps offload some of the
bigger allocations, but keeping things stable under sustained load is still a
work in progress. It works, but I wouldn’t call it solved.</p>

<hr />

<h2 id="is-this-a-product">Is this a product?</h2>

<p>No. It’s a hobby project that I built because I could and because my brother
was happy to let me try.</p>

<p>I’d already been working with the ESP32 platform on other projects, so the
tooling was familiar. Why not ESPHome or Tasmota? Both are great projects.
But honestly, I did it because I could. I wanted to build something from
scratch and this was a good excuse. Having full control over the networking
stack - standalone alerting over cellular, custom OTA, direct Telegram
integration - that’s a bonus. The real reason is that writing firmware is
more fun than configuring someone else’s framework.</p>

<p>The firmware grew into something more general along the way - I adapted it to
work with all the different boards I had laying around at home. A small
touchscreen display on the desk, an Ethernet-connected sensor node, a bare
dev board on the bench. Same firmware, different modules enabled per board.</p>

<p>There are commercial monitoring solutions out there - they work fine for most
people. But none of them did exactly what we wanted: standalone operation
without a cloud dependency, cellular fallback, flexible alerting, and the
ability to add whatever sensor makes sense next. So I built it.</p>

<p>As it evolved, I moved the firmware from a private repository to a public one
on GitHub. It’s not polished documentation-wise, but the code is there if
anyone wants to look at it or build on it. More of the project may follow as
things mature.</p>

<p>It’s a hobby. I build it in the evenings because I enjoy it.</p>

<hr />

<h2 id="whats-next">What’s next</h2>

<p>Right now the boiler monitor alerts every few days when nobody has loaded wood
and the supply temperature starts dropping. It’s more of a reminder than an
emergency - but that’s exactly what Theo wanted. It works, and it hasn’t
missed one yet.</p>

<div style="text-align: center;">
<img src="/assets/img/owb/thesada_bot_screenshot_cropped.png" alt="Telegram alerts on the phone" style="max-width: 240px;" />
<p><em>Work in progress - Telegram alerts showing temperature drops and pump power readings</em></p>
</div>

<p>The platform runs on a few different boards around the house for testing, but
the boiler is the one that matters. There’s a custom PCB in the works to
replace the dev board with something cleaner, and the firmware keeps getting
new features when I find an evening to work on it.</p>

<p>Next up is a well pump monitor. Last year we discovered a leak in the water
line from the deep well pump to the house - about 3 meters (10 feet)
underground. It was a mess. A current clamp on the pump would have shown the
duty cycle changing long before it became obvious. Same sensors, same
firmware, different location.</p>

<p>If you’re interested in the project, the firmware is on
<a href="https://github.com/Thesada/thesada-fw">GitHub</a>. For technical details on the
hardware and firmware, see the
<a href="https://thesada.io/modules/owb-monitor/owb-index">project documentation</a>.</p>]]></content><author><name>Foothills Builds</name></author><summary type="html"><![CDATA[How a cold house in rural Alberta turned into a custom ESP32 firmware project. The story behind thesada-fw.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://foothillsbuilds.com/assets/img/owb/boiler_on_pad_wide.png" /><media:content medium="image" url="https://foothillsbuilds.com/assets/img/owb/boiler_on_pad_wide.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Deploying a Jekyll Blog to Cloudflare Pages</title><link href="https://foothillsbuilds.com/blog/jekyll-cloudflare-pages/" rel="alternate" type="text/html" title="Deploying a Jekyll Blog to Cloudflare Pages" /><published>2026-04-07T00:00:00-06:00</published><updated>2026-11-29T19:06:15-06:00</updated><id>https://foothillsbuilds.com/blog/jekyll-cloudflare-pages</id><content type="html" xml:base="https://foothillsbuilds.com/blog/jekyll-cloudflare-pages/"><![CDATA[<h1 id="deploying-a-jekyll-blog-to-cloudflare-pages">Deploying a Jekyll Blog to Cloudflare Pages</h1>

<p>A static blog has no server to maintain, no database to back up, and no security patches to apply. You write markdown, push to git, and the site updates in seconds.</p>

<p>This post covers how this blog is set up: Jekyll with the just-the-docs theme, deployed to Cloudflare Pages from a (private) GitHub repository.</p>

<hr />

<h2 id="why-static">Why static</h2>

<p>WordPress needs PHP, a database, regular updates, security plugins, and a server that costs money to run. A static site like this blog needs none of that. The HTML is pre-built, served from a CDN, and costs nothing to host. For a technical blog where the content is guides and notes, static is the right choice.</p>

<h2 id="the-stack">The stack</h2>

<ul>
  <li><strong>Jekyll</strong> - static site generator (Ruby, mature, huge plugin ecosystem)</li>
  <li><strong>just-the-docs</strong> - clean documentation theme with search, dark mode, sidebar navigation</li>
  <li><strong>Cloudflare Pages</strong> - free hosting with automatic SSL, global CDN and GitHub integration</li>
  <li><strong>GitHub repo</strong> - source control (Cloudflare Pages works with private repos too)</li>
</ul>

<p>Total cost: $0/month, the personal domain is the only expense - But it also works with a free Cloudflare domain.</p>

<hr />

<h2 id="setting-up-jekyll">Setting up Jekyll</h2>

<h3 id="gemfile">Gemfile</h3>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">source</span> <span class="s2">"https://rubygems.org"</span>

<span class="n">gem</span> <span class="s2">"jekyll"</span><span class="p">,</span> <span class="s2">"~&gt; 4.3"</span>
<span class="n">gem</span> <span class="s2">"just-the-docs"</span><span class="p">,</span> <span class="s2">"~&gt; 0.10"</span>

<span class="n">group</span> <span class="ss">:jekyll_plugins</span> <span class="k">do</span>
  <span class="n">gem</span> <span class="s2">"jekyll-seo-tag"</span>
  <span class="n">gem</span> <span class="s2">"jekyll-feed"</span>
  <span class="n">gem</span> <span class="s2">"jekyll-sitemap"</span>
<span class="k">end</span>
</code></pre></div></div>

<h3 id="_configyml">_config.yml</h3>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="na">title</span><span class="pi">:</span> <span class="s">Your Site Title</span>
<span class="na">description</span><span class="pi">:</span> <span class="pi">&gt;-</span>
  <span class="s">One-line description for search engines.</span>
<span class="na">url</span><span class="pi">:</span> <span class="s2">"</span><span class="s">https://yourdomain.com"</span>
<span class="na">baseurl</span><span class="pi">:</span> <span class="s2">"</span><span class="s">"</span>

<span class="na">remote_theme</span><span class="pi">:</span> <span class="s">just-the-docs/just-the-docs</span>

<span class="na">plugins</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="s">jekyll-seo-tag</span>
  <span class="pi">-</span> <span class="s">jekyll-feed</span>
  <span class="pi">-</span> <span class="s">jekyll-sitemap</span>

<span class="na">permalink</span><span class="pi">:</span> <span class="s">/blog/:title/</span>

<span class="na">color_scheme</span><span class="pi">:</span> <span class="s">dark</span>
<span class="na">nav_enabled</span><span class="pi">:</span> <span class="kc">true</span>
<span class="na">search_enabled</span><span class="pi">:</span> <span class="kc">true</span>
<span class="na">back_to_top</span><span class="pi">:</span> <span class="kc">true</span>

<span class="na">footer_content</span><span class="pi">:</span> <span class="s2">"</span><span class="s">Your</span><span class="nv"> </span><span class="s">footer</span><span class="nv"> </span><span class="s">text"</span>
</code></pre></div></div>

<p>Note: use <code class="language-plaintext highlighter-rouge">theme: just-the-docs</code> for local development, switch to <code class="language-plaintext highlighter-rouge">remote_theme: just-the-docs/just-the-docs</code> for Cloudflare Pages deployment (Cloudflare doesn’t install gems from a Gemfile).</p>

<h3 id="robotstxt">robots.txt</h3>

<p>Drop this at the site root. Tells crawlers they can index everything and points them at the sitemap that <code class="language-plaintext highlighter-rouge">jekyll-sitemap</code> will generate at build time:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>User-agent: *
Allow: /

Sitemap: https://yourdomain.com/sitemap.xml
</code></pre></div></div>

<p>Jekyll copies it straight through to <code class="language-plaintext highlighter-rouge">_site/</code>. No plugin needed.</p>

<h3 id="directory-structure">Directory structure</h3>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>site/
  .gitignore
  Gemfile
  _config.yml
  robots.txt            # tells crawlers where sitemap lives
  index.md              # landing page
  blog.md               # blog index
  _posts/               # blog posts (YYYY-MM-DD-title.md)
  assets/img/           # screenshots, diagrams
</code></pre></div></div>

<h3 id="writing-a-page">Writing a page</h3>

<p>Every page needs a YAML header block (called “frontmatter”) between triple dashes at the top of the file. Jekyll uses it to set the title, layout, and more metadata:</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nn">---</span>
<span class="na">layout</span><span class="pi">:</span> <span class="s">default</span>
<span class="na">title</span><span class="pi">:</span> <span class="s2">"</span><span class="s">Page</span><span class="nv"> </span><span class="s">Title"</span>
<span class="na">description</span><span class="pi">:</span> <span class="s2">"</span><span class="s">Short</span><span class="nv"> </span><span class="s">description</span><span class="nv"> </span><span class="s">for</span><span class="nv"> </span><span class="s">search</span><span class="nv"> </span><span class="s">engines"</span>
<span class="na">nav_order</span><span class="pi">:</span> <span class="m">1</span>
<span class="nn">---</span>

<span class="c1"># Page Title</span>

<span class="s">Content in markdown.</span>
</code></pre></div></div>

<h3 id="writing-a-blog-post">Writing a blog post</h3>

<p>Posts go in <code class="language-plaintext highlighter-rouge">_posts/</code> with the naming convention <code class="language-plaintext highlighter-rouge">YYYY-MM-DD-title-slug.md</code>:</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nn">---</span>
<span class="na">layout</span><span class="pi">:</span> <span class="s">default</span>
<span class="na">title</span><span class="pi">:</span> <span class="s2">"</span><span class="s">Your</span><span class="nv"> </span><span class="s">Post</span><span class="nv"> </span><span class="s">Title"</span>
<span class="na">description</span><span class="pi">:</span> <span class="s2">"</span><span class="s">Post</span><span class="nv"> </span><span class="s">description</span><span class="nv"> </span><span class="s">for</span><span class="nv"> </span><span class="s">search</span><span class="nv"> </span><span class="s">engines</span><span class="nv"> </span><span class="s">and</span><span class="nv"> </span><span class="s">blog</span><span class="nv"> </span><span class="s">index"</span>
<span class="na">parent</span><span class="pi">:</span> <span class="s">Blog</span>
<span class="na">nav_exclude</span><span class="pi">:</span> <span class="kc">true</span>
<span class="nn">---</span>

<span class="c1"># Your Post Title</span>

<span class="s">Post content here.</span>
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">parent: Blog</code> and <code class="language-plaintext highlighter-rouge">nav_exclude: true</code> keep posts out of the sidebar navigation but listed on the blog index page.</p>

<hr />

<h2 id="local-development">Local development</h2>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bundle <span class="nb">install
</span>bundle <span class="nb">exec </span>jekyll serve <span class="nt">--host</span> 0.0.0.0 <span class="nt">--port</span> 4000
</code></pre></div></div>

<p>Browse to <code class="language-plaintext highlighter-rouge">http://localhost:4000</code>. Jekyll auto-rebuilds on file changes.</p>

<hr />

<h2 id="deploying-to-cloudflare-pages">Deploying to Cloudflare Pages</h2>

<h3 id="1-push-to-github">1. Push to GitHub</h3>

<p>Create a repository and push your site:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git init
git add <span class="nt">-A</span>
git commit <span class="nt">-m</span> <span class="s2">"initial site"</span>
git remote add origin git@github.com:you/your-site.git
git push <span class="nt">-u</span> origin main
</code></pre></div></div>

<h3 id="2-connect-to-cloudflare-pages">2. Connect to Cloudflare Pages</h3>

<ul>
  <li>Log into Cloudflare Dashboard</li>
  <li>Go to Compute &gt; Workers and Pages &gt; Create application &gt; Pages &gt; Connect to Git</li>
  <li>Select your repository</li>
  <li>Build settings:
    <ul>
      <li><strong>Framework preset:</strong> None (not Jekyll - the preset is outdated)</li>
      <li><strong>Build command:</strong> <code class="language-plaintext highlighter-rouge">bundle exec jekyll build</code> (see note below)</li>
      <li><strong>Build output directory:</strong> <code class="language-plaintext highlighter-rouge">_site</code></li>
    </ul>
  </li>
  <li>Environment variables:
    <ul>
      <li><code class="language-plaintext highlighter-rouge">JEKYLL_ENV</code> = <code class="language-plaintext highlighter-rouge">production</code></li>
    </ul>
  </li>
</ul>

<p><img src="/assets/img/build-settings.png" alt="Cloudflare Pages build settings" /></p>

<h3 id="3-custom-domain">3. Custom domain</h3>

<ul>
  <li>In Cloudflare Pages project settings &gt; Custom domains</li>
  <li>Add your domain (e.g. <code class="language-plaintext highlighter-rouge">yourdomain.com</code>)</li>
  <li>If DNS is already on Cloudflare, it auto-configures</li>
  <li>SSL is setup automatically - no manual cert management needed</li>
</ul>

<h3 id="4-first-deployment">4. First deployment</h3>

<p>Push any change to <code class="language-plaintext highlighter-rouge">main</code> and Cloudflare builds and deploys automatically. Typical build time: 30-60 seconds.</p>

<p><img src="/assets/img/build-success.png" alt="Deployment success" /></p>

<hr />

<h2 id="the-result">The result</h2>

<p>Push to main, site updates in under a minute. No CI/CD config, no server, no maintenance. 
The blog is a git repo with markdown files - version controlled, portable, and free to host.</p>

<p>Write it once, reference it whenever you need it.</p>

<hr />

<h2 id="what-id-do-differently">What I’d do differently</h2>

<p><strong>Commit your Gemfile.lock.</strong> I initially gitignored it and Cloudflare Pages resolved different gem versions than my local setup. The build ran but the theme didn’t load - just black on white text. Committing the lock file fixed it.</p>

<p><strong>Add descriptions from the start.</strong> Every page should have a <code class="language-plaintext highlighter-rouge">description</code> in the YAML header from day one. Going back and adding them to 30 pages later is no fun.</p>

<p><strong>Always use <code class="language-plaintext highlighter-rouge">bundle exec jekyll build</code> as the Cloudflare build command.</strong> I originally had <code class="language-plaintext highlighter-rouge">jekyll build</code>. The site built fine, but plugins declared in the Gemfile <code class="language-plaintext highlighter-rouge">jekyll_plugins</code> group silently did not load - I only noticed when <code class="language-plaintext highlighter-rouge">sitemap.xml</code> came back as the homepage HTML instead of a real sitemap. <code class="language-plaintext highlighter-rouge">bundle exec</code> pins the gem set from Gemfile.lock and activates the plugin group. If you use any plugins (sitemap, seo-tag, feed, archives), this is not optional.</p>

<p><strong>Don’t over-design.</strong> just-the-docs looks good out of the box, the dark theme, search, and sidebar navigation are built in. Spend time writing content, not customizing CSS.</p>]]></content><author><name>Foothills Builds</name></author><summary type="html"><![CDATA[How to set up a static Jekyll blog with the just-the-docs theme and deploy it to Cloudflare Pages from a GitHub repository. Free hosting, automatic SSL, basically zero maintenance.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://foothillsbuilds.com/assets/img/build-success.png" /><media:content medium="image" url="https://foothillsbuilds.com/assets/img/build-success.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry></feed>