itead / Sonoff_Devices_DIY_Tools

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

Cannot flash Tasmota OTA using DIY mode #95

Open jds11111 opened 3 years ago

jds11111 commented 3 years ago

I am working from linux, and using curl to send JSON posts to the device. I can get it into pairing mode, log it into my WiFi network, and see it. I can query it for info to get the deviceid. I can unlock the ota_flash. Everything works according to documentation as expected. However, when I try to flash it, it sends an empty return, and never flashes. I have set up a webserver on my desktop, which I can confirm is reachable by other devices on the network.

This is the command:

curl http://$DEVICE_IP:8081/zeroconf/ota_flash -XPOST --data '{"deviceid":"$DEVICE_ID","data":{"downloadUrl": "http://$WEBSERVER_IP/tasmota-lite.bin", "sha256sum": "$SHASUM"} }'

Where I have triple checked that the variable values are correct. In fact, I have also tried replacing the variables with the known values. Unfortunately, there is no log or any info of value returned to debug, except "curl: (52) Empty reply from server."

gaco79 commented 3 years ago

Same here.

Sonoff Mini on 3.6.0 firmware

jds11111 commented 3 years ago

Same here.

Sonoff Mini on 3.6.0 firmware

I eventually got all three to work, but it took multiple efforts. I still don't know what was done differently to get it to work. I think that just leaving it switched on for a long time might have helped. But who knows. One of those empty returns actually meant that it flashed, and when I rebooted, it finally had Tasmota. My only suggestion is to keep trying. If you figure out what the proper sequence of rebooting, time waiting, time hurrying, how many times you swing the dead chicken, etc., I would love to know, and probably others, too.

gaco79 commented 3 years ago

Working here now. Had to use a local web server, couldn't get it to work from an online site.

Malarcy commented 3 years ago

Having (I think) the same issue, firmware appears to download, Sonoff finishes the sequence for downloading and then tries a POST to an endpoint /api/device/otaflash - in there (in wireshark) I see json payload off error:409 That isn't documented as a response to the ota_flash rest call. The MINI doesn't do anything after this exchange and restarting it shows the flash hasn't happened.

marcinprzybysz86 commented 3 years ago

got the same problem, /zeroconf/info works, /zeroconf/ota_unlock also. But when I pass command to /ota_flash i have to wait like 5-10 mins and in the end i got: Error: socket hang up

f0ff886f commented 3 years ago

I think that the Sonoff is trying to request a file from a separate URL, its hard to see but in my webserver logs I see this line spam over and over:

Nov 08 15:56:53 bank caddy[3070669]: 2020/11/08 15:56:53 [INFO] dl.itead.cn - No such site at :80 (Remote: 10.0.0.162, Referer: )

After issuing

curl http://10.0.0.162:8081/zeroconf/ota_flash -XPOST --data '{"deviceid":"1000b8c61","data":{"downloadUrl": "http://10.0.0.11/tasmota-lite.bin", "sha256sum": "b8a16f18a018bd6233170ce28a625508c38770d9d8ef195c7afa50f914c4ac9c"} }'
KrzysztofDziankowski commented 3 years ago

I had exactly the same issue with my Sonoff MINIR2 fwVersion 3.6.0 After successful '/zeroconf/ota_flash' REST request, Sonoff tries to reach firmware passing following HTTP headers:

    Host: dl.itead.cn\r\n
    Range: bytes=0-4095\r\n
    User-Agent: itead-device\r\n

'Host' header is hard-coded to 'dl.itead.cn'

'Range' header is used to download only a partial of data.

njh commented 3 years ago

I have been working on a command-line Bash script for OTA flashing of the Sonoff firmware: https://github.com/njh/sonoff-ota-flash-cli

The Sonoff Minis that I bought came with version 3.5.0.

I have also experienced the problem of the Sonoff Firmware hardcoding the Host heading to dl.itead.cn. In the end I setup my own server (nginx) which also accepts the dl.itead.cn virtual host: http://sonoff-ota.aelius.com/

ne0rb commented 3 years ago

OTA_UNLOCK - not working ota_unlock command solution SonOFF mini R2 3.6.0 firmware

Device that creating hotspot / access point (sonoffDiy network) need also have access to internet, without access to internet command ota_unlock is not working

Solution found in reddit: https://www.reddit.com/r/sonoff/comments/je63tg/is_ota_unlock_broken_in_360/

charlesmerlen commented 3 years ago

OTA_UNLOCK - not working ota_unlock command solution SonOFF mini R2 3.6.0 firmware

Device that creating hotspot / access point (sonoffDiy network) need also have access to internet, without access to internet command ota_unlock is not working

Solution found in reddit: https://www.reddit.com/r/sonoff/comments/je63tg/is_ota_unlock_broken_in_360/

I've put my Mini R2 into DIY Mode. fw3.6.0 And with Postman, i can access to API of the Module, but impossible to Flash on OTA.

But with the solution of the .sh script, that work well for me. Very easy !
(Mac Os)

njh commented 3 years ago

I bought some Sonoff Mini R2s recently, which came with Firmware 3.6.0.

I have flashed one so far but had no trouble putting it into DIY Mode and then unlock it and flash it with Tasmota using my sonoff-ota-flash.sh shell script.

sygad commented 4 months ago

Apologies for dragging up an old thread, but I have a slightly newer Mini R2 firmware (3.7.6) and a different problem if anyone can help.

I followed all the steps, got to OTA onlock successful.

image

I then ran the script, the "getting module info" took about 5-8mins and did nothing.

I've never seen this output and am quite stuck now.

Any ideas how to progress? (p.s. not very Linux savvy)

Checking new firmware file exists
OK

Looking up sha256sum for firmware
OK

Searching for Sonoff module on network...
Found module on network.
Hostname: eWeLink_1001faa309
IPv4 Address: 192.168.20.19

Getting Module Info...
curl: (52) Empty reply from server
Error posting to: http://192.168.20.19:8081/zeroconf/info
sygad commented 1 month ago

UPDATE SOLVED:

Edit the ota-flash.sh script

_sonoff_httprequest() function

# ---------------------------------------------
# Remove the DEVICE ID paramater
# body='{"deviceid":"","data":{}}'
# ---------------------------------------------
body='{"data":{}}'

_otaflash() function

# -----------------------------------------------------------------------------------------------------------------------------------------------
# Remove the DEVICE ID paramater
# sonoff_http_request "${IPADDRESS}" ota_flash "{\"deviceid\":\"\",\"data\":{\"downloadUrl\":\"${FIRMWARE_URL}\",\"sha256sum\":\"${SHASUM}\"}}"
# -----------------------------------------------------------------------------------------------------------------------------------------------
sonoff_http_request "${IPADDRESS}" ota_flash "{\"data\":{\"downloadUrl\":\"${FIRMWARE_URL}\",\"sha256sum\":\"${SHASUM}\"}}"