Compile a custom firmware for ESP8266 (Tasmota, ESPurna etc.) with Atom

7 minutes of reading
AIMS OF THE GUIDE
  • Complete the firmware using the Atom software Sonoff-Tasmota, thus making it installable on a compatible device based on SOC ESP8266 (ITEAD Sonoff and similar)
  • Difficulty level: bass
CONCEPTS FACED:
  • Software compilation
SOFTWARE COMPONENTS USED:
Prerequisites
  • an adapter USB / TTL and its USB connection cable (optional)
PHYSICAL DEVICES USED:
  • A computer (Apple, Windows or Linux).
GUIDE more indicated for:

All environments

Notes and disclaimer
  • qualsiasi modifica all'impianto elettrico dev'essere effettuata da personale qualificato;
  • any changes implemented in probefore is a propersonal responsibility as well as a profirst risk and danger (this guide is for educational purposes only);
  • any changes implemented in probefore a device will void the warranty.
Driving review: 1.0

CAUTION: this guide is part of MasterGuide inDomus dedicated to riprodevice weighting based on ESP8266 SOC.

Abstract

As is well known, devices based on SOC (System-On-A-Chip) ESP8266 (those of the family ITEAD Sonoff "Smart Home”, rather than of the Shelly "Home Automation Systems " and many others) can be changed in terms of firmware, or in the portion of software that decrees the functionnameand expresses its functions.

ESP8266
the ESP8266 SOC.

To make this firmware modification broadly it is necessary, in the order:

  • connect the computer to the device (via an ad hoc device called USB / TTL or FTDI);
  • set the device in "flash" mode (a specific mode that allows overwriting, in its internal memory);
  • upload the firmware to the device.

To be "loaded" on the device, this custom firmware must be in binary format, a single file (usually with extension ". Bin"). To acquire this binary file it is necessary fill in the firmware source code via, appanointed, a compiler.

This guide shows first of all how to install and configure free software Atom, while in the second instance it illustrates how to compile various firmware. for SOC ESP8266.

It starts

Install and configure Atom

ATOM LogoAtom it is, first of all, a text editor very powerful and versatile. Its peculiarity lies in the fact of being modulate, or provides the ability to install a series of additional packages, including those needed to compile firmware / software, write code in different languages ​​and much more.

That's why inDomus adopts Atom as a favorite editor: not only is it useful to compile firmware, as we will see, but it is also excellent as an editor for configuration files related to HUB home automation and much more.

Atom you download for free (for Windows, macOS and Linux) from the site https://atom.io/.
Once downloaded, install like any freeware available from the Internet.

For the purposes of this guide it is necessary, once installed and executed, install an additional package called "platformhyoid".

To go to:

  • su Windows, Menu : File > Settings > install
  • su macOS, Menu : To Tom > Preferences > install
  • on Linux, Menu : Edit > Preferences > install

and in the search hole search, for theappanointed, "platformhyoid". Once you find the package, click on "Install".

ATOM install packages
scroll to zoom

After successful installation close and reopen Atom, which at this point prowill install a series of integrative packages completely automatically.

At the end, PlatformIO will ask to restart for a last time Atom.

COM port

An adapter USB / TTL (FTDI) is the simple device that allows us to put in communication our computer and the heart of the ESP8266 SOC based device.

Without need, for the moment, to connect this device to the one to reprogramming, proinstead look to connect the latter (via USB cable) to our computer. If drivers are required, prosee the installation.

Then select the Atom menu item PlatformIO > Serial Monitor.
A fi will opennestas follows:

After a moment, in the entry "Port (The Harbour District)”Will indicate which COM port the computer has assigned to the USB / TTL module.
Take note of it.
Now disconnect the module from the USB port.

NOTE for users Apple: Atom should identify a different port than the classic COMx. To understand how to configure the door in this series, refer to to this thread. Beyond what is expressed in the link, always remember to install the correct driver for Mac the profirst USB / TLL adapter.

After installing the correct driver, in the system report of the Mac, under USB, you will need to (by connecting the USB / TTL adapter) a voice similar to the one below:

FT232R on MacCompile the firmware

Sonoff-Tasmota

"Re”Unchallenged among the custom firmware dedicated to home automation components based on ESP8266 SOC, Sonoff-Tasmota allows to introduce a large number of features and customizations, Among which proadditional communication packages, external sensor management and much more.

At each new version release, Sonoff-Tasmota is released already pre-filled for all those who want to limit themselves to update a previous version already installed (using OTA support - wireless - maybe using TasmoAdmin); those who have to install instead Sonoff-Tasmota on a device for the first time, then they will necessarily have to profollow in the reading and acquire - using the Atom compiler - a profirst file . Bin.


To configure and compile the firmware Sonoff-Tasmota it goes first of all downloaded. It's possible to do it directly from the Git pageHub the projet; once downloaded, you need to unzip the zip file where you prefer.

At this point, at Atom, select the menu item "Fillet > add Project Folder"And then select the folder where the .zip file has previously been decompressed and contains the firmware code Tasmota.

At this point it is possible to "configure" the software package, a configuration that will naturally end inside the binary file prolearned from compilation and, with him, on the device. Tasmota it is in fact supplied "basic", without customizations, which are necessary so that, at the end of the programmation, the ESP8266 SOC based device can operate correctly.

Specifically, the proprocess is the following:

  • configure the file "platformio.ini";
  • configure the file "sonoff/my_user_config.h";
  • compile the firmware.
platformio.ini

What we are going to first customize is the file "platformio.ini".

The first item to configure is "env_default": This entry communicates to the compiler which portion of the code to compile based on the needs. That item cannot not be configured, under penalty of being filled out.

The choice can be made based on the available list which, by default, is all "commented" (all lines have the prefix "#"). It is enough to remove one of the "#”(Relative to the interest line) to make operational, at compilation, the corresponding portion of code.

In the following example we configure the more traditional and standard environment, that is “env_default = sonoff"

scroll to zoom

The items commented below identify the alternatives, namely the compilation or a minimal part of the firmware (“env_default = sonoff-minimal") Or full language versions ("env_default = sonoff-E"Is the Italian one), or the standard one (appanointed, as suggested above, "env_default = sonoff“).

Then find the section "[Core_active]”And configure it as follows:

[core_active]
; Select one core set for platform and build_flags
platform                  = ${core_2_3_0.platform}
build_flags               = ${core_2_3_0.build_flags}
;platform                  = ${core_2_4_2.platform}
;build_flags               = ${core_2_4_2.build_flags}
;platform                  = ${core_2_5_0.platform}
;build_flags               = ${core_2_5_0.build_flags}
;platform                  = ${core_stage.platform}
;build_flags               = ${core_stage.build_flags}

this will ensure that the firmware is compiled using the PlatformIO core platform version 2.3.0, that compromore stable (especially in avoiding continuous disconnections Wi-Fi by the device, a phenomenon that sometimes occurs when using other higher core versions).

Find it then the following items (e appurare are configured as follows:

monitor_speed             = 115200
upload_speed              = 115200
upload_resetmethod        = nodemcu

Immediately follow, identify the item "upload_port =") And enter the identifying COM as a value, which can be expressed

su Windowsupload_port = COM1
su macOS / Linuxupload_port = /dev/cu.usbserial-00000000

Then configure the COM assigned at the entry "upload_port =", Obviously indicating the door and discovery in the previous step.

Nb In case the destination of the compiled binary file is an updatenameOTA (Over-The-Air), this step of configuring the item “upload_port ="Can be skipped.

Once everything is complete, save and close the file.

sonoff/my_user_config.h

Now you need to configure name and password of Wi-Fi in which the device must enter automatically when it is turned on.

Open the file "sonoff/my_user_config.h"And find the items" #define STA_SSID1" and "#define STA_PASS1"

scroll to zoom

Enter the name there was originally the proman Wi-fi (in the first item) and the related one password (second item).

Finally, save and close the file.

COMPILATION

Now we are proto "compile" our firmware package.

At Atom, click on the menu "Platform > Build"
In case everything goes well, the procedura should proto produce an output of this type:

scroll to zoom

At this point the file (called "firmware.bin") Will have been generated at the computer's file system, at the location"% directorycontenentetasmota/.pioevens/sonoff"

This file rappresets the "completed" of the custom firmware Sonoff-Tasmota, pronow being installed on the device.

Espurna

To configure and compile the ESPurna firmware, it goes first downloaded. It's possible to do it directly from the Git pageHub the projet; once downloaded, you need to unzip the zip file where you prefer.

At this point, at Atom, select the menu item "Fillet > add Project Folder"And then select the folder"/ code”Contained in turn from the folder where the .zip file was previously decompressed.

At this point it is possible to "configure" the software package, a configuration that will naturally end inside the binary file prolearned from compilation and, with him, on the device. Tasmota it is in fact supplied "basic", without customizations, which are necessary so that, at the end of the programmation, the ESP8266 SOC based device can operate correctly.

Specifically, the proprocess is the following:

  • configure the file "platformio.ini";
  • configure the file "espurna/config/general.h";
  • compile the firmware.
platformio.ini

What we are going to first customize is the file "platformio.ini".

The first item to configure is "env_default": This entry communicates to the compiler which code environment to compile based on the needs. That item cannot not be configured, under penalty of being filled out.

To decide which environment to indicate, it is necessary to scroll the file to the entry

# ----------------------------_
# ESPURNA CORE BUILDS
# -----------------------------

ESPurna supports many, different types of devices: the following blocks "ESPURNA CORE BUIDS"Identify the various devices, and the key included in" [env:] "in the block of prointerest is the one to be indicated at “env_default"

For example, the block that identifies the "Sonoff Basic" starts with

[env:itead-sonoff-basic]

therefore, to make the compilation generate a track related to this device, the entry "env_default"Will be configured like this:"env_default = itead-sonoff-basic"

Chosen the device and therefore the key to insert in the voice "env_default", it is necessary save and close the file.

Espurna / config / general.h

Now you need to configure name and password of Wi-Fi in which the device must enter automatically when it is turned on.

Open the file "Espurna / config / general.h"And find the following block:

// Optional hardcoded configuration (up to 2 networks)
#ifndef WIFI1_SSID
#define WIFI1_SSID                  ""
#endif

#ifndef WIFI1_PASS
#define WIFI1_PASS                  ""
#endif

e prosee insert, between the apices of the entries “#define WIFI1_SSID" and "#define WIFI1_PASSRespectively the name of the proRPIA Wi-Fi and the related password.

Finally it is necessary save and close the file.

COMPILATION

Now we are proto "compile" our firmware package.

At Atom, click on the menu "Platform > Build"
In case everything goes well, the procedura should proto produce an output of this type:

Platformer ESPurna
scroll to zoom

At this point the file (called "firmware.bin") Will have been generated at the computer's file system, at the location"% directorycontenentetasmota/.pioenvs/nome-dell-environment-compilato/firmware.bin"

This file rappresents the "compiled" of the ESPurna custom firmware, pronow being installed on the device.


ITEAD Sonoff BasicATTENZIONE: remember that there is on our FORUM community an ad hoc section dedicated to Sonoff (and more generally to devices ESP8266), for any doubt, question, information on the specific merit of these components.


Please comment below