• November 19, 2017, 12:52:01 AM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

This Forum Beta is ONLY for registered owners of D-Link products in the USA for which we have created boards at this time.

Pages: [1] 2

Author Topic: DSP-W215 - read values via HNAP protocol  (Read 9660 times)

pzelenka

  • Level 1 Member
  • *
  • Posts: 21
DSP-W215 - read values via HNAP protocol
« on: December 24, 2015, 06:37:00 AM »

Hi,

since I want to directly receive measured values from the smart plug I found this:
On the address http://<ip> you can login using PIN code. Then you are provided with basic device info.
On the address http://<ip>/HNAP1 there is a list of actions that you query the device.
After some days of playing with the HNAP I finally managed to retrieve measured values from the plug!
If anyone is intrested in I can provide more detailed info.

Pavel
« Last Edit: December 27, 2015, 05:05:13 AM by pzelenka »
Logged

ark0n3

  • Level 1 Member
  • *
  • Posts: 3
Re: DSP-W215 - read values via HNAP protocol
« Reply #1 on: January 04, 2016, 07:53:35 AM »

I'm interested! I would like to connect my nas (synology) to the smartplug in order to plot its values and keep yearly statistics.

thanks
Logged

pzelenka

  • Level 1 Member
  • *
  • Posts: 21
Re: DSP-W215 - read values via HNAP protocol
« Reply #2 on: January 04, 2016, 08:41:00 AM »

Coincidentally I applied the same approach. You can download the source code (JavaScript + Node.js) here: https://github.com/bikerp/dsp-w215-hnap
From Synology packages install Node.js
copy the app to desired folder
connect to Synology using Putty or similar app
In order to run the application as a background process I use NodeJS module "forever"

Cheers
Logged

ark0n3

  • Level 1 Member
  • *
  • Posts: 3
Re: DSP-W215 - read values via HNAP protocol
« Reply #3 on: January 12, 2016, 02:37:00 AM »

Coincidentally I applied the same approach. You can download the source code (JavaScript + Node.js) here: https://github.com/bikerp/dsp-w215-hnap
From Synology packages install Node.js
copy the app to desired folder
connect to Synology using Putty or similar app
In order to run the application as a background process I use NodeJS module "forever"

Cheers
thanks a lot, I'll try it asap!
Logged

tombevers

  • Level 1 Member
  • *
  • Posts: 4
Re: DSP-W215 - read values via HNAP protocol
« Reply #4 on: January 13, 2016, 01:37:35 PM »

Hi,

I'm also interested to read values from the plug,
and even better: control the plug with http commands.

Thanks in advance for tips and advise.

Logged

pzelenka

  • Level 1 Member
  • *
  • Posts: 21
Re: DSP-W215 - read values via HNAP protocol
« Reply #5 on: January 13, 2016, 01:42:01 PM »

Hi,
it is possible to fully control the device and read measured values. Check my github project here: https://github.com/bikerp/dsp-w215-hnap
You can find there basic info how to control the device and code written in JavaScript
I hope it will help you

Pavel

Logged

tombevers

  • Level 1 Member
  • *
  • Posts: 4
Re: DSP-W215 - read values via HNAP protocol
« Reply #6 on: January 14, 2016, 06:44:46 AM »

Hi,

I am not familiar with javascript, but I have notice of programing.

Do i have to compile the javascript?
How do I load the script into the plug? with putty software?

thanks a lot!

Tom
Logged

pzelenka

  • Level 1 Member
  • *
  • Posts: 21
Re: DSP-W215 - read values via HNAP protocol
« Reply #7 on: January 14, 2016, 12:07:22 PM »

The script is not supposed to run in the plug. It's a client that communicates with the plug via HTTP protocol. You have to run it on some computer.
As a runtime environment is used NodeJs. Steps how to run the app are described on wiki: https://github.com/bikerp/dsp-w215-hnap/wiki/How-to
Logged

tombevers

  • Level 1 Member
  • *
  • Posts: 4
Re: DSP-W215 - read values via HNAP protocol
« Reply #8 on: January 15, 2016, 07:40:16 AM »

OK,

in meanwhile I installed the node JS on my synology DS213, and uploaded the files from github.

Can you give me some more hints for controlling the smartplug by means of a http command to my diskstation?

as you can read... node js and this kind of software is new for me...

Thanks a lot!
Logged

pzelenka

  • Level 1 Member
  • *
  • Posts: 21
Re: DSP-W215 - read values via HNAP protocol
« Reply #9 on: January 15, 2016, 01:01:03 PM »

Download Putty which is a SSH client which provides terminal connection to your Synology diskstation.
Modify app.js and put PIC CODE to LOGIN_PWD and update IP address of the plug in HNAP_URL.
Connect to diskstation using Putty. Navigate to folder where you download the application (e.g. cd /volume1/home/hnap)
run the application: node app.js
once the application starts it connects to the plug, turn it on and every 60 seconds reads power consumption and temperature and saves those values into result.txt file.
Logged

Angakok

  • Level 1 Member
  • *
  • Posts: 5
Re: DSP-W215 - read values via HNAP protocol
« Reply #10 on: January 19, 2016, 08:10:56 AM »

Hi Pavel,

i've tried to use your documentation here: https://github.com/bikerp/dsp-w215-hnap/wiki/Authentication-process to proceed authentication on the plug, either with curl, either in python (with a soap client), but eachtime the server respond with the list of available soap action.

Could you explain me how exactly do you manage authentication ?
Logged

pzelenka

  • Level 1 Member
  • *
  • Posts: 21
Re: DSP-W215 - read values via HNAP protocol
« Reply #11 on: January 19, 2016, 10:22:45 AM »

Hi,

you have to send the requests via POST method. Keep in mind that the authentication process has two steps. In the first step you receive  Cookie,
Challenge and PublicKey values that are used to construct the second request. If you follow principle described on wiki than it should work. Be carefull that this was tested on firmware version 2.20

Pavel
Logged

Angakok

  • Level 1 Member
  • *
  • Posts: 5
Re: DSP-W215 - read values via HNAP protocol
« Reply #12 on: January 20, 2016, 12:38:02 AM »

Hi Pavel,

my request is a POST request but i don't receive a cookie ... the response is a GetDeviceSettingsResponse and not a LoginResponse.
I've probably missed something ...

my request :
 curl --header "Content-Type: text/xml; charset=utf-8" --header "SOAPAction: http://purenetworks.com/HNAP1/Login" --data @auth.xml http://192.168.60.9/HNAP1
With the input message in the auth.xml file.

Regards.
Logged

pzelenka

  • Level 1 Member
  • *
  • Posts: 21
Re: DSP-W215 - read values via HNAP protocol
« Reply #13 on: January 20, 2016, 02:02:36 AM »

Do you also send the proper body content?
Logged

Angakok

  • Level 1 Member
  • *
  • Posts: 5
Re: DSP-W215 - read values via HNAP protocol
« Reply #14 on: January 20, 2016, 03:41:57 AM »

here is the auth.xml file :
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Login xmlns="http://purenetworks.com/HNAP1/">
      <Action>request</Action>
      <Username>admin</Username>
      <LoginPassword/>
      <Captcha/>
    </Login>
  </soap:Body>
</soap:Envelope>
Logged
Pages: [1] 2