ESPHome community plugin

tprelog

Patron
Joined
Mar 2, 2016
Messages
291
I'm going to remove the ESPHome community plugin from TrueNAS CORE.

Well, life got in the way and I completely forget about this until @duffel99 opened an issue on GitHub.

The good news is, we managed to get the ESPHome plugin working again (at least for now)

TLDR

The main problem is that ESPHome relies on platformio to compile firmware for the ESP devices. For this to work in our jails, platformio downloads certain libraries made for FreeBSD however updated version are no longer provided.

Code:
PackageManager: Installing toolchain-xtensa @ ~2.40802.191122
Error: Could not find a version that satisfies the requirement '~2.40802.191122' for your system 'freebsd_amd64'


Code:
Tool Manager: Installing platformio/toolchain-xtensa32 @ ~2.50200
Error: Could not find the package with 'platformio/toolchain-xtensa32 @ ~2.50200.0' requirements for your system 'freebsd_amd64'


If anyone is actually familiar with FreeBSD (beyond using jails on TrueNAS CORE) or maybe just building software from source in general, it may be possible to compile these missing toolchains yourself. I think most people using this plugin (myself included) will find it is easiest to just run ESPHome on something else.


Saving the ESPHome config

Don't worry, at least you'll be able to save your config

The directory (inside the jail) that you'll need to back-up is /var/db/esphome - You can also find this directory from your TrueNAS host -- For example, if the name of your ZPOOL is tank and the JAIL_NAME is esphome, the path would be /mnt/tank/iocage/jails/esphome/root/var/db/esphome

Copy everything inside this directory to a new location before you destroy the plugin's jail.
 
Last edited:

tyme

Cadet
Joined
Jun 23, 2021
Messages
3
I preferred to keep it in a jail, but for now I decided to just create an Ubuntu vm in Truenas with docker and installed the esphome docker container
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
291
FWIW, I managed to compile the correct version of toolchains using these ports by @trombik

- https://github.com/trombik/freebsd-ports-esp-quick-toolchain/tree/main/devel/esp-quick-toolchain
- https://github.com/trombik/xtensa-esp32-elf/tree/devel/devel/xtensa-esp32-elf

I uploaded the pre-compiled toolchains to a detached branch in the ESPHome plugin repo. Here's some manual instructions to update the ESPHome community plugin so it works again.

Log into the jail and install some new dependencies
Code:
iocage console $JAIL_NAME
# Press 1 to exit the menu
pkg install -y hash rust


Download and install the pre-compiled toolchains for ESP8266 and ESP32
Code:
#  toolchain-xtensa - ESP8266
fetch https://github.com/tprelog/iocage-esphome/raw/toolchains/toolchains/toolchain-xtensa-FreeBSD.12.amd64-2.40802.191122.pkg
pkg install -y toolchain-xtensa-FreeBSD.12.amd64-2.40802.191122.pkg

# toolchain-xtensa32 - ESP32
fetch https://github.com/tprelog/iocage-esphome/raw/toolchains/toolchains/toolchain-xtensa32-FreeBSD.12.amd64-2.50200.0.pkg
pkg install -y toolchain-xtensa32-FreeBSD.12.amd64-2.50200.0.pkg


Now switch to the esphome user and remove the existing .platformio/packages directory
Code:
su - esphome
rm -rf ~/.platformio/packages


Next create an empty .platformio/packages directory and cd into it
Code:
mkdir -p ~/.platformio/packages
cd ~/.platformio/packages


Finally create the links to the installed toolchains
Code:
#  toolchain-xtensa
ln -s /usr/local/esp-quick-toolchain-gcc48/xtensa-lx106-elf .

#  toolchain-xtensa32
ln -s /usr/local/xtensa-esp32-elf-idf3 toolchain-xtensa32
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
291
By now the updated requirements have made it to the plugin manifest for the 12.2-RELEASE, and I've also updated the plugin to use the toolchains I compiled. A clean install of the ESPHome plugin should (at least for now) compile both ESP8266 and ESP32 firmwares out of the box.

---

For an existing plugin, running a Plugin UPDATE from the TrueNAS UI should also work - but may require some additional steps. If the ESPHome service fails to start after a Plugin UPDATE, you'll need re-create the ESPHome virtualenv. This can easily be done from the jail's console menu.

Use number 7 to remove

1631887346870.png



When the virtualenv is removed, number 7 will change to install

1631884111126.png


EDIT to update screenshot after I noticed / fixed a small bug
 
Last edited:

Mitaka

Cadet
Joined
Dec 24, 2021
Messages
1
I have this problem with esp8266, esp32 works fine
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    187.5 KB · Views: 178

tprelog

Patron
Joined
Mar 2, 2016
Messages
291
Hi @Mitaka - I need to stress, I'm really taking a guess here...

In my experience, these type of errors are typically caused by the jail using a FreeBSD release that is past EOL, or at very least needs updating.

Can you please say what TrueNAS version you have installed, and also what release your plugin is at?
1640361670652.png


I'm not running TrueNAS CORE atm, so best I can do is a quick test in a VM - I can confirm, at least on clean install, ESP8266 compiles without any errors. If your jail is not on the latest release, my best guess is that updating the jail would help.

On a related side note... It's sad to say, for as long as I've been maintaining plugins, I still don't have a complete understanding of how jail/plugin updates are supposed to work from the UI. Personally, I've alway found it easiest to just install another plugin, then migrate my config. If the new plugin works, I delete the old one and go on with life. I only spend time troubleshooting when something is broke for a clean install.
 

Myka

Cadet
Joined
Oct 21, 2016
Messages
9
I getting an error about missing pre-compiled toolchains does anybody know if there is an easy way to download an update for it?

INFO Reading configuration /var/db/esphome/sonoff-piano.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing iot-piano (board: esp01_1m; framework: arduino; platform: platformio/espressif8266 @ 3.2.0)
--------------------------------------------------------------------------------
Tool Manager: Installing platformio/toolchain-xtensa @ ~2.100300.0
Error: Could not find the package with 'platformio/toolchain-xtensa @ ~2.100300.0' requirements for your system 'freebsd_amd64'
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
291
Hi @Myka - The updated toolchains need to be compiled from source.

Last time, I made a separate jail to run portshaker and used these ports. esp-quick-toolchain is the one used for esp8266

I'll try to spin up a TrueNAS CORE VM this afternoon to see if I can compile the new toolchain and update plugin again

---

I should also mention I've added the following warning to all the TrueNAS CORE community plugins I made, including ESPhome

At this time I am no longer using TrueNAS CORE or any iocage jails. As a consequence I may not be aware of, and proactively fixing any issues that could arise. If you're having trouble with the installation of this plugin you can still open an issue and I will do my best to help. While no further development is currently planned, I will continue trying to support this plugin for as long as it remains feasible.

Of all my plugins, ESPHome has the highest risk of being removed mainly because of these toolchain updates.

---

UPDATE: I recompiled the latest version of esp-quick-toolchain from trombik's port. Unfortunately it's still not the correct version ESPhome is looking for. I'll keep an eye on it for the next week or two, and try again if there is an update to the port. But it may just be the end of the line for this plugin unless someone wants to take it over before TrueNAS CORE 13 is released. March thru June is a busy time of the year at work and I'm not going to have much time for trying to compile these toolchains as needed.
 
Last edited:
Top