itead / Sonoff_Devices_DIY_Tools

BSD 3-Clause "New" or "Revised" License
548 stars 168 forks source link

Impossible (but near) to flash firmware using DIY Tools under Ubuntu 18.04 #21

Open ThierryM opened 4 years ago

ThierryM commented 4 years ago

Hi, Here my experience in intending flashing Tasmota firmware with Sonoff_Devices_DIY_Tools under Ubuntu 18.04 (I think, that this DIY mode should interest many people working with GNU/Linux and not only these under Windows...). You can find more informations (in french) here : https://lofurol.fr/joomla/electronique/domotique/225-sonoff-flasher-tasmota-sur-un-module-sonoff-rf-r3. As the tools are python programs, I think that they could work for GNU/Linux... Almost but not. When I try to flash, the progression bar stay at 0% and I have this error message:

Server initialization complete
Traceback (most recent call last):
  File "/perso_ssd/Thierry/Electronique/Domotique/Tasmota/Sonoff_DIY_Tools/Sonoff_Devices_DIY_Tools/code/Dialog_text.py", line 623, in start_root
    server_port=myport, server_ip=myaddr)
  File "/perso_ssd/Thierry/Electronique/Domotique/Tasmota/Sonoff_DIY_Tools/Sonoff_Devices_DIY_Tools/code/tcp_server.py", line 30, in __init__
    self.sockfd.bind(ADDR)
PermissionError: [Errno 13] Permission non accordée

So it seems that this is an access denied problem but I don't know how to solve it. I add that I succeeded to flash with the same local WLAN network with a Windows 10 laptop. Thanks for your help, regards

ZZLinvec commented 4 years ago

Now the error is that the expression tool cannot get to the IP address of the local machine, so the port cannot be bound.If you need to run under LINUX, change the tool code to get the IP address under LINUX. I can talk to you about the upgrade process.

ThierryM commented 4 years ago

Hi, thanks for your reply. I made some searches but I'm not able to modify the tool code ;-). Under Ubuntu when I launched mdns.py, nothing happened. It seems in this topic https://stackoverflow.com/questions/10244117/how-can-i-find-the-ip-address-of-a-host-using-mdns that there is a problem with zeroconf and ESP8266. Regards

rradar commented 4 years ago

This needs to be investigated!

@ZZLinvec could you please assist get your DIY Tools running with linux? Thank's a lot!

sigmdel commented 4 years ago

Don't know if this could be helpful:

$ avahi-browse --all
+ wlp3s0 IPv4 eWeLink_1000987654                            _ewelink._tcp        local

shows that a Sonoff Mini is connected and broadcasting its _tcp service. BUT

$ avahi-resolve -n eWelink_1000987654
Échec de la création du résolveur de nom d'hôte  : Nom d'hôte invalide

(i.e. Resolving error: invalid host name) shows that the host name is not valid. Indeed underscores "_" are not valid in host names. Only letters, digits and the hyphen "-" are valid. Maybe the mdns resolver in Windows is more forgiving than in Linux?

I tried changing lines 24 and 25 of tcp_server.py from

        HOST = func_task["server_ip"]
        PORT = func_task["server_port"]

to the actual IP & TPC port number of the Mini

       HOST = '192.168.0.130'
       PORT = '8081'

without success. Guess that would have been too easy. So I ended up flashing the firmware using the DIY mode API. Works well in Linux at least : https://www.sigmdel.ca/michel/ha/sonoff/sonoff_mini_en.html, but additional hardware is needed to create the Wi-Fi access point.

Merci ThierryM. Avec votre aide j'ai réussi à me rendre plus loin avec Linux (Ubuntu) qu'avec Windows 10.

ZZLinvec commented 4 years ago

@ThierryM I'll see it now

ZZLinvec commented 4 years ago

What I see from the log you gave me is that the TCP server was set up at the wrong address.My code is RootDialog class --->start_root function in the file code/ dialog_text.py to get the native IP port and test whether the port is available, which is about line 618.Line 619 is to obtain the IP of the current computer and determine which is the IP of the device passing through a LAN. If it is abnormal, then directly obtain the local address.

ZZLinvec commented 4 years ago

The purpose here is to get the IP under the same LAN as the device and create an HTTP service with that IP to give the device the get firmware

ZZLinvec commented 4 years ago

I hope that helps

rradar commented 4 years ago

news?

danisojo commented 4 years ago

Hi, I have the same problem here. Running in Linux Mint 19.2 Cinnamon. 10009bcbc6 >>> {'ip': '192.168.1.25', 'port': '8081', 'switch': False, 'startup': 'off', 'pulse': False, 'pulseWidth': 500, 'rssi': -37} Port 80 is not open ('dani-desktop', [], ['127.0.1.1']) self.all_sub {'10009bcbc6': {'ip': '192.168.1.25', 'port': '8081', 'switch': False, 'startup': 'off', 'pulse': False, 'pulseWidth': 500, 'rssi': -37}} 127.0.1.1 Server initialization complete updata eWeLink_10009bcbc6._ewelink._tcp.local. info len 404 ServiceInfo(type='_ewelink._tcp.local.', name='eWeLink_10009bcbc6._ewelink._tcp.local.', addresses=[b'\xc0\xa8\x01\x19'], port=8081, weight=0, priority=0, server='eWeLink_10009bcbc6.local.', properties={b'txtvers': b'1', b'id': b'10009bcbc6', b'type': b'diy_plug', b'apivers': b'1', b'seq': b'5', b'data1': b'{"switch":"off","startup":"off","pulse":"off","sledOnline":"on","pulseWidth":500,"rssi":-37}'}) Traceback (most recent call last): File "/home/dani/Documentos/Sonoff_Devices_DIY_Tools/code/Dialog_text.py", line 623, in start_root server_port=myport, server_ip=myaddr) File "/home/dani/Documentos/Sonoff_Devices_DIY_Tools/code/tcp_server.py", line 30, in __init__ self.sockfd.bind(ADDR) PermissionError: [Errno 13] Permiso denegado 10009bcbc6 >>> {'ip': '192.168.1.25', 'port': '8081', 'switch': False, 'startup': 'off', 'pulse': False, 'pulseWidth': 500, 'rssi': -37} updata eWeLink_10009bcbc6._ewelink._tcp.local. info len 404 ServiceInfo(type='_ewelink._tcp.local.', name='eWeLink_10009bcbc6._ewelink._tcp.local.', addresses=[b'\xc0\xa8\x01\x19'], port=8081, weight=0, priority=0, server='eWeLink_10009bcbc6.local.', properties={b'txtvers': b'1', b'id': b'10009bcbc6', b'type': b'diy_plug', b'apivers': b'1', b'seq': b'5', b'data1': b'{"switch":"off","startup":"off","pulse":"off","sledOnline":"on","pulseWidth":500,"rssi":-37}'}) I'have done this test with the patched versions from ThierryM By the way, "Permison Denegado" means Access Denied in Spanish.

Does anyone managed to do a firmware update with the python scripts under linux? It's frustrating that it seems that is only working fine under windows.

Kind Regards

biotecov commented 4 years ago

I am trying too in another flavor of Linux (slackware), with no success so far, although I am stuck on an earler step.

Setting up an AP with the required SSID and password and getting the device linked to the AP was easy. Then, I discovered that the provided python code has inconsistencies (mixed usage of spaces and tabs and some incorrect indentations, yes, now I know that you had discovered that already). After fixing those inconsitencies and installing the missing python packages, I still get a message I don't know how to address: 'Could not load the Qt platform plugin "xcb" in "" even though it was found'.

I am no really proficient on python, so I don't know how to solve this. Any clue?

SirGoodenough commented 4 years ago

Perhaps this is possible. Surely someone could take the information Michel Deslierres started here and plug this into a raspberry pi image that starts a web server, does the cURL commands, and ties it up in a pretty bow similar to the existing tool for flashing Tuya devices. This is not even an exploit, merely an implementation or extension of the manufacturers intent. Maybe not a single python file, rather an image for a ras-pi we could put on a memory card and boot into a pi to complete the task. https://www.sigmdel.ca/michel/ha/sonoff/sonoff_mini_en.html

jrbenito commented 4 years ago

hi @SirGoodenough ,

Here is a docker image that brings up an AP for sonoffDiy SSID and runs a script to wait for sonoff dveice, issues http requests and serve the firmware file. Nothing fancy but tries to be as automatic as possible: https://github.com/jrbenito/SonoffDIY-tasmotizer

Hope this could be helpful to you guys.

cheers

jpwise9 commented 4 years ago

Just came across this thread. Did a very similar thing to @jrbenito a few months ago. Companion scripts building on the tuya-convert packages to automate converting Sonoff DIY modules to tasmota. Brief details and link posted at: https://community.openhab.org/t/sonoff-diy-mode-ota-unlock-convert-to-tasmota-automated/90116