an AlpineLinux image targeted at raspberry pi zero W for sonoff-diy autoflashing with Tasmota
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Paolo Asperti 0a5e95871c
FIX missing ACF httpdocs link
1 month ago
rootfs FIX missing ACF httpdocs link 1 month ago
LICENSE Initial commit 1 month ago
README.md added ACF 1 month ago

README.md

sonoff-flasher

An AlpineLinux image targeted at raspberry pi zero W for sonoff-diy autoflashing with Tasmota.

BIG FAT WARNING

** this is only a proof of concept, that’s no guarantee whatsoever that it’s working as intended **

** there’s a big chance to brick your device **

** as with anything that works with mains voltage, there’s also risk of injury **

** go on if you’re ok with all that, and also don’t blame me if something goes wrong **

installation instructions

requirements

  • internet connection
  • raspberry pi zero W (pay attention as the non-wifi version is very similar)
  • a small microsd card (1GB or more will go)
  • an USB to microUSB cable (to give power to the rPi)

instructions

  1. Download the AlpineLinux image for raspberry (armhf architecture) from here
  2. Format your microSD card as FAT32
  3. Unpack the downloaded AlpineLinux into the microSD card
  4. Copy all the files from this repo’s rootfs directory into the microSD card (you have to replace cmdline.txt with the new one when asked)
  5. unmount the card and place it into the rPi

usage

Power on the raspberry with the microSD card you just created and wait a minute for the OS to load.

It is imperative to have ewelink firmware >=3.1 !!! You can check current version in ewelink app. Sadly there’s no way to overcome this, for now. We don’t know if we need firmware >=3.1 AND ewelink registration OR firmware >=3.1 only. We haven’t found a single sonoff mini with stock firmware >=3.1.

Disconnect all the cables from your brand new Sonoff-mini, open it and insert the “DIY jumper” in the proper place. Close it, reconnect the wires and power it on.

In 2-3 minutes you should see a new wifi called “SONOFF-xxxx”, this is created by the newly-tasmotized sonoff-mini.

info on sonoff DIY mode

When you enable the “DIY mode” for a sonoff, you should create a new wireless network called “sonoffDiy” with password “20170618sn”, the sonoff connects with that network and you have the possibility to flash a different firmware using the “itead diy tool”.

More info on that procedure here.

how does this thing works

  • this tool creates the “sonoffDiy” wireless network (that’s why we need a zero-W) with DHCP and DNS
  • when a sonoff-mini connects, it assigns an IP address
  • it scans the network (via avahi-browser) to get the IP address of the sonoff and its ID
  • it the uses these informations to check if the sonoff is responding to zeroconf requests
  • if it does, it requests an “ota-unlock”: normally the firmware flashing is not enabled and when asked, the sonoff-mini “phones home” to signal that a OTA unlock has been requested for that specific ID.
  • we don’t have internet connection, so the raspberry tells the sonoff “I’m itead and you can enable OTA”
  • then the raspberry requests a firmware upgrade, telling the sonoff to pick the firmware directly from the raspberry webserver
  • the sonoff downloads the firmware, flashes it and reboots
  • we now have a new tasmotized friend! (you can remove the jumper now)

what to do next

As stated here we use the “sonoff-basic.bin” firmware (6.7.1) and it’s mandatory to issue a “reset 5” and flash the complete firmware (I usually flash the “sonoff-minimal.bin” and then the “sonoff.bin”).

more info

You can use your PC to power the raspberry, through the OTG port. If you do that, you have an emulated USB ethernet, with an IP address different from that on the wireless side.

SSH is enabled with root user and the default password is “root” (we need little to no security, as we won’t need the raspberry anymore after the flashing)

The IP address on the USB side is: 10.111.101.1

The IP address on the WIRELESS side is: 10.101.111.1

You can find a log of the flashing script in /var/log/flasher.log You can find dnsmasq logs in /var/log/messages

Everything is cleared at each reboot as the whole system is running from RAM. If you want to keep some modifications (e.g. an authorized_keys for ssh autologin) take a look at how it’s done here

ACF (Alpine Configuration Framework) is enabled and reachable via HTTPS (you must login with root credentials). From this web interface, you can restart services and take a look at the logs

current limitations

As of today, this is a very basic script. It has never been tested with two sonoff-mini at the same time, for example (and I’m very confident that this condition is not working). Maybe this works with Sonoff Basic R3 or Sonoff RF R3, it has never been tested. This tool is designed to work without internet connection so it hasn’t got access to different firmwares other than the 6.7.1 that is loaded onboard.