Flash Tasmota to Sonoff using Raspberry Pi
I'm using a Raspberry Pi to flash the firmware. I find this simplier that using a USB TTY device plus I also have a number of Raspberry Pi's laying around.
Prerquisite
Install PIP
apt install python3-pip sudo pip3 install esptool
Change Config Files
cmdline.txt
vi /boot/cmdline.txt
delete
"console=serial0,115200"
config.txt
vi /boot/config.txt
add
"enable_uart=1"
Flashing
Warning: Do not have this device connected to mains power while flashing. Power is obtained by the Raspberry Pi. You need to hold the button down while powering on. After each command you will need to reboot the device and hold the button down to enter flash mode.
Display Existing
esptool.py --port /dev/serial0 flash_id
Backup
esptool.py --port /dev/serial0 read_flash 0x00000 0x400000 sonoff-image4M-stock.bin
or
esptool.py --port /dev/serial0 read_flash 0x00000 0x100000 sonoff-image1M-stock.bin
Erase
esptool.py --port /dev/serial0 erase_flash
Flash
Here I'm downloading the sonoff.bin file from thehackbox but writing the file as sonoff-6.7.1.bin. At time of download the version has probably changed, so write the file as per the correct version number so you know which version of the file you have.
wget http://thehackbox.org/tasmota/release/sonoff.bin -O /home/pi/Downloads/sonoff-6.7.1.bin
esptool.py --port /dev/serial0 write_flash -fm dout 0x0 /home/pi/Downloads/tosmato-sonoff-6.7.1.bin
Configure
miniterm
Miniterm is a terminal app to allow connection to the Sonoff over serial so we don't need to connect to the device over Wi-Fi for initial configuration.
miniterm /dev/serial0 115200 -e
settings
Change the settings as you require.
backlog ssid1 myssid; password1 mypassword backlog ipaddress1 10.13.13.238; ipaddress2 10.13.13.254; ipaddress3 255.255.255.0; ipaddress4 8.8.8.8 backlog ntpserver au.pool.ntp.org; timezone +10; Latitude -27.475646; Longitude 153.030499 backlog PowerOnState 1; teleperiod 20; PowerRetain 1 backlog MqttUser username; MqttPassword passw0rd; Topic laundry; FriendlyName laundry; MqttHost 10.13.13.253
Now change your device to the correct type. Note if you have the Pow device, changing to Pow will disable the serial logger so any further commands will need to be done from the WEB GUI.
module 43
You can view the console command but can not enter any moving forward. Also notice the baud rate change.
miniterm /dev/serial0 4800 -e
When updating the MQTT details and the module type the device will reboot, so make sure you wait for reboot to complete.
Field | Description |
ipaddress1 | IP address |
ipaddress2 | gateway |
ipaddress3 | IP mask |
ipaddress4 | DNS |
Modules
Number | Descrption |
0 | Generic |
1 | Basic |
4 | TH |
5 | Dual |
43 | Pow R2 |
....and many more.