LinuxChristian / pyW215

Python interface to the d-link W215 smart plug.
MIT License
37 stars 25 forks source link

Unable to open a connection to dlink switch <IP>: D-link W115 #27

Closed DanielAndreasen closed 4 years ago

DanielAndreasen commented 6 years ago

Hi Christian,

I'm sure this package is just what I need, however I can't get it to work with the W115 model (which I guess is fair since your package is called pyW215). But before I give up hopes, I just want to make sure I do the right thing.

  1. Connect with my laptop to the switch and obtain the IP address.
  2. Run the command as per the README, with the correct IP and pin code.

Then I get the above error. I also tried after being connected to my normal wifi, but I get the same error.

If this package is not supposed to work with the W115 model, can you then maybe point me in the right direction to either expand this by a PR or make a new from scratch?

Thanks for your effort :)

LinuxChristian commented 6 years ago

Hi Daniel,

I only own the W215 model but I know the software supports the W110 model so let's see if your 115 is not also supported. The error you are seeing is from the auth step when communicating with your plug. You can see the exception on line L328.

I would start by seeing if you can access

http://plug IP/HNAP1
http://plug IP/my_cgi.cgi

Then we can see if the interface is similar to the W215. If that works then do a git clone of the repo and try printing line 325. The auth step is quite complicated because it is not documented by D-Link but try poking abound in the auth function (print or pdb some variables) and see if anything pops out.

I am AFK for the next couple of days but let me know if you figure anything out. Hopefully we can it working.

nc-dtan commented 6 years ago

Hi Christan,

Mange tak. I will have a look during the weekend, and let you know how it goes.

Edit: Send from my work account, but same person :)

rafaelbiriba commented 5 years ago

Any news about how to connect to W115?

rafaelbiriba commented 5 years ago

Ok, problem solved! I got access to my DSP-W115! Using user Admin and password is the PIN code number and not the password.

So, we need to change the code to use the user with uppercase.

yoshienlin commented 5 years ago

I have the same issue on W115. I can access to both: http://plug IP/HNAP1 http://plug IP/my_cgi.cgi

However, the just cannot use the code to create a SmartPlug instance. Is there any way I can debug? thanks.

LinuxChristian commented 5 years ago

Hi @yoshienlin,

Can you add a bit more detail about what information you use to create the SmartPlug instance and how your setup is? The hardware version of your plug would be nice. Adding a print to line 325 would also give you some more information about what type of response your plug provides.

yoshienlin commented 5 years ago

Thanks @LinuxChristian for the reply.

The HW version of my W115 is: A1

adding a print to line 325 and got knew that the error was a HTTP Error 500: Internal Server Error error 500

Here is how I create the SmartPlug instance: In [1]: from pyW215.pyW215 import SmartPlug In [2]: sm = SmartPlug('192.168.1.44', '266150', 'Admin') Unable to open a connection to dlink switch 192.168.1.44

The smart plug was assigned the IP '192.168.1.44'. With the same information, I can log-in via the Chrome browser and got the below information: Firmware Version: 1.02-b04 Date: Nov 12, 2018 Checksum: 0x17A16B59 2.4GHz regulation domain: NA 1,2,3,4,5,6,7,8,9,10,11 2.4GHz SSID: DSP-W115-A424 LAN MAC: 00:AD:24:EA:A4:24 2.4GHz WLAN MAC: 00:AD:24:EA:A4:24

Any suggestion would be great appreciated.

Thanks.

LinuxChristian commented 5 years ago

Hmm. That does not look promising. Without some logs from the webserver (your plug) we cannot really get any closer to the error.

Perhaps they changed the login process. What information do you get when you visit the http://IP/HNAP1?

yoshienlin commented 5 years ago

This is what I get when I visit http:/IP/HNAP1 192 168 1 44

Here is the response if I only supply self.url to Request. : response = urlopen(Request(self.url)) output from 192 168 1 44

It failed when I supplied payload to Request.

Thanks a lot for your reply and help.

LinuxChristian commented 5 years ago

Have you tried to login with your PIN as password and admin as the user?

rafaelbiriba commented 5 years ago

same issue here... this is the maximum that I can do with my W155: image

tried HNAP1 endpoint, and after login I got the redirection above.

LinuxChristian commented 5 years ago

Okay.. well then the login feature works on you device. Then they have most likely change the login setup for the W115.

The only way forward is then to open the developer toolbox in your browser and investigate what passes over the wire when you login via the browser. That may shed some light on what has changed. Exactly what you are looking for? I don't know. But you can see the XML payload I send with the request to login. Perhaps see if you can find the same payload for your device.

rafaelbiriba commented 5 years ago

After the login, it redirects to the same /login with the user and password on the url. Is a GET request. there is no XML :(

LinuxChristian commented 5 years ago

Hmm... Then I don't really how we can gain more information to fix this. I found the current protocol online so I don't know how to decode it from scratch.

jonassjoh commented 4 years ago

In case anyone is still interested. The W115 and W245 do not use the HNAP1 protocol to control the device. The devices will just respond with generic error messages for any HNAP1 request.

As a result of a project of mine, I created a library to interface with these devices (and possibly others that I am unaware of). You can find the repository here.

https://github.com/jonassjoh/dspW245

LinuxChristian commented 4 years ago

Cool! @jonassjoh, thanks for sharing. I have added a link to your library in the README so it is easier for people to find.

I know most people use this library through home-assistant. If you find the time it could be cool to add support for your library in the existing hass integration, https://www.home-assistant.io/integrations/dlink/

LinuxChristian commented 4 years ago

Well, I guess that closes this issue. @DanielAndreasen and @rafaelbiriba - hopefully, that solves your issues getting the W115 running.

jonassjoh commented 4 years ago

I don't think I'll ever get around to adding it to home-assistant since I won't have access to the plug for much longer. Although if someone else is up for it they are more than welcome to do so.

DanielAndreasen commented 4 years ago

I haven't played with this since I opened up this issue. I think I'll give it another go one of these days. Thanks guys :)