Developing a Binding for DLink Plugs

Hi All,

I have been using OpenHab for about a year now, recently upgraded to openhab2.

I found a nodejs package for managing the DLink Smart Plugs, and it works really well, however it would be really nice if it were available as a binding in OpenHab2. I have limited experience in java being primarily a .net developer. I have followed the instructions for setting up Eclipse and running the skeleton generation script. Everything looks good, but I am running into trouble.

I have figured out how to Export a .jar file to put into my openhab instance. First I am attempting just a basic logger.info and updateState command to see if I can get anything working. So far I am having no success getting anything to show up in OpenHab.

I have been unable to find any good directions for troubleshooting what could possible be wrong since nothing is showing up in the log files. Does anyone have a suggestion on how to get some response out of my skeleton Binding?

Edit:
Environment:
Developing on Windows 10 with Eclipse (installed following the directions on openhab)
Live instance a separate Windows 10 server running an openhab2 instance which was upgraded from openhab1

Edit 2:
Here is the updated link to the new dlink smarthome binding
https://drive.google.com/file/d/0Bw4h_PZMcXOGVVkyVDNiODVYa2M/view?usp=sharing

I found a setup tutorial for Eclipse that got me half running the OpenHab software in Eclipse for debugging purposes. Working might be an over statement, but it was enough to throw a few errors and at least let me clean up a couple items I had changed in the Binding code.

Now when I put the .jar file in my openhab instance and try to use a Switch with it I get this error in the log:
2017-02-28 15:33:11.681 [WARN ] [ome.core.thing.internal.ThingManager] - Cannot delegate update ‘OFF’ for item ‘TestPlug’ to handler for channel ‘dlinksmartplugs:dlinkplug:testplug:power’, because no thing with the UID ‘dlinksmartplugs:dlinkplug:testplug’ could be found.

I do have a dlinkplugs.things file that is being at least scanned.
2017-02-28 15:32:08.260 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘dlinkplugs.things’

inside of dlinkplugs.things is:
dlinksmartplugs:dlinkplug:testplug [ ipaddress=“192.168.1.11”, pincode=“123456” ]

I have read about other people having trouble with the manual .things files in openhab2. So I am wondering if this is my issue at this point, or is this the OpenHab2 core code?

Looks like I am doing things right according to this successful thread:

I tried creating a jar file from coolmasternet which did not work either, nothing shows up for bundle:list in the openhab console for either jar file.

I am running out of ideas, but it is looking more like an issue with my openhab install. Perhaps the upgrade did not go super smoothly. However, since it is a single folder on Windows 10 there does not seem to be much that could have gone wrong.

Does anyone know of a flag that needs to be set to have openhab start scanning the /openhab2/addons folder?

I think I finally spotted the issue. When I first started installing I killed the install and moved the folder from my downloads folder to the root of my drive. It looks like openhab is still looking for the addons folder in my downloads folder. So I need to figure out how to clean up the mess I created. Or just do a re-install:

2017-03-03 11:54:04.017 [WARN ] [org.apache.felix.fileinstall ] - C:\Users\admin\DOWNLO~1\OPENHA~1.0\addons does not exist, please create it.
2017-03-03 11:54:04.017 [WARN ] [org.apache.felix.fileinstall ] - Root path does not exist: C:\Users\admin\Downloads\OPENHA~1.0\addons

Edit:
I used the notepad++ mass search to fix all the paths pointed to the wrong place, and the error is no gone. However, it seems to have had no effect on the issue I am having.

I then tried a completely fresh install of openhab2, this time starting in the correct location. No change in my issue.

I just tried upgrading to the latest openhab-2.1.0-SNAPSHOT. As this thread indicates could be a potential fix:

Unfortunately the upgrade broke nearly everything. Paperui no longer worked, lots of errors in the log files, and the habmin app was not pulling good values. And of course my package built with “mvn install” is not showing up in feature:list. Does anyone have any ideas what is wrong? Is there a specific build I should target rather than the latest?

My Binding is now working quite well in Eclipse in debug mode. I rolled my openhab installation back to the stable version.

Hi,

how can I test your binding?

I tried already with this: http://rhapen.czweb.org/2016/04/11/d-link-smart-plug-dsp-w215-with-openhab/
but something is not working.

If that is not working for you it is probably because you do not have node.js installed.

Message me your email and I can send you the .jar file for openhab2. However, remember that so far I have been unsuccessful getting a custom .jar file to work in my actual openhab2 installation, and it will probably be awhile yet before this binding makes it into the official openhab code base.

How can I send you my email? Don’t find a way to send a PN.

I emailed you the binding. If you can get it to show up for you let me know what you did. I am still struggling to make it show up in a live environment.

I’ve got the code in github here if anyone can point out what I did wrong that the .jar file is not working in openhab2, but is working in Eclipse.

https://github.com/jeremeguenther/openhab2-addons/tree/master/addons/binding/org.openhab.binding.dlinksmartplugs

Edit: the code is now working. Just needs to be reviewed, then i’ll create a Pull Request.

Finally figured out my problem.
Turns out in the pom.xml the Packaging needed to be set to "eclipse-plugin"
eclipse-plugin

Sweet! I finally got it all working. My Amazon Echo can now control my DLink plug via openhab with the new binding.

Since I am getting no responses on this thread I am going to just go ahead and submit my pull request. I think I have gotten the majority of the contribution rules adhered to.

I ran the mvn clean install, and while it did fail, it did not fail on my binding. So I assume that means my binding is in the clear:
[INFO] DLinkSmartPlugs Binding … SUCCESS [ 1.078 s]
[INFO] Systeminfo Binding … SUCCESS [ 1.159 s]
[INFO] Systeminfo Binding Test … FAILURE [01:30 min]

I have found a small abnormality in my binding. I keep getting this error when trying to read input from a soap request.

[Fatal Error] :1:1: Premature end of file.

The odd part is that it is happening inside of a try/catch clause. The try/catch should be covering up communication issues, but in this case the error seems to bubble up through three try/catch’s to be displayed in the Karaf console. How do you stop an error that bubbles up through a try/catch like that?

For those who want to try the binding it is here:
EDIT: [link removed] updated link put in top post.

I will take it down eventually.

Hi,
First I would like to thank you for building this binding. I’ve been playing with your binding today (openhab2) and had a couple issues with consumption and temp, I’m in the US with DSP-w215A1 plugs with 1.24 version of firmware. I do have a node version running exec binding as well. This is functional but I had to adjust soapclient.js to work with this firmware as the moduleparameters are in different order. Below is my modified soapclient.js code. Just wondering if you have seen this issue and if not if you could incorporate this into your binding. I only tested consumption, totalconsumption and temperature so all the params would need to be checked.

exports.consumption = function () {
return soapAction(“GetCurrentPowerConsumption”, “CurrentConsumption”, requestBody(“GetCurrentPowerConsumption”, moduleParameters(3)));
};

exports.totalConsumption = function () {
return soapAction(“GetPMWarningThreshold”, “TotalConsumption”, requestBody(“GetPMWarningThreshold”, moduleParameters(3)));
};

exports.temperature = function () {
return soapAction(“GetCurrentTemperature”, “CurrentTemperature”, requestBody(“GetCurrentTemperature”, moduleParameters(2)));
};

The plug I have only supports On/Off/State. So I was unable to test the other ported code. However, I would certainly be willing to adjust things based on your feedback for the other areas.

Currently this binding is going through the process of being merged with another dlink binding. It’s going slow as I have not had time for this project, and won’t for a couple more weeks.

Also, I am moving away from the DLink plugs due to a bug in their firmware that causes the soap interface to lock up. I do still intend to finish the binding though.

@williamdm I uploaded a version with your moduleParameter updates. Give it a try. This is just a quick fix, but might help point in the right direction.

This binding is working great! Thank you for your efforts. I had this binding as exec bindings via nodejs.
This is much more user friendly :slight_smile:

@miklosandras what model of the plug are you using? What features are you using?

I’ve had a lot of issues with my plug freezing after about a day of constant polling. So i’ve had to set my polling window really high so it does not hit the plug much. Let me know if you see this issue.