Small software and fun with an ESP8266

Body

I enjoy building small, self-contained software for the pure joy of simplifying what you build. Building complex software is easy; small and maintainable software is not (not always anyway).
To take that same vein of thought, I have been working on a floppy-sized Linux distro (fluxflop) for the pure fun of how small I can build the Linux kernel, while keeping it usable. Running make tinyconfig is easy enough, but how small can you truly make the kernel? 

In my quest to find any resources on this, I stumbled upon Linux Tiny. It's a set of patches (with the intention of getting the patches merged into mainline to make future builds easier) that can slim down the kernel and add additional Kconfig options for reducing the compiled size. The project has not been updated since approx 2007 and uses Linux 2.6.23.0. Backporting these patches (whats the opposite of backport with newer software? haha) would take time and it's not guaranteed that the patch intention would work the same. Well, with too much time on my hands, I dug deep and did just that. You can see the git repo here with updated patches for Linux 6.9. Now, they are not guaranteed to work for everyone and every arch, but for i386 I was able to shave off about ~80KB which doesn't seem like much, but it all adds up in the end. For fluxflop, I was able to trim bzImage down to 712KB, and an aarach64 kernel down to about 820KB. 

I found this presentation that Matt Mackall gave in 2004 for the introduction of Linux Tiny. In the slides, it is mentioned that the Linux kernel produced, with net, EXT2, a NIC (not mentioned which one) and IDE, was 363KB! Very impressive. For my project, that 712KB is without /dev/ram, no filesystems, network capabilities, VGA and not even PS/2. All over serial too, so good luck having it be any use on a desktop box. Still, this is something to aim for. I would be curious to replicate the results in the presentation to build a 720KB floppy-sized Linux distro.
 




Two years ago this summer, I purchased an ESP8266 from Aliexpress for less than $5 CAD. As well, as DHT11 air sensors and a capacative soil moisture sensor. Somehow all the parts have been sitting in a drawer all this time, and I finally got around to building something. Microcontrollers of this nature, including the Arduino, have never interested me very much and I think it's due to having no real-world application of them. Living rurally as I do now, having a wifi weather station connected at home is mostly useless. You can just look out side and look up. Sure, having a forecast of the weather of the days or weeks to come can be productive to plan gardening or hiking in the forest, but it doesn't really matter too much. I find that out here, time ceases to exist. It is either daytime or nighttime. You wake up when the sun rises, and go to bed a few hours after sunset. Working remotely has given me the ultimate freedom in my life in that regard, and I am thankful. Except for 9am standups.

Anyway, plugging the sensors into a breadboard and writing some Python code for the ESP8266 was exhilarating. I realized how much I have missed working with electronics like this, using ICs and DIP switches and doing the calculations to find the resistance of a resistor. Through some thorough reading of MicroPythons documentation (which is fantastic by the way), I was able to flash MicroPython, get a working REPL accessible over wifi and start building.

What I built was a very simple weather station. From the DHT11 sensor, I receive the air temperature and humidity. There is no precision to it and readings are output in whole numbers. Not that I needed to know if it was 11C or 11.1C outside anyway. Using the capacative soil sensor, I was able to read from the output voltage using the AD0 pin. 

Power usage is the next task to complete. My ESP8266 has a built in micro USB port which is very convenient for using off the shelf phone battery packs. From some quick research, it seems that with the board running + wifi I could expect around 65-80mA. Using deepsleep I could expect around 20mA which is impressive, but not sure if it's possible using the built-in linear regulator the micro USB port uses. Regardless, at 75mA consumption and using a 9000mAh battery pack, I could expect around 120 hours. Which doesn't seem like very much, but that is having the board on the entire time. I have some more configuring to do, and build a nice case out of it so I can actually put outside (and most likely forget about it in my yard somewhere).


 


Reading from sensors isn't enough in 2024. No, you must log data, send network requests and have other companies store your precious data. So like any sane person, I did just that. Using the Adafruit IO platform, they offer an easy way for storing and building pretty dashboards for your IoT boards.


 

I had a lot of fun building something that was a bit hardware and a bit software. And all for less than $10 which is staggering. I can see why these boards are so popular ;) 


You can download the source code to my boot.py here: https://geekness.eu/sites/default/files/boot.py



 

Tags
Attachment Size
boot.py_.txt (3.23 KB) 3.23 KB