PhatFil
Posts: 1309
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

good news for home automation enthusiasts..ota reprogramming of smart-life (tuya) devices

Fri Feb 01, 2019 7:53 pm

If you have ever considered using smart wifi switches with your pi system but been put off by not wanting to pry open a factory sealed unit or solder header pins onto a pcb. there is currently one style/type of wifi controller that can be flashed OTA without any interference.

This may change as the manufacturer catches on but devices that use a Tuya based style esp device The apps used on the phone provided by the manufacturer have names like XXXX-Life like "Smart Life"
Tuya is a major distributer of these devices in the US, in the UK the brand KooGeek is sold, and i have a far east sourced 4x socket strip that also uses the same h/w.
https://www.amazon.co.uk/Koogeek-Compat ... plug&psc=1
https://www.amazon.co.uk/gp/product/B07 ... UTF8&psc=1
the powerstrip is not upto UK code( tho it probably will be next year ), earth neutral and live wires are soldered onto the steel (brass lookalike) bus bars and the flex grip fully clamped down is useless.. not a safe product so i am not recommending it.

the process is pretty straight forward and as usual involves more time waiting than doing.
you will need a Pi3B or 3B+ an 8gb sd card with a freshly flashed raspian image and a network cable to connect your pi to your network. enable ssh with a file named ssh in the boot partiton of the sd card, plug in your pi and ssh into it.
use

Code: Select all

sudo raspi-config 
to expand the file system ONLY, exit and reboot
then execute the following 3 commands only

Code: Select all

sudo apt get update
sudo apt-get dist-upgrade
sudo apt-get install network-manager
then follow the guide here to clone the repository and run the install pre-requisites and start scripts responding appropriately when prompted
https://github.com/ct-Open-Source/tuya-convert

Also DO NOT upgrade npm if invited to by the install script...

you will also need a wifi enabled phone or tablet to make a connection to the AP the system will set up on your pi via its wifi. when prompted it will provide you with the ssid and pw to use.

After a few false starts trying to use my everyday pi3b system to preform the upgrades the above method proved successful..

dont worry about security and passwords etc after all the pi is up on your network and empty for the duration it takes to set up, flashing the device takes seconds.. once done your pulling the sd card and reinserting your system..

the system will set your device up for flashing, its got the binaries for the tasmota project which is the firmware i use and will provide you with the command to flash tasmota to your device when its ready but you could if you wanted use your own code too.
https://github.com/arendst/Sonoff-Tasmota/wiki
Last edited by PhatFil on Fri Mar 22, 2019 12:27 am, edited 2 times in total.

burnhaj
Posts: 24
Joined: Sun Mar 09, 2014 3:43 am

Re: good news for home automation enthusiasts..

Sun Feb 17, 2019 10:21 pm

Thank you for your post. I reached it by following a link in another post reporting how simple and successful he was using this procedure. You have given me the confidence to order a four pack of these devices to give it a go. They are to arrive within a couple days and I will report back.

PhatFil
Posts: 1309
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: good news for home automation enthusiasts..

Sun Feb 17, 2019 11:46 pm

Welcome to the 'Dark Side', and thanks for the thumbs up.

It seems that its a fairly safe punt to assume any device using an app called either 'smart-life' or XXXXX-Life, where XXXXX is some play on the device brand name. Is a Tuya based device and currently open to this OTA 'hack'

There may be a limited window of opportunity here, the SonOta method of ota reprogramming the sonoff based devices was closed off by a subsequent ewelink app updates.

Tasmota is a very sophisticated system with a lot of configurable options, if you need pointers and cant find the relevant wiki page, https://github.com/arendst/Sonoff-Tasmota/wiki check out the sonoffusers google group

burnhaj
Posts: 24
Joined: Sun Mar 09, 2014 3:43 am

Re: good news for home automation enthusiasts..

Wed Feb 20, 2019 3:07 pm

yes!

I love good step by step instructions.
Here are the devices that I purchased: https://www.amazon.com/gp/product/B07J4 ... UTF8&psc=1

Most of the time is spent setting up the pi3 with clean image and doing the updates.

I stumbled a little on the Github instructions. First attempt, apparently I didn't really get the device into flashing mode even though the LED was flashing. Power cycling and entering flash mode a second time worked. The first time around I waited about ten minutes while the progress bar was waiting for the device to show up after I pressed enter before I aborted it (cntrl-C). The second time it took less than 30 seconds for the device to show up.

After this point in the Github instructions, many options are presented (backup/restoring/alternative firmware, etc.) This only served to confuse me until I figured out that all I needed was the curl http://10.42.42.42/flash3 line to install the Tasmota firmware and I was done.

So, in a nutshell it is:

1. follow the Github installation instructions through the ./start_flash.sh line,
2. agree by typing yes,
3. login to the vtrust WIFI from your phone/pad,
4. put the device into flashing mode,
5. press ENTER,
6. when the hex stuff stops scrolling by put curl http://10.42.42.42/flash3 at the command line.

Connect to the sonoff-xxxx wifi access point.

You are done!

I also configured the device parameters as outlined here to get the device to work:

https://github.com/arendst/Sonoff-Tasmo ... eckin-sp10

PhatFil
Posts: 1309
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: good news for home automation enthusiasts..

Wed Feb 20, 2019 8:38 pm

https://www.youtube.com/watch?v=O5GYh470m5k
has been flagged as useful elswhere,, personally i find the chaps accent difficult.

burnhaj
Posts: 24
Joined: Sun Mar 09, 2014 3:43 am

Re: good news for home automation enthusiasts..

Wed Feb 20, 2019 11:29 pm

Thanks for the link to the youtube video. I just reviewed it and yes, that is exactly what I did.

User avatar
bensimmo
Posts: 4129
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: good news for home automation enthusiasts..

Thu Feb 21, 2019 8:59 am

I've been doing this with Teckin UK plugs (as they have power monitoring, proper 'smart' stuff so you can log all your device and see if they are still running)

Pi3B+ & ZeroW using WiFI only
All I did was, fresh SD card, raspbian lite Nov-18
boot, let it do it's stuff (it expands automatically and reboots)

go into raspi-config,
change overscan to off, just as it irritates me ;-)
setup WiFi county, to enable WiFi and then connect to my router.

Do TUYA-CONVERT #INSTALL# github stuff
just do what it says, till it stops installing itself.

Then reboot
then disconnect from WiFi (remove entries from /etc/wpa_supplicant/wpa_supplicant.conf and I rebooted)
... you could probably just do sudo killall wpa_suppliant but I wanted to make sure ...
Then run the script to start_flash
let it do it's stuff, mobile phone connect etc.
I then checked with the device location it gave me the same info.
Check with flash2 and it should reply already done
then flash3
that was actually the most confusing part and took me a while to work it outas it's instant and does't tell you anything.
At this point, go back to your mobile and scan WiFi for the Smart Device with a Sonoff name.
log in setup WiFi and off you go.

UK Teckins are Blitzwolf
Give it a proper Name for the network
Turn WeMo emulation on and a useful name (and then just do a scan in Alexa for other devices, nothing specific and it picks it up, no good for Google Home though.)
Disable MQTT if you are not using it at the moment , this stops the LED from constantly flashing.
Grab next plug/switch and just do the flash part.
Simples.

The next part is setting up your own server to centralise and control them outside the house (or use Alexa I guess)
OpenHAB, HomeAutomation.. no idea which to use.

These are the one I have, 8 of them now.
https://www.amazon.co.uk/TECKIN-Monitor ... B07D7BH6N8
they drop to about £32 in Flash Sales, so keep an eye on them.
They are a bit crap if you have them in switched plug wall sockets and it fowls the switch, but is not to big a problem, just poor design.
Fit nicely in my strip sockets though.


If you use a ZeroW and keep the SD card and use a USB battery you have a cheap portable converter ;-)

You can then flash with firmware with more function (auto discovery etc) with Tasmota.
Or at the original flash stage, switch to alternative firmware if it's compatible, e.g. Espurna

User avatar
bensimmo
Posts: 4129
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: good news for home automation enthusiasts..

Thu Feb 21, 2019 9:09 am

might want to edit your title to include SmartLife and TUYA ?
otherwise it's a bit generic and could be some new fangled device are Pi whatsit and I only happened upon it.

whatsupskip
Posts: 4
Joined: Thu Mar 21, 2019 9:20 pm

Re: good news for home automation enthusiasts..ota reprogramming of smart-life devices

Thu Mar 21, 2019 9:48 pm

bensimmo wrote: Pi3B+ & ZeroW using WiFI only
All I did was, fresh SD card, raspbian lite Nov-18
boot, let it do it's stuff (it expands automatically and reboots)

go into raspi-config,
change overscan to off, just as it irritates me
setup WiFi county, to enable WiFi and then connect to my router.

Do TUYA-CONVERT #INSTALL# github stuff
just do what it says, till it stops installing itself.
I am also trying to set this up on the RPi Zero W, however I hit some problems trying to run the tuya-convert/install_prereq.sh

I also used a fresh install of Raspbian Lite.

I had to install git first sudo apt-get install git
Then I could

Received error on ./install_prereq.sh it was the wrong version of NodeJS for the RPi Zero
I found the correct version of NodeJS and then wget https://nodejs.org/dist/v10.15.3/node-v ... v6l.tar.xz

However at this point I was stuck.

PhatFil
Posts: 1309
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: good news for home automation enthusiasts..ota reprogramming of smart-life devices

Fri Mar 22, 2019 12:26 am

you probably need a usb-nic and to connect via ssh/ethernet ip addy in order to use a pi-0-w as the wireless will be devoted to the AP used for the OTA backup and flashing.
Without it i dont see how you can maintain access to the shell instance within which you start the tuya convert process to continue the dialog and flash the device and see the progress/success.. since as soon as you start the tuya-convert it will kill the wifi and any tty session your connected to to set up the AP???

you could i guess wire up to mouse keyboard and tv but that seems a bit extreme..

PhatFil
Posts: 1309
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: good news for home automation enthusiasts..

Fri Mar 22, 2019 12:28 am

bensimmo wrote:
Thu Feb 21, 2019 9:09 am
might want to edit your title to include SmartLife and TUYA ?
otherwise it's a bit generic and could be some new fangled device are Pi whatsit and I only happened upon it.
Done :)

User avatar
bensimmo
Posts: 4129
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: good news for home automation enthusiasts..ota reprogramming of smart-life (tuya) devices

Fri Mar 22, 2019 7:09 am

If I remember correctly, I just ignored the node.js and any errors during the initial install.
I had a mouse and keyboard attached probably (I can't remember), but when ready to go I killed WiFi (remove the details from wpasupplicant.conf) and then in can go into AP mode

Once attached to the AP as you need to be, just SSH in to it from your mobile (JuiceSSH here) and get on with it.

whatsupskip
Posts: 4
Joined: Thu Mar 21, 2019 9:20 pm

Re: good news for home automation enthusiasts..ota reprogramming of smart-life (tuya) devices

Thu Mar 28, 2019 5:35 am

There is a new version of the script that uses python instead of Node.JS. This should mean the RPi Zero W can be used. (I think).

I have made some progress, but I am still having some problems.

In the marthack-wifi.log there is an error

Code: Select all

Configuration file: /etc/hostapd/hostapd.conf
Failed to create interface mon.wlan0: -95 (Operation not supported)
wlan0: Could not connect to kernel driver
Using interface wlan0 with hwaddr b8:27:eb:7e:64:XX and ssid "vtrust-flash"
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED 
wlan0: STA 1c:cb:99:6c:ae:8d IEEE 802.11: associated
wlan0: AP-STA-CONNECTED 1c:cb:99:6c:ae:XX
wlan0: STA 1c:cb:99:6c:ae:XX RADIUS: starting accounting session 9843ADC78F1D7100
wlan0: STA 1c:cb:99:6c:ae:XX WPA: pairwise key handshake completed (RSN)
wlan0: STA 1c:cb:99:6c:ae:XX IEEE 802.11: disassociated
wlan0: AP-STA-DISCONNECTED 1c:cb:99:6c:ae:XX
wlan0: STA 1c:cb:99:6c:ae:XX IEEE 802.11: disassociated
However I am able to connect to the RPi access point as a WiFi client, but I can't ssh in. Using JuiceSSH I receive the error can't connect to "/10.42.42.1" and the same for 10.42.42.42.

Any suggestions would be great.

PhatFil
Posts: 1309
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: good news for home automation enthusiasts..ota reprogramming of smart-life (tuya) devices

Thu Mar 28, 2019 5:26 pm

I think you need a lan/usb adaptor to use a pi-0-w

whatsupskip
Posts: 4
Joined: Thu Mar 21, 2019 9:20 pm

Re: good news for home automation enthusiasts..ota reprogramming of smart-life (tuya) devices

Thu Mar 28, 2019 11:08 pm

PhatFil wrote:
Thu Mar 28, 2019 5:26 pm
I think you need a lan/usb adaptor to use a pi-0-w
I realised afterwards to mention that I was using a USB LAN adapter.

PhatFil
Posts: 1309
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: good news for home automation enthusiasts..ota reprogramming of smart-life (tuya) devices

Thu Mar 28, 2019 11:40 pm

whatsupskip wrote:
Thu Mar 28, 2019 11:08 pm
PhatFil wrote:
Thu Mar 28, 2019 5:26 pm
I think you need a lan/usb adaptor to use a pi-0-w
I realised afterwards to mention that I was using a USB LAN adapter.
Ok whats the point of using juice ssh then? a quick google tells me that its an android app, the tuya-convert app/scrip only needs a 3rd device to connect to its AP, once connected via wifi management NO FURTHER ACTION IS NEEDED. at that point return to your lan ssh connection within which you have run the tuya-convert, and press the button on your device for 5+seconds to kick off the original f/w backup and prep for the reprogramming..

**EDIT re-reading that sounds a bit harsh, sorry, i just dont understand why your using the android app to ssh in?

whatsupskip
Posts: 4
Joined: Thu Mar 21, 2019 9:20 pm

Re: good news for home automation enthusiasts..ota reprogramming of smart-life (tuya) devices

Fri Mar 29, 2019 12:02 am

PhatFil wrote:
Thu Mar 28, 2019 11:40 pm
i just dont understand why your using the android app to ssh in?
Sorry again for my poor explanation.

I initially tried to run the operation via ssh via the USB LAN with a phone connecting to the RPi hotspot. I wasn't sure that just connecting to the RPi hotspot was sufficient. When just connecting to the RPi hotspot didn't appear to work, I also tried to connect with the phone and then ssh in.

I had previously had other issue which I was able to resolve.

PhatFil
Posts: 1309
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: good news for home automation enthusiasts..ota reprogramming of smart-life (tuya) devices

Fri Mar 29, 2019 12:44 am

Only problem i have had is getting the smart device into the correct comms mode unlike the usual esp8266 type device its NOT a case of starting up with the gpio-0 grounded, but in most cases afaik powering the device and then holding its button down for 5+ seconds..
but i have used a raspi-3B

Next time i buy a tuya device i will attempt the flash with my Pi3B built sd card in a pi-0-w with my working usb/nic to confirm the procedure.

User avatar
bensimmo
Posts: 4129
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: good news for home automation enthusiasts..ota reprogramming of smart-life (tuya) devices

Fri Mar 29, 2019 3:58 pm

I just held the power button iirc as you don't have access to the internals
It's a bit more like flashing the WeMo/NodeMCU in that respect, none of the resistors and ground malarkey.

It was just so simple, might have to buy some more and have another go.

Return to “Automation, sensing and robotics”