itead / Sonoff_Devices_DIY_Tools

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

Feature Request: Encryption support (which will support for non DIY switches with firmware v3+) #3

Closed mattsaxon closed 4 years ago

mattsaxon commented 5 years ago

Thanks for the implementation, it runs for me now. However the code is not discovering any devices on my LAN.

I appreciate I don't have an R3 device, but it looks like the new 3.0.x firmware that I have downloaded to my S26 device implements exactly the interface described in the PDF in this repo.

However the mDNS.py file specifically filters by type = 'diy_plug', the type reported by S26 is just 'plug'.

When I change this in the code, I get a failure due to the code in this repository not having encryption implemented.

What are the plans for this code to support other devices at latest firmware and/or to support encryption?

martin3000 commented 5 years ago

if I run mdns-scan, I don't see my r2 sonoff with firmware 3.1!?

ZZLinvec commented 5 years ago

In DIY mode, the device has no encrypted information.

We haven't had a plan to support encryption for nearly a month.

Currently, this tool only supports Basic R3, RFR3 and mini.

I'm so sorry!Neither S26 nor r2 supports the DIY model.

mattsaxon commented 5 years ago

@ZZLinvec, would you consider accepting pull requests from outside ITEAD that add encryption support to the existing code base? I have a working prototype based on PyCryptodome

mattsaxon commented 5 years ago

@martin3000, mine is visible in mdns, i have blocked by device from accessing the Internet, so that could be the reason? My firmware is 3.0.1.

To be clear, it is NOT visible in the tool in this repo at present.

ZZLinvec commented 5 years ago

@mattsaxon Thank you very much. Your suggestion is very good.We just don't have any plans to add encryption right now.You can tell me about your library connection, and if we use encryption in the future, we will prioritize it.

mattsaxon commented 5 years ago

I have created a minimal commit here in my forked repo. I appreciate this is not ready for merging by some stretch, but I wanted others to be aware I was working on this.

If you insert your API key in the code, the UI works to report the status of my S26 device with firmware 3.0.1

@peterbuga, are you interested in collaborating on this as I see you have forked the repo too?

peterbuga commented 5 years ago

@mattsaxon thanks for the proposal but after I've spent enough time trying to reverse engineer the sonoff devices I've seen the bad part of it and I prefer to keep out of any official implementation. any changes that I might do to this fork I'll solely keep it that way and no future PRs.

hdjweb commented 5 years ago

So peterbuga have you abandoned the project of your wonderful custom component???? No please help us with your wonderful project.

gambalaya commented 5 years ago

@mattsaxon - I was pleasantly surprised to discover that your forked repo version with encryption support successfully finds and faithfully reports status on my non-DIY 4ch Pro with firmware 3.0.1 (with tweaks to accommodate the longer status by concatenating data1 + data2 + data3 payloads, retrieving only the first subkey of switches (plural), and adding type of 'strip' to the mdns search types). However it ignores any control commands, even though it returns success status. Were you able to open/close your S26 with your forked version? I can see my 4ch Pro is actually reading the /switch control command because it returns 0, whereas sending to /switches (as an experiment) returns error 400. I guess the control API's of my 4ch Pro are just dummy placeholders - so close! @ZZLinvec - nice to see this tool, and here's another vote for supporting non-DIY switches one day (even though there are no current plans to do so).

mattsaxon commented 5 years ago

Yes, the S26 works well with this. I think the switch command is different for multi-channels. I don't own one so can't work this through, but I suspect you would be able to trace your network whilst running eWeLink to work out the correct JSON format for multi-channel switches.

gambalaya commented 5 years ago

@mattsaxon, thanks for the confirmation on S26. I now realize the eWeLink app itself doesn't seem to find the 4ch Pro in LAN mode (even though your tweaked tool clearly does, and the Pro is in double-blinking mode etc). The iPhone app says connecting to 0 devices in LAN mode and grey's out the device when it is blocked from the internet. An iTead support article mentions S26 supports LAN mode but 4ch Pro doesn't. I think I will park any further investigation until there is more clear support from iTead for the Pro. Great work, and I am still surprised the tool communicates with the Pro at all given the above!

mattsaxon commented 5 years ago

For V3 firmware, the 'found x devices in LAN mode' should not be trusted, this is only referring to pre V3 firmware's found! You can tell if it is in LAN mode for V3+ by looking at the icon of the device.