itead / Sonoff_Devices_DIY_Tools

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

Sonoff basic R2 (firmware 3.5.0) doesnt switch to DIY mode #106

Open kostyan-git opened 3 years ago

kostyan-git commented 3 years ago

Hello there! I am really don`t know where i should ask, so I ask here.

I have Sonoff Basic R2 with 3.5.0 firmware and I am going to use it at LAN without chines cloud. So, I need to switch it to DIY mode. Official Itead sources doesnt associate the R2 with DIY mode, BUT the device answered when I pushed http GET, so I start thinking that device might be working in LAN. My sequence:

1 Hold button for 5 sec until led change his state. 2 Hold button again for 5 sec until the led start fast blinking 3 Connect to Itead-XXXXX wifi with 12345678 pass 4 Push HTTP GET request to address http://10.10.7.1/device and have got the answer:

{
"deviceid": "1000efe4ab",
"apikey": "cf0a7148-1c09-4a57-9424-5f8d53059600",
"accept": "post",
"chipid": "00FB6381"
}

4.1 Tools mentioned at github.com/itead/Sonoff_Devices_DIY_Tools doesn`t works 4.2 In browser "The page unareacheble" by goes to http://10.10.7.1 4.3 That it. No any POST request give results.

Who can suggest steps 5 and so on) PS Sorry for my English, I am not native.

sasog23 commented 3 years ago

same here.. did you have any success resolving this issue

kostyan-git commented 3 years ago

same here.. did you have any success resolving this issue

Nope. After a many unsuccessful tries I uploaded a tasmota firmware. But I still interested in that.

DoctorSclero commented 3 years ago

Maybe you can try to force the form data to the sonoff by sending a form request. It's quite difficult because you have to match the field names, but it is still an option.

bartlomiejborzucki commented 3 years ago

I have the same problem. IMHO Sonoff Basic R2 doesn't have a DIY mode :( I also tried change the firmware using OTA but I failed :(

n4dwxihyeyhes2 commented 2 years ago

Hello all, I've got Sonoff basic R2 on original 3.5.0 firmware and it works perfectly in LAN thanks to SonoffLAN custom component for HomeAssistant. From what I tried to understand from its code, SonoffLAN discovers and reads state of eWeLink devices using mDNS. I don't know how it sends state updates, but everything should be in the Python code in this repo. I know this isn't exactly the DYI mode like in R3 but for me it's enough - exactly what I need for my home automation.

jhdutoit commented 2 years ago

same here.. did you have any success resolving this issue

Nope. After a many unsuccessful tries I uploaded a tasmota firmware. But I still interested in that.

Hi, how dis you upload the Tasmota firmware? Serially?

n4dwxihyeyhes2 commented 2 years ago

I looked into SonoffLAN code and it uses http://<host>:8081/zeroconf/switch API endpoint to send state updates to the device. Payload must be encrypted with AES (devicekey is the encryption key). I experimented with other API endpoints documented by Itead for newer devices (/zeroconf/info, /zeroconf/ota_unlock) but consistently received error code 422, only /zeroconf/switch returns error code 0 and actually does its job.

khanh41 commented 2 years ago

I think basic R2 doesn't support DIY mode https://sonoff.tech/product/diy-smart-switch/basicr2/ DIY mode is the new feature of basic r3

n4dwxihyeyhes2 commented 2 years ago

@khanh41 you're right, basic R2 doesn't have full DIY mode known from basic R3 . However, some simple functionalities do work on R2 (like setting switch state through /zeroconf/switch API endpoint).

khanh41 commented 2 years ago

@n4dwxihyeyhes2 but i can't call that api, do i need to make BasicR2's ip address public or not if connect same wifi?

n4dwxihyeyhes2 commented 2 years ago

@khanh41 the IP address doesn't need to be public if you're on the same WiFi. What do you mean by

i can't call that api

do you get any error message? Does your R2 respond to ping? (mine does).

bartlomiejborzucki commented 2 years ago

Maybe this is the key: Payload must be encrypted with AES (device key is the encryption key). @n4dwxihyeyhes2 Could you create some tutorial on how you get it? Or maybe you could create a tutorial on how to use R2 on local mode (without cloud)

n4dwxihyeyhes2 commented 2 years ago

@bartlomiejborzucki steps to get the device key are described in the OP:

1 Hold button for 5 sec until led change his state. 2 Hold button again for 5 sec until the led start fast blinking 3 Connect to Itead-XXXXX wifi with 12345678 pass 4 Push HTTP GET request to address http://10.10.7.1/device

The apikey response field is the encryption key. Encryption/decryption functions are here: https://github.com/AlexxIT/SonoffLAN/blob/master/custom_components/sonoff/sonoff_local.py#L37

More user-friendly option is to use Home Assistant with SonoffLAN custom component - it is available through HACS.

khanh41 commented 2 years ago

do you get any error message? Does your R2 respond to ping? (mine does).

@n4dwxihyeyhes2 I can ping to R2, but when i use postman with:

It take too much time for a response and get "Could not get response".

3 Connect to Itead-XXXXX wifi with 12345678 pass 4 Push HTTP GET request to address http://10.10.7.1/device

When i connect basic R2 with my mobile phone, It not show step 3 and i can't request as step 4

n4dwxihyeyhes2 commented 2 years ago

@khanh41

It take too much time for a response and get "Could not get response".

That's exactly the symptoms that I got as well when experimenting with unencrypted communication. You have to encrypt the payload with AES.

When i connect basic R2 with my mobile phone, It not show step 3 and i can't request as step 4

I'm not 100% sure what you mean by that but did you follow the procedure (steps 1. and 2.)? You have to press and hold the button for 5 seconds, then release it for a moment, and again press and hold for another 5 secods. The LED should start blinking fast and the 'ITEADxxxxx' SSID should become available.

sheppyh commented 1 year ago

I got this working on a Sonoff Basic R2 by blocking it's access to the internet, which puts it into LAN mode when it boots up. Before blocking it would multicast that the device has been turned on/off via Ewelink app, but could not be controlled locally. After blocking, both worked

Source: https://curatedpython.com/p/no-longer-beveradb-sonoff-lan-mode-homeassistant/index.html

johanviv commented 1 year ago

Maybe this is the key: Payload must be encrypted with AES (device key is the encryption key). @n4dwxihyeyhes2 Could you create some tutorial on how you get it? Or maybe you could create a tutorial on how to use R2 on local mode (without cloud)

This might help. I hacked and slashed the code at https://github.com/AlexxIT/SonoffLAN/blob/master/custom_components/sonoff/core/ewelink/local.py to create a standalone python script that can switch a sonoff basicr2. Apologies for the quality of the code, I am not experienced in Python. You will need the device IP, key and ID, as described in the previous posts.

Have to provide 'on' or 'off' as the first command line parameter switch_sonoff_basicr2.txt

johanviv commented 5 months ago

Hi

You need to change the script and fill in the DEVICEKEY, DEVICEID and IPADDRESS

[image: image.png]

On Tue, 30 Jan 2024 at 21:36, leosoftGR @.***> wrote:

Hello @jonhviv

I tried your python script, put in deviceid and IP (on the url) but nothing happen when i execute it with on or off. Do I need to know the apikey?

— Reply to this email directly, view it on GitHub https://github.com/itead/Sonoff_Devices_DIY_Tools/issues/106#issuecomment-1917752170, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADA3XNHWPEL3VBXAWABNW4DYRFDUTAVCNFSM4VXVBX72U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJRG43TKMRRG4YA . You are receiving this because you commented.Message ID: @.***>

leosoftGR commented 5 months ago

Hello,

Thanks. Now works fine for me.

Btw, I am looking for a similar function to be able to call it from within arduino code. Any ideas?