Help with a Couple of Errors in First Device Driver

Hi all,
After several weeks of reading and experimenting I believe I have created my first device driver. I have no previous coding experience, when I started in electronics vacuum valves were still around! But, thanks to the wealth of existing code out there, I managed to cobble together a driver for the ZConnect Garage Door Controller. This is a multi channel device available in Australia consisting of 2 binary switches and 2 binary sensors in the one package.
It joins the Z-Wave network securely as a generic device and I then apply my driver. I do it this way because if I create a mfr fingerprint it seems to hang at "initialize".
Anyway after creating the child devices I end up with this.


Everything seems to work well with the exception of two errors in the log. Firstly when I do a refresh, I get:
019-09-24 17:00:31.002 errorjava.lang.NullPointerException: null on line 277 (refresh)
Secondly, when I try operate the second switch from the parent device using the childon/off commands I get:
2019-09-24 17:01:16.843 errorjava.lang.NullPointerException: Cannot invoke method split() on null object on line 258 (childOn)
As I mentioned I have virtually no coding experience, I'm teaching myself as I go. Could I ask if someone could firstly check my coding to see why I'm getting these errors and secondly suggest any improvements I could make.
Oh, and most importantly what is the easiest way to put my code up for inspection?

Cheers,
Darren

Unfortunately, I don’t have time to check through your code as I am tied up with so much work.
However; I can give you a couple of pointers...

If you read the error messages they are actually telling you what is wrong and where to look.
The first one says look on line 277 of you code.
This line has a ‘variable’ in it which should have a value.. the error says it can’t find the value
(I.e. it is ‘null’ or nothing)
So trace that variable name to see where it should pick up a value.. something is missing and it’s not getting one (so the device can’t use/process it)

It seems a similar error is on line 258, although it’s a different message the cause is the same.. no (null) value in a variable.

As you are free to install any code in HE you don’t need to have it ‘inspected’
However, if you feel the code might be useful for others, you can always post it in the code catagory of the forum once you have it working.

If you still have problems finding the issue you will need to post those two lines of code along with a couple of lines before and after them.
Pehaps someone will be able to help.

Andy

3 Likes

Thanks for the reply Andy.
I have used the pointers to line numbers in error messages when sorting out the many mistakes I made when creating the driver. These particular messages have me stumped because I don't really understand the expressions used in the code. It's a very steep learning curve.
With regards "2019-09-24 17:01:16.843 errorjava.lang.NullPointerException: Cannot invoke method split() on null object on line 258 (childOn)", here is the code in question:

private channelNumber(String dni) {
def ch = dni.split("-")[-1] as Integer
return ch
}

And with "019-09-24 17:00:31.002 errorjava.lang.NullPointerException: null on line 277 (refresh)" it's:
private encap(cmd, endpoint) {
if (endpoint) {
zwave.multiChannelV3.multiChannelCmdEncap(destinationEndPoint:endpoint).encapsulate(cmd).format()
} else {
cmd.format()
}
}

The reason I wanted real programmers to look at my driver is to make sure I don't have any redundant stuff in there or code that could be written in a more streamlined fashion. Also, even though the device joins the network securely there is no reference to secure commands in the driver. I see some drivers deal with secure inclusion. Should mine have it?
When I have ironed out the last few issues I intend to try and code in some of the more useful parameters, as I've seen in many drivers.
I'd also like to investigate the possibility of having a "switchable" custom attribute of say "Clear:Obstructed" for when S1 is used for an IR beam.

Anyway thats for later.
Thanks again.

Darren

So that error is telling you that it's trying to call the function split() on the object/variable dni, but dni isn't set to anything and hence the error is produced. So you need to work back through your code and find the places that call the channelNumber function (just search for all occurrences). Look at what variable they call channelNumber with and see if it's null or could be null.

Try putting debug log (print) functions in the code in various places to see what the values are, and watch the Logs page of your hub's website.

1 Like

Okay, so my errors are sorted. Thanks to Andy and Paul. The ChildOn error turns out to be a function of the device driver I based mine on. The commands on the parent device were never meant to be used, they are just there for the child device to reference.
The Refresh error was an incorrect command I had in the child device section to be sent. Refresh works fine now. Thanks again.