|
Post by papa on Dec 30, 2019 16:09:09 GMT
Some Home Automation without openHAB
My son wanted to do some home automation without openHAB. He found this Gruppio Github offering of flashing a Sonoff ESP8266 WiFi controlled switch so that it could be controlled by the iOS Home app.
According to the Gruppio Github, this worked on Sonoff Basic, Sonoff Slampher, & Sonoff S26. I also flashed a Sonoff S20 smart outlet. The Sonoff devices have been consistent in using GPIOs so this could probably work on other Sonoff devices. Earlier devices had a header convenient for flashing. My later Sonoff S26 no longer had the convenient header, but below I'll point to ways to work around that.
This Github was promising, but I found it could use some additional information (see below), especially for a glitch that kept it from working.
Next, Preparing to Program a Sonoff Device
|
|
|
Post by papa on Dec 30, 2019 16:12:07 GMT
Physical Preparations to Program a Sonoff Device
We need to get the Itead Sonoff Device open. We also need an FTDI programming device (capable of 3.3 volt output) & cables/connectors.
Update, Jan. 3, 2020: Drivers for the FTDI device also need to be installed. I believe installing the Arduino IDE includes the FTDI driver.
See this post which covers the FTDI device & cables. It also relates to the Itead Sonoff S20 & other devices with the convenient programming header.
See the threads in this board for help on opening & connecting to other Itead Sonoff devices. From those threads, use only the info for opening & connecting the devices. Don't use the programming that the threads offer for flashing the devices.
For the Sonoff S26 AND other Sonoff devices who do not have the convenient programming header, see this thread.
Next, Software Preparations to Program a Sonoff Device
|
|
|
Post by papa on Dec 30, 2019 17:07:50 GMT
Software Preparations to Program a Sonoff Device
Have the Home app installed on an Apple iOS device.
Have Python 2.7 installed. Have the ability to run a Linux script either on a Linux computer or on a Windows 10 computer with Windows Subsystem for Linux (WSL) activated & an installed Linux version like Ubuntu. (I used Ubuntu Linux on Windows 10.)
Don't use that Gruppio software yet. We will tweak & augment it.
Next, Prepare to Tweak the Gruppio Software
|
|
|
Post by papa on Jan 3, 2020 22:29:37 GMT
Prepare to Tweak the Gruppio SoftwareIn the two scripts to be used below, we need to complete the line that starts: SONOFF_PORT= For Windows 10, this "port" will start with "COM" & end with a number, such as "COM4" If the Arduino IDE is installed & the FTDI device is plugged into a USB port, Arduino IDE will list this under Tools/Port. For Linux, I believe you can remove the FTDI device from USB & reinsert to USB & then in Terminal, execute the command: echo -n "/dev/"; dmesg | grep tty|grep USB|rev|awk '{print $1}'|rev This may display something like this path to the FTDI's port: /dev/ttyUSB0
Next, Augmenting & Tweaking the Gruppio Software
|
|
|
Post by papa on Jan 3, 2020 22:40:17 GMT
Augment the Gruppio SoftwareBefore we execute a flash script, things may work better if we save & execute an erase script. (Without first erasing all the flash memory with the erase.sh script, flashing the Gruppio software failed for me.) Starting with the text below that is bracketed by the =========== lines, create a new file named erase.sh
Where instructed, tweak the file based on posts above. If necessary, make the file executable. ================================ #!/bin/bash # For better flashing success, this script will erase all of a Sonoff's flash memory first. Put file in Python\Scripts subfolder. # For a true Linux computer, enable line 9 of this script (delete # at start) & disable line 11 (put # at start) # For Linux running on Windows 10, disable line 9 (put # at start) & enable line 11 (delete # at start) # SONOFF_PORT="/dev/cu.wchusbserial14310" # edit to match connection to 3.3 volt FTDI programmer on Linux computer SONOFF_PORT="COM4" # edit to match Windows 10 port to 3.3 volt FTDI programmer # You may need to augment line 16. For Linux on Windows 10 example, see line 14 (without the disabling # at start) # /mnt/c/Python27/Scripts/esptool.py.exe \ esptool.py \ -p $SONOFF_PORT \ --baud 115200 \ erase_flash \ ======================================= Next, Tweak the Flash Script
|
|
|
Post by papa on Jan 3, 2020 22:44:09 GMT
Tweak the Flash Script
Using the text below bracketed by the =========== lines, edit & save the Gruppio file named flash.sh
Where instructed, tweak the file based on posts above.
=========================
#!/bin/bash # This an edit of Gruppio's flash.sh script to avoid syntax errors & warnings & to add Linux on Windows 10 capability. POWERON_STATE="ON" # Change this to "OFF" if you want your Sonoff to be OFF when powered # For a true Linux computer, enable line 11 of this script (delete # at start) & disable line 13 (put # at start) # For Linux running on Windows 10, disable line 11 (put # at start) & enable line 13 (delete # at start) # SONOFF_PORT="/dev/cu.wchusbserial14310" # edit to match connection to 3.3 volt FTDI programmer on Linux computer SONOFF_PORT="COM4" # edit to match Windows 10 port to 3.3 volt FTDI programmer # You may need to augment line 18. For a Linux on Windows 10 example, see line 16 (without the disabling # at start) # /mnt/c/Python27/Scripts/esptool.py.exe \ esptool.py \ -p $SONOFF_PORT \ --baud 115200 \ write_flash \ -fs 1MB \ -fm dout \ -ff 40m \ 0x0 ./firmware/rboot.bin \ 0x1000 ./firmware/blank_config.bin \ 0x2000 ./firmware/Sonoff_$POWERON_STATE.bin
===============================
Continued
|
|
|
Post by papa on Jan 4, 2020 21:37:40 GMT
Physical Connections for Flashing the Gruppio FirmwareIf your Sonoff has the convenient programming header, follow this post. Also be ready to follow most of this next post, but disregard the firmware provided in the post's thread & disregard using the Arduino IDE for flashing. If your Sonoff does NOT have the convenient programming header, adapt from this post, this post, & this post. Also be ready to follow most of this post, but disregard the firmware provided in the post's thread & disregard using the Arduino IDE for flashing.
Next, Erase & Re-flash the Sonoff
|
|
|
Post by papa on Jan 4, 2020 21:58:30 GMT
Erase & Re-flash the Sonoff with Gruppio FirmwareIn a Linux Terminal window, navigate to the folder containing the erase.sh & flash.sh scripts (see above) which may end with \Python27\Scripts.
On Windows if the folder is C:\Python27\Scripts, then execute the following command at the Linux prompt (adapt to your situation): cd /mnt/c/Python27/Scripts
Now at the Terminal prompt, type erase.sh but do not hit enter yet. On Windows Linux, using the full path worked better for me. In my case: /mnt/c/Python27/Scripts/erase.sh
Based on above posts, have the FTDI programming device cabled to the Sonoff. Then holding down the Sonoff's push button, plug the FTDI cable into the computer's USB. Hit enter on the Terminal Window. On the Terminal window, a successful process of the erase.sh script should end: "Hard resetting via RTS pin..." Once the erase.sh script is successful, follow the same procedure with the flash.sh script (perhaps using the full path).
If running the flash.sh script ends with "Hard resetting via RTS pin...", your Sonoff should be successfully reflashed with the Gruppio firmware.
Next, Pairing the Sonoff with the Home App
|
|
|
Post by papa on Jan 5, 2020 20:40:10 GMT
Pairing the Sonoff with the iOS Home App Adapted from Gruppio Github: 0 Plug a re-flashed & reassembled Sonoff switch into mains power (The iOS devices's Bluetooth needs to be ON)
1 On your Apple iOS device, enter Settings/WiFi & select the new WiFi network named Sonoff Switch-xxxxxx (xxxxxx will be the last 3 hexadecimal identifier codes of the Sonoff switch)
2 Wait for the Captive Portal page to open on the iOS device & there, select your normal WiFi network 3 Enter your WiFi's Password & tap the [Join] button at the bottom (Your iOS device should reconnect with your local WiFi)
4 Open the Home app on the iOS device 5 Click the + symbol (upper right) in the Home app 6 Tap [Add accessory] 7 Select Sonoff-Switch-xxxxxx (If Sonoff-Switch-xxxxxx does not appear, press the Sonoff's push button a few times & restart the Home App)
8 At "Add Homekit Accessory ... not certified," tap [Add Anyway] when that's offered 9 Tap "Enter Code Manually" 10 Using the 8 small boxes, enter the pairing password code: 11111111 [that is, eight number ones] (Now keep the iOS device & Sonoff near each other until pairing completes.)
The pairing process may spin a while. You may need to enter the pairing password multiple times. You may need to click the Sonoff's push button a few times & restart the Home app & pairing process. You may even need to remove the Sonoff switch from power & plug it back in & restart the pairing process. When pairing succeeds, this Sonoff switch will have a virtual button on the Home app. Tapping that button will toggle the power coming through the Sonoff. The Sonoff switch will store its login to your WiFi so it can connect to WiFi whenever it is powered.
|
|