njh / sonoff-ota-flash-cli

Bash script to perform an OTA (Over the Air) firmware update for Sonoff 'DIY Mode' device on the command line
http://sonoff-ota.aelius.com/
MIT License
129 stars 19 forks source link

3.7.6 - Mini - Needs change to work #18

Open JonLaliberte opened 1 year ago

JonLaliberte commented 1 year ago

For some reason, the script was not working on a Mini (I think R1? I got it a long time ago) running firmware 3.7.6. I was able to get it working by completely removing the "deviceid" from the body variable in the sonoff_http_request function, and also from the ota_flash function.

That made the script start working and got Tasmota flashed.

njh commented 1 year ago

Hm, interesting, thanks!

I have tested quite a bit with Firmware versions 3.5.0 and 3.6.0 and both R1 and R2 but didn't experience this. I can't remember how essential the deviceid parameter was when I was testing.

I wonder if it is possible to test if the parameter is needed somehow.

JonLaliberte commented 1 year ago

With the deviceid there I wasn’t getting any response when it tries to get the device info. Maybe after X seconds timeout and try without it?

RKeme commented 1 year ago

I confirm Jonathans findings- I was able to use the scipt by removing the deviceid at the mentioned places four times. 3.3.0 -> 3.7.6 -> diy-> adapted script

gonzalonaveira commented 1 year ago

Can confirm using Mini R2 and firmware version "3.7.6" as well

njh commented 1 year ago

It would be good to try the following things:

I am going to have to get my serial cable and tazmotizer out, to load different firmware versions on to a test device 😬

LngWork commented 11 months ago

Thank you for this report, same issue. Firmware version 3.7.0 : impossible to flash, with or without deviceid. Very difficult to configure WiFi.

Finaly here was my way :

Thank you @njh for your job !

solarsnoop commented 11 months ago

Hi Thanks you all, my expierence is the same and i have my problems to modify this scrip so i used RESTer Add on for send the requests to the SONOFF with FW 3.7.6. What i can say ist that the ID you can see in the SSID ITEAD-ID. In my case: ITEAD-10017318ef So what i did is i request the /zeroconf/info with using this ID and was succesful. { "deviceid": "10017318ef", "data": { } } Than I enable OTA Flashing with /zeroconf/ota_unlock:

{ "deviceid": "10017318ef", "data": { } }

and than i flash tasmato fw with zeroconf/ota_flash { "deviceid": "10017318ef", "data": { "downloadUrl": "http://sonoff-ota.aelius.com/tasmota-latest-lite.bin", "sha256sum": "5c1aecd2a19a49ae1bec0c863f69b83ef40812145c8392eebe5fd2677a6250cc" } }

So the Setting for RESTler was Clean Request and the Method is POST.

So hope this will help someone has the same problem .-)

@njh Nicholas maybe you can extend your script whre we can add the ID smae like the IP etc... Thanks in advance Guido

mifraburneo commented 10 months ago

Hi! I’m having an issue (that’s actually happening in 3.6.0 as well as after updating to 3.7.6) in which I can get the response on the Module Info but it hangs with an empty reply whoen trying to do the ota_unlock… Have you run into some simmilar issue? I’ve now tried with two brand new MINI R2.

Thanks a lot! image

IBims1NicerTobi commented 10 months ago

@mifraburneo Can you please try flashing again with https://github.com/IBims1NicerTobi/sonoff-ota-flash-cli-devid-fix?

IBims1NicerTobi commented 10 months ago

@njh There is a pull request now. I have personally tested it on a sonoff mini r2 with 3.7.6 and it worked while the current base version did not work at all.

jesusvallejo commented 9 months ago

@njh There is a pull request now. I have personally tested it on a sonoff mini r2 with 3.7.6 and it worked while the current base version did not work at all.

it worked like a charm, thanks a lot!

3N37 commented 7 months ago

@mifraburneo

I have the same problem as you, I have version 3.7.3 on sonoffminiR2. 2 I managed to flash and 2 others I can't.Another strange thing, I installed ewelink but when I try to register it crashes.

Siftah commented 7 months ago

Same issue as @mifraburneo and @3N37, running 3.7.6 firmware the curl always times out when trying to unlock.

I can see it's trying to contact apid.coolkit.cn/v2/d/otaflash (changed URL from earlier versions) and have redirected this to a local http server which is responding with { "error": 422 }, which I've seen elsewhere can allow the flash to proceed, but no dice, it still times out even though I can see in the logs it's hitting that URL correctly.

Unfortunately @IBims1NicerTobi fix doesn't help either :(

3N37 commented 7 months ago

@Siftah I've written a guide here flashing sonoffminiR2.it.en.pdf

Siftah commented 7 months ago

Thanks for sharing it @3N37, unfortunately it no longer works - the call to the unlock server is happening but the response seems to be ignored, the curl eventually times out and the Sonoff is never unlocked :(

I presume this must be a bug in the latest firmware, or they've changed the necessary response from what's in your example :(

3N37 commented 7 months ago

@Siftah , check if the apache server has the rewrite module enabled . I have unblocked sonoffminiR2 that had 3 different firmware. It works !

Siftah commented 7 months ago

Rewrite module is working great:

siftah@fozzie sonoff-ota-flash-cli-devid-fix % curl -v -X POST http://apid.coolkit.cn/v2/d/otaflash --data-raw '{"deviceid":"10009be24e","data":{} }'
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 192.168.1.253:80...
* Connected to apid.coolkit.cn (192.168.1.253) port 80 (#0)
> POST /v2/d/otaflash HTTP/1.1
> Host: apid.coolkit.cn
> User-Agent: curl/8.1.2
> Accept: */*
> Content-Length: 36
> Content-Type: application/x-www-form-urlencoded
> 
< HTTP/1.1 200 OK
< Date: Thu, 30 Nov 2023 14:18:12 GMT
< Server: Apache/2.4.52 (Ubuntu)
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
< 
{
"error": 422
* Connection #0 to host apid.coolkit.cn left intact
}%                                                                                                                                                                                                                                                                 siftah@fozzie sonoff-ota-flash-cli-devid-fix %

And I see the corresponding hit in the local server also: /var/log/apache2/access.log.1:192.168.1.90 - - [29/Nov/2023:14:32:42 +0100] "POST /v2/d/otaflash HTTP/1.1" 200 194 "-" "-"

3N37 commented 7 months ago

@Siftah , ok so it works? where does it get stuck?

Siftah commented 7 months ago

Times out when calling the ota_unlock :(

siftah@fozzie sonoff-ota-flash-cli-devid-fix % curl http://192.168.1.90:8081/zeroconf/ota_unlock -XPOST --data-raw '{"deviceid":"10009be24e","data":{} }' -v
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 192.168.1.90:8081...
* Connected to 192.168.1.90 (192.168.1.90) port 8081 (#0)
> POST /zeroconf/ota_unlock HTTP/1.1
> Host: 192.168.1.90:8081
> User-Agent: curl/8.1.2
> Accept: */*
> Content-Length: 36
> Content-Type: application/x-www-form-urlencoded
> 
* Empty reply from server
* Closing connection 0
curl: (52) Empty reply from server
siftah@fozzie sonoff-ota-flash-cli-devid-fix %
3N37 commented 7 months ago

@Siftah
check these 2 things :

  1. with wireshark or tcpdump check that the sonoff actually calls apid.coolkit.cn
  2. that the .htaccess file (must be placed in the root directory and then before flashing should be moved to v2) transforms the otaflash call to otaflash.php
Siftah commented 7 months ago

@3N37 Yes, both of those things are proven in the dumps I've pasted above;

  1. This is the Sonoff (192.168.1.90) on my local network making the POST to my server at 192.168.1.253: /var/log/apache2/access.log.1:192.168.1.90 - - [29/Nov/2023:14:32:42 +0100] "POST /v2/d/otaflash HTTP/1.1" 200 194 "-" "-"

  2. The last post confirms 2, that the URL is hit and the remote server is responding with the necessary response.

Thank you for your help, it's much appreciated! :)

3N37 commented 7 months ago

@Siftah ,

Siftah commented 7 months ago

I was not able to unlock it, because the curl times out and never completes.

I did use the manual procedure as explained in your .pdf, the logs I've pasted above show it being done and failing.

3N37 commented 7 months ago

i give up. i can still tell you that at the beginning i had the same errors as you , then applying the procedure as in the .pdf i was able to unlock them all . let me know if you solve

3N37 commented 7 months ago

this is the correct form

curl -XPOST --header "Content-Type: application/json" --data-raw '{"data": {}}' http://192.168.1.90:8081/zeroconf/ota_unlock

Siftah commented 7 months ago

@3N37 Exactly the same error.

siftah@fozzie ~ % curl -XPOST --header "Content-Type: application/json" --data-raw '{"data": {}}' 192.168.1.90:8081/zeroconf/ota_unlock
curl: (52) Empty reply from server
3N37 commented 7 months ago

@https://github.com/itead/Sonoff_Devices_DIY_Tools/issues/45

stefan-STMODE commented 3 months ago

i got i working after lots of testing and trying, i just upgraded 2 r2 mini's

both added first with eWeLink app and upgraded them from 3.6.0 to 3.7.6 with the use of the script i only get the deviceid number, one i flashed tasmota lite on with "postman" and with the deviceid filled in the other one failed even to get info from it, but this one i could flash with the DIY tool (v1.2.0)

3N37 commented 3 months ago

in a nutshell those with jumpers should be updated with the old way , those without external antenna and without jumpers with the procedure described above.

stefan-STMODE commented 3 months ago

it are "newer" ones with wifi inside

Gyrohammer commented 2 months ago

For some reason, the script was not working on a Mini (I think R1? I got it a long time ago) running firmware 3.7.6. I was able to get it working by completely removing the "deviceid" from the body variable in the sonoff_http_request function, and also from the ota_flash function.

That made the script start working and got Tasmota flashed.

Just used this method with a Mini R2 purchased a a few weeks ago and it worked! Thanks.