Category Archives: ESP8266

How to Install Tasmota on Shelly 1 from Linux

This guide will show you how to flash Tasmota firmware onto a Shelly 1 device using Linux. You will use the PlatformIO toolchain to communicate with the device, erase the existing firmware, and install the Tasmota firmware via serial communication. After flashing, you’ll configure the device to connect to your Wi-Fi and MQTT broker.

Prerequisites

  1. Linux PC
  2. Shelly 1 device
  3. USB to Serial adapter (e.g., FTDI adapter)
  4. Jumper wires to connect the Shelly 1 to the USB-to-serial adapter
  5. Tasmota binary downloaded to your local machine

Make sure that PlatformIO and Python 3 are installed on your system.

Step 1: Install PlatformIO

If you don’t already have PlatformIO installed, you can install it via Python’s package manager pip:

pip install platformio

This installs the platformio command-line interface (CLI), which will be used to flash the firmware onto the Shelly 1.

Step 2: Connect Shelly 1 to Your Linux PC

  1. Disconnect Shelly 1 from mains power to avoid electric shock.
  2. Connect the TX, RX, GND, and VCC pins of the Shelly 1 to the corresponding pins of your USB-to-serial adapter (TX->RX, RX->TX, GND->GND, VCC->3.3V). GPIO0 has to be temporary connected to GND to enter programming mode.
  3. Plug the USB-to-serial adapter into your Linux PC.
  4. You can now disconnect GPIO0 from GND or leave it as is.

Step 3: Test Communication with the Device

Before proceeding with the flashing, test whether your Linux PC can communicate with the Shelly 1 via serial.

Run the following command to check communication (replace /dev/ttyUSB0 with your actual serial device if needed):

python3 ~/.platformio/packages/tool-esptoolpy/esptool.py -p /dev/ttyUSB0 flash_id

If the communication is successful, you should see information about the connected ESP8266 chip inside the Shelly 1.

Step 4: Erase the Flash Memory

You have to reconnect the device to the pc as seen in Step 2.

Next, you need to erase the existing firmware on the device to ensure a clean installation of Tasmota. To erase the flash memory, run the following command:

python3 ~/.platformio/packages/tool-esptoolpy/esptool.py -p /dev/ttyUSB0 erase_flash

This process clears the current firmware from the Shelly 1.

Step 5: Flash Tasmota Firmware

You have to reconnect the device to the pc as seen in Step 2.

Once the flash memory is erased, you can now flash the Tasmota firmware onto the device. Replace the path ~/Downloads/tasmota.bin with the actual path to your downloaded Tasmota binary file:

python3 ~/.platformio/packages/tool-esptoolpy/esptool.py -p /dev/ttyUSB0 write_flash -fm dout 0x0 ~/Downloads/tasmota.bin

This writes the Tasmota firmware onto the Shelly 1.

Step 6: Configure the Device via Serial

After flashing, you can configure the Shelly 1 via serial connection using picocom. If it’s not installed on your system, you can install it with:

sudo apt install picocom

To open a serial connection, run:

picocom --echo --omap crcrlf --baud 115200 /dev/ttyUSB0

Once connected, you will see the device’s output. You can now paste the following configuration string to set up Wi-Fi and MQTT parameters:

Backlog ssid1 YourSSID; password1 veryStrongWiFiPassword; MqttHost 192.168.1.200; Template {"NAME":"Shelly 1","GPIO":[1,1,0,1,224,192,0,0,0,0,0,0,0,0],"FLAG":0,"BASE":46};

Parameters in the Configuration String:

  • ssid1: Replace YourSSID with the name of your Wi-Fi network.
  • password1: Replace veryStrongWiFiPassword with your Wi-Fi password.
  • MqttHost: Set this to the IP address of your MQTT broker (e.g., 192.168.1.200).
  • Template: This defines the GPIO pin mapping for the Shelly 1.

Step 7: Verify the Device Connection

Once the Shelly 1 reboots, it should connect to your Wi-Fi and MQTT broker based on the configuration provided. You can now control it via the MQTT interface or the Tasmota web interface.


Congratulations! You have successfully flashed and configured Tasmota on your Shelly 1 device from Linux.

Software install of Espurna on Sonoff Mini

UPDATE starting from firmware 3.5.0 it’s totally different, see http://developers.sonoff.tech/sonoff-diy-mode-api-protocol.html


It’s possible to flash Espurna on the Sonoff Mini using Diy mode via software.

What you need

  • A Sonoff Mini
  • A mobile device capable of creating an Access Point and which can install eWelink app
  • A PC:
    • with Wi-Fi
    • running GNU/Linux (I used Ubuntu 19.10)
    • with a running web server
    • with git installed

Procedure

Here’s the steps I took to do it:

  1. Download and compile Espurna

    $ mkdir ~/project
    $ cd ~/project
    $ git clone https://github.com/xoseperez/espurna
    $ cd espurna/code
    $ pio run -e itead-sonoff-mini
    
  2. Install and configure eWelink app

  3. Update Sonoff Mini firmware (currently the latest version is 3.3.0, I’ve read you need 3.1.0 at least)

  4. Shutdown the device (detach it from mains current)

  5. Enable OTA OTA port
  6. Create an Access Point with your phone. These must be the parameters:
    • SSID: snonffDiy
    • pre shared key (password): 20170618sn
    • band: 2.4 GHz
  7. Boot the device (attach it to mains current)
  8. Wait until it connects to the AP (the blue led double pulses)
  9. Connect the PC to the same Wi-Fi
  10. Search for the Sonoff Mini device on the Wi-Fi network

    $ avahi-browse -t -r _ewelink._tcp
    + wlp1s0 IPv4 eWeLink_10009b8ed6                            _ewelink._tcp        local
    = wlp1s0 IPv4 eWeLink_10009b8ed6                            _ewelink._tcp        local
       hostname = [eWeLink_10009b8ed6.local]
       address = [192.168.43.200]
       port = [8081]
       txt = ["data1={"switch":"off","startup":"off","pulse":"off","pulseWidth":500,"rssi":-29}" "seq=1" "apivers=1" "type=diy_plug" "id=10009b8ed6" "txtvers=1"]
    

    Keep track of the deviceid which is, in my case, 1009b8ed6.

  11. Test if everything works as expected

    $ curl -XPOST --data '{ "deviceid": "10009b8ed6", "data": {} }' http://192.168.43.200:8081/zeroconf/info; echo
    {"seq":2,"error":0,"data":"{\"switch\":\"off\",\"startup\":\"off\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"sonoffDiy\",\"otaUnlock\":false}"}
    
  12. Unlock OTA updates

    $ curl -XPOST --data '{ "deviceid": "10009b8ed6", "data": {} }' http://192.168.43.200:8081/zeroconf/ota_unlock; echo
    {"seq":2,"error":0}
    
  13. Put file in a web server

    $ cd ~/public_html
    $ cp ~/project/espurna/code/.pio/build/itead-sonoff-mini/firmware.bin .
    $ chmod a+r firmware.bin
    
  14. Test url

    $ curl -s http://192.168.43.53/~max/firmware.bin --output - | sha256sum
    e9e7d72d2c2a8b25678cab7ded20645c5e37c60459cbe6ba1448ed3a62f72b72
    $ sha256sum ~/public_html/max/firmware.bin
    e9e7d72d2c2a8b25678cab7ded20645c5e37c60459cbe6ba1448ed3a62f72b72  firmware.bin
    

    You will need the sha256sum value in a minute.

  15. Do the OTA, keep attention to use the right deviceid, sha256sum and ip values

    $ curl -XPOST --data '{ "deviceid": "10009b8ed6", "data": { "downloadUrl": "http://192.168.43.53/~max/firmware.bin", "sha256sum": "e9e7d72d2c2a8b25678cab7ded20645c5e37c60459cbe6ba1448ed3a62f72b72" } }' http://192.168.43.200:8081/zeroconf/ota_flash; echo
    {"seq":3,"error":0}
    

Done.

References