ESP8266/ESP32 libraries released! LeifESPBase, LeifESPBaseHomie, LeifHomieLib

Tags: #<Tag:0x00007f386d1388d0> #<Tag:0x00007f386d138790>

@rak, @Fa_Bien, @epicurean, @JGKK

Holy crap that was a lot of work. I spent all of today cleaning up, refactoring and testing my framework code, turning them into a proper libraries with example sketches and everything. I even made sure it compiles in the Arduino IDE, with both ESP8266 and ESP32!

I named the libraries after myself to avoid naming collisions and to not have to spend too much time thinking up names. Please feel free to rename your local copy :wink:

So, what do we have?


Light weight homie v3 (MQTT) Library for ESP8266 and ESP32

No documentation yet but does have an example sketch!

It doesn’t have every homie feature but is well matched with openHAB.




Base library for ESP8266/ESP32

Provides HTTP server, mDNS, simultaneous serial and telnet console output (for debugging), OTA update.

It is designed for use by programmers.

For example, SSID, Password, host name are hardcoded and not settable from any user interface.

These and other things were conscious design decisions that reduce code complexity and resource requirements.

It’s designed to help in the construction of purpose-built specialty devices. It is not designed to build user-configurable devices.

As a programmer, I will always have a development environment set up and ready to upload new code to my devices through OTA.

This library depends on several great libraries listed below, which do most of the actual work. I am not claiming any ownership of those - LeifESPBase just ties them together.

Enter your WiFi SSID/key to environment_setup.h

Dependencies here:

dependencies (ESP32)


dependencies (ESP8266)


And finally:


This ties both LeifESPBase and LeifHomieLib together to form the basis of a homie-capable ESP8266 or ESP32-based device!

Enter your WiFi SSID/key to LeifESPBase\environment_setup.h
Enter your MQTT credentials to LeifESPBaseHomie\environment_setup.h

All three can be found on my github account.

I’m absolutely beat. But, tomorrow I will update my existing production projects (such as BedroomMCU) to use these libraries (rather than the pre-refactoring individual cpp files), and then release the ones people may be interested in. It’s not worth putting those on github – they are tailor-made for their duties here, but I can release them as zip files for reference. Then I’d better take a break from openHAB and get some “real work” done for a change. :slight_smile:


Big thank you. I will be able to look into this the next weekends. Well done.

1 Like

You the man! Thank you

1 Like

Yes thank you for doing the work and sharing it. Just have a quick question and that is does LeifHomieLib allow you to setup in AP mode so the wifi credentials don’t need to be hardcoded into the source and allows you to connect with a phone and setup the wifi details that way?

Is there a reason why you did not just use the esp32 V3 version of this project?


Thx for sharing!

1 Like

Well, I had already started on LeifESPBase (as separate source files) before I even started using openHAB and before learning about MQTT and Homie… but a couple of weeks ago when I knew I needed to make my devices homie compliant, I did actually look into the homie V3 version of that exact project. And there’s a very good reason why I didn’t end up using it: It instantly crashed for me when I tried it. :slight_smile:

So why didn’t I debug it?

  • It was bigger than I wanted. The compiled size of the demo project was something like 550 KB, which would not fit on a 1MB ESP-01 if you want OTA.
  • The Homie V3 version of the library was in the middle of development, and it looked like it had been in development for a few months already. If it was a matter of a missing feature I might have been able to dive in and help, but the fact that it was instantly crashing means I never saw it do anything useful, and that’s not a good entry point for a volunteer. Also, why would it take several months to release?? The spec looked simple enough, I figured I could make something in a weekend! Little did I know.

So, in the end I figured “How hard can it be!” and started writing my own homie library. Famous last words…

Anyway, it’s hopefully good for the community that there’s another library publically available. This way, if someone else has my particular set of needs, there’s something available to fill them. :slight_smile:

By the way, LeifHomieLib is not in any way dependent on LeifESPBase.

It doesn’t, because, what would that alone gain? There are so many other things that would need to be configured… like the pin assignments for hardware… or what the device should be doing at all. I could spend 10 or even 100 times the amount of time to make an infinitely configurable device, and end up with something that won’t fit even on 4MB flash…

…or, simply realize that there is already a user interface that lets you configure ALL of these things and more… Drumroll… It’s the Arduino IDE. Or, Sloeber once you’ve outgrown that.

I once read something interesting, might have been a geek comic or a programming blog. Something to the effect of:
“As frameworks grow excessively and become more and more extensive and bloated, inevitably they start resembling a bleak copy of the development environment used to create the framework.”
I tried finding it again now and couldn’t… but it is one of the truest adages about programming I have ever come across. It’s just a matter of where you draw the line. When I develop a proprietary app, obviously that line is all the way up in the sky. The app has to be able to handle all target use cases by reconfiguration.

For a microcontroller, for me, the line is all the way down at the floor. I’m a programmer. I’m okay with recompiling it for every little thing, as long as I can OTA it to the target device.

Great! Thank you for all these details!

1 Like

Thanks for the info, now I know if I want a stripped back version of Homie that still allows OTA updates to check yours out and what the main differences are as I have never used any form of Homie before. Keen to give it a try when the right project comes along… There are many ways to approach a project and it is great to have another library with which to choose, so thanks heaps :+1::+1: My post was purely for this reason to help select which library to use.

I often program for other people who are not programmers so I have to make choices about which way suits the projects goals the most. I’m sure you understand that, so there is no point saying more.

1 Like

Me too, usually! Not this time though. It is REFRESHING, I tell you! :joy:

By the way, it allows OTA updates but only through the development environment – NOT through Homie!

FancyButton library released!

This is what handles all my 433 MHz remotes.
I spent most of the day writing a detailed example sketch.

@rak, @Fa_Bien, @epicurean, @JGKK

And, now that the underlying libraries are public, here is the full BedroomMCU project source code!

This is the source code for my air conditioning controller which I showed off here.

Please note that this is a Sloeber project. It will not build in the Arduino IDE.
It fact, I wouldn’t bother trying to build it – it’s not going to be useful beacuse it’s a completely custom project, designed for exactly the combination of hardware and appliances I have here. It can however be useful as a reference, to look at for ideas, and it is in that spirit alone that I am releasing it here. I’m not putting it on github because it needs no further development – it is finished and in service.

I may modify it to use the TFT_eSPI library later but that won’t affect actual functionality.

Modified BedroomMCU to use TFT_eSPI. Screen updates are now INSTANT.

Also changed to an RLE format for the font so less memory is used as well. :slight_smile: