Thursday, August 5, 2021

Tasmota standalone setup and flashing with python

I have:

   Sonoff - RF R2 

   Serial FTDI clone  (YP-05)   

   MaxOSx 10.10

   Arduino 1.8.8

Using Tasmota is the best and no need of any of these other crap. only issue is putting a header to the board for the initial flash

   Easiest way to plug the serial pins without soldering is using a header like here:  conectigng serial pins of Tasmota without soldering

Installing (Flashing Tasmota)

    Tasmota is the best firmware for sonoff to install, tried GUI tools none worked(atom, win tools etc)


    MacOS has perl & python by default so the tool that worked was esptool  which is a

python script, it needs pip so first download the pip installer

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

then run it (i ran both with sudo just to make sure)

python get-pip.py   

   Finally get the esptool with 

pip install esptool  

   


 Here it is ready to flash.. 1st let’s save the original firmware that came with it,

to find the port use Arduino IDE on ports it will list the new port from the FTDI adaptor

my esptool was not in the path I had to give full path hanging from my python dir in ~/Library/python

esptool.py -p /dev/cuxxx read_flash 0 0x100000 sonoff_orig.bin 
       
   and finally flashed it with

esptool.py -p /dev/cu.usbserial-xxxx  write_flash -fs 1MB -fm dout 0x0 sonoff_6.7.1.bin  
             

Tasmota picks up the time off  the net via NPT(by default npt.org) and boots with default values

time by detault is GMT time when initially connected to an AP with access to the net so the timezone needs to be updated


    Don't forget to put the sonoff in flashing mode i.e. unplug it hold down the only button and plug it in while holding down the button for a few seconds and it is ready to receive

  My customization

  I needed to use it remotely with no internet/router so when it starts it connects to a local AP(I use PDAnet on an old iPhone) then with webUI I can set the timers which stay when the unit is unplugged. But when no AP is available e.g. I leave the remote site to work standalone, by default when no internet Tasmota resets the timer (to 1970 actually the time 0 command is the default using time epoch stops using the NTP and keeps this time until powered off) that killed my needs and popped up with the setup site for 3 mins.  I had planned to add a checkbox on that screen from the setup that skips the NPT testing and popping the setup page when no internet and set up the Time to epoch but the source code was quite convoluted and a friend had an old router that  was much quicker than digging thru the code. Easy does it.

So I ended up using an old router and these settings

WifiConfig 5      (to wait when the AP in unavaiable)
timezone -5       (my timezone hours to GMT)
time xxx          (the current time from a call to epoch, will only take epoch after 2015)

     

  Hints

   Initial router was a wireless Huawei and it couldn't connect i.e. see the device 192.168.8.xxx I also had a NetGear Nighthawk where it did work as advertised on the standard channel (not the 5G) 



Also if you don't have a scanner to get the IP number  we can hard code it before hand

as below (keep in mind if swapping to a different AP the base address might be different and your hard coded IP needs to reflect that or it won't connect to the NTP server and hence the time will be set to 1970)

ipaddress1 [192.168.xxx.yyy]
restart 1

to point to a NTP server

ntpserver <ipadrress or host>

when switching APs it runs a restart


   If it becomes unreachable due to funny IP or similar reset it by holding the button for 4secs in my case it would not respond at all so I had to do a real "hard reset" manually since I was at the site with no serial port connection it goes like this: take power out for 30 secs then repeat a plug in for 10 secs and unplug it 6 times and on the 7th plugin leave it in an AP named sonoff-xxx will become available where the SSID can be set and from there it is easy to come back to life.