Developing a Binding for DLink Plugs

Mine model is DSP W215. It is used to change the state to offline (freezing), but I thought may I did wrong anything.

I used this one as exec binding before.
http://rhapen.czweb.org/2016/04/11/d-link-smart-plug-dsp-w215-with-openhab/
Until used this, I had no freezing issues.

@miklosandras good, my model is DSP-W110 this gives me a broader range for testing which is nice.

When you had the nodejs implementation in place, did you have it pulling the plug state every few seconds? Or did you just have it turning the plug on and off?

It’s the pulling of the plug state so frequently that seems to hang the DLink firmware. I intend to allow pulling to be turned off in the next major version of the plugin. But for now, if you just set the pulling value really high, like 99999, see if that helps with the freezing issue.

@Jereme_Guenther Here was my script for my Work room e-plug.

root@raspberrypi:/usr/share/openhab2/dlink_dsp# cat work_room_app.js
/**
 * Tool for reading data from D-Link DSP-W215 Home Smart Plug.
 *
 * Usage: enter your PIN code to LOGIN_PWD, change value of HNAP_URL according to your device settings.
 *
 * @type {exports|module.exports}
 */
var soapclient = require('./js/soapclient');
var fs = require('fs');
var OUTPUT_FILE = "work_room_result.txt";
var LOGIN_USER = "admin";
var LOGIN_PWD = "code";
var HNAP_URL = "http://192.168.1.152/HNAP1";
var POLLING_INTERVAL = 60000;

var sys = require('util')
var exec = require('child_process').exec;

var args = process.argv.slice(2);

soapclient.login(LOGIN_USER, LOGIN_PWD, HNAP_URL).done(function (status) {

if (!status) {
  throw "Login failed!";
}
if (status != "success") {
  throw "Login failed!";
}

if (args == "on" || args == "On") {
  soapclient.on();
  exec('curl -s -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "state" "http://localhost:8080/rest/items/DSPW215WorkRoom_Input" > /dev/null');
}
if (args == "off" || args == "Off"){
  soapclient.off();
  exec('curl -s -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "state" "http://localhost:8080/rest/items/DSPW215WorkRoom_Input" > /dev/null');
}
if (args == "power" || args == "Power"){
  soapclient.consumption().done(function (power) {
    console.log(power+" W");
  });
}
if (args == "total" || args == "Total"){
  soapclient.totalConsumption().done(function (power) {
    console.log(power+" kWh");
  });
}
if (args == "temp" || args == "Temp"){
  soapclient.temperature().done(function (temperature) {
    console.log(temperature+" C");
  });
}
if (args == "state" || args == "State"){
  soapclient.state().done(function (state) {
    if(state == "true"){
      console.log("ON");
    } else {
      console.log("OFF");
    }
  });;
}

});

This was worked well. Unfortunately my e-plug again freezed. This is mean that all request will be error 500:

error: { Error: Server responded with status code 500:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <title>500 - Internal Server Error</title>
 </head>
 <body>
  <h1>500 - Internal Server Error</h1>
 </body>
</html>

    at Response.getBody (/usr/share/openhab2/dlink_dsp/node_modules/then-request/node_modules/http-response-object/index.js:34:15)
    at /usr/share/openhab2/dlink_dsp/js/soapclient.js:27:36
    at tryCallOne (/usr/share/openhab2/dlink_dsp/node_modules/then-request/node_modules/promise/lib/core.js:37:12)
    at /usr/share/openhab2/dlink_dsp/node_modules/then-request/node_modules/promise/lib/core.js:123:15
    at flush (/usr/share/openhab2/dlink_dsp/node_modules/then-request/node_modules/promise/node_modules/asap/raw.js:50:29)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)
  statusCode: 500,
  headers:
   { 'content-type': 'text/html',
     'content-length': '369',
     connection: 'close',
     date: 'Tue, 18 Apr 2017 13:26:08 GMT',
     server: 'lighttpd/1.4.34' },
  body: <Buffer 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 69 73 6f 2d 38 38 35 39 2d 31 22 3f 3e 0a 3c 21 44 4f 43 54 ... >,
  url: undefined }

/usr/share/openhab2/dlink_dsp/node_modules/then-request/node_modules/promise/lib/done.js:10
      throw err;
      ^
Login failed!

Are you using the nodejs code in combination with my binding?
Is your plug freezing after a period of time when you just use the nodejs code by itself?
Are you just using the on/off feature, or are you checking for temp/power/state/etc as well when using the nodejs code?

I did not used your binding and the exec binding version at the same time. This is only freezed when I used this binding. It is used to freeze after a day or 2. If need, I can check the proper amount of time, if needed.

Now, I am using the exec binding (on, off, state) with Interval 600 and Autorun. The Mon(itoring) is running with interval 60.

Let me know, if need anything else.

It sounds like you are saying you use the exec binding with nodejs and an interval of 60 seconds and have no flreezing issues at all?

But when you switch to using the dlink java binding you start having freezing issues. Do you have the dlink binding set to 60 second intervals as well?

This is very unexpected, I might have to fire up my nodejs again to verify. Unless it is a java issue, I would expect the problem to be consistent across both the dlink binding and the exec binding.

Okay, exec binding removed, and added this binding again. I set them Refresh Interval to 60s , and Soap Call Timeout to 60000. Let me check how will working. I will let you know if anyone will freeze. But I hope, this will be okay :slight_smile:

@Jereme_Guenther, after reading some of the comments on this thread i was inspired to do some more testing on my DLink motion sensor binding.

To see if it made any difference I swapped to using the Jetty HttpClient and surprisingly it does seem to make a difference. One of my motion sensors which would regularly freeze after about 4-6 hours ran for 12 hours without issue.

I noticed it happened to be offline in the dlink app during that time so I restarted it this morning to do a proper test and it’s been running for over 8 hours.

I’ll see how they behave over the next couple of days and let you know.

@MikeJMajor that’s awesome. You are one step ahead of me. I have the nodejs setup running and was letting it run for several days to prove that it really does not have issues. If you have already identified the java side issue that is fantastic.

Hi,
I’m really new to all of this and have had a really steep learning curve thus far trying to get the Dlink smart plug to work . How did you set up the exec binding. Currently I can get the Dlink plug to operate via node app.js using terminal.

I used the scripting from http://rhapen.czweb.org/2016/04/11/d-link-smart-plug-dsp-w215-with-openhab/

Thanks in advance

You are looking at the right base post. The problem is that the OpenHab 2.0 Exec binding lost a lot of functionality. Hopefully someone comes along and makes it more convenient and more like it’s 1.0 version. Hopefully there will be a working version of this DLink binding we are working on sometime in the next month or two.

In the meantime, here are the exec configs I am using for testing.

ITEMS:
String DSPW215 “dsp-w215” { channel=“exec:command:internetplug:input”}
String DSPW215s “dsp-status [%s]” { channel=“exec:command:testplug:output”}

SITEMAP:
Switch item=DSPW215 mappings=[“on”=“on”, “off”=“off”]
Text item=DSPW215s

PAPERUI config:
internetplug (interval=0 autorun=on):
node C:<JsFilePath>\dsp-w215-hnap-master\app.js %2$s
testplug (interval=10, autorun=off):
node C:<JsFilePath>\dsp-w215-hnap-master\app.js state

1 Like

@Jereme_Guenther: I would like to inform you that I have no freeze since I set the Refresh Interval to 60s , and Soap Call Timeout to 60000 (4 days ago) in your binding, so this is really great :slight_smile:

1 Like

@Jereme_Guenther both my motion sensors have been running for 3 days (polling every second) without any issues, so I think using Jetty for the HTTP communication has fixed the freezing problem.

Where did you download and unzip the binding to get it to work?

@Jereme_Guenther provided at Marc 19. Here is his link: https://drive.google.com/open?id=0Bw4h_PZMcXOGUU5YTy1QSlE2bVU

Sorry my wording was a little confusing. I mean where do you place the downloaded file in the openhab file system so that I can use it. I noticed the zip file earlier in the thread.

Thanks for the reply though

Oh, okay, sorry, please place the JAR file into this directory: /usr/share/openhab2/addons/ and restart the openhab2 :wink:

1 Like

Thank you :blush:

OK so I’ve downloaded the JAR file and i placed it in directory : /usr/share/openhab2/addons/ however before unzipping it I had a quick peak on the computer i use for SSH. I notice that i have directories from another JAR file i downloaded from https://www.mysensors.org/, that are the same name if i unzip this binding wont it create havoc between the 2 bindings? I have the Dlink binding in another folder shown below.

[17:24:31] openhabian@openHABianPi:~$ cd /usr/share/openhab2/addons
[17:31:37] openhabian@openHABianPi:/usr/share/openhab2/addons$ ls
Dlinksmartplug ESH-INF META-INF org org.openhab.binding.mysensors-2.0.0-SNAPSHOT.jar OSGI-INF README
[17:31:39] openhabian@openHABianPi:/usr/share/openhab2/addons$ cd Dlinksmartplug/
[17:31:59] openhabian@openHABianPi:/usr/share/openhab2/addons/Dlinksmartplug$ ls
build.properties ESH-INF META-INF org org.openhab.binding.dlinksmartplugs-2.1.0-SNAPSHOT.jar OSGI-INF pom.xml README.md src target
[17:32:01] openhabian@openHABianPi:/usr/share/openhab2/addons/Dlinksmartplug$

I hope this sort of makes sense. Any ideas what i should do ?

Copy org.openhab.binding.connectsdk-2.1.0-SNAPSHOT.jar to /usr/share/openhab2/addons/ and that’s all. Please download the JAR file and place to that directory. The ZIP version need to be complie.

The directory should look like:

root@raspberrypi:/usr/share/openhab2/addons# ls -lrt
összesen 1384
-rw-rw-r-- 1 openhab openhab     70 febr  12 12:37 README
-rw-r--r-- 1 openhab openhab 886354 mĂĄrc  26 23:22 org.openhab.binding.connectsdk-2.1.0-SNAPSHOT.jar
-rw-r--r-- 1 openhab openhab 315477 ĂĄpr    6 00:00 org.openhab.binding.yeelight-2.1.0-SNAPSHOT.jar
-rw-r--r-- 1 openhab openhab 127023 ĂĄpr   11 22:44 org.openhab.binding.dlinksmartplugs-2.1.0-SNAPSHOT.jar
-rw-r--r-- 1 openhab openhab  73639 ĂĄpr   11 23:29 org.openhab.binding.mihome-2.1.0-SNAPSHOT.jar
root@raspberrypi:/usr/share/openhab2/addons#
1 Like