I switched from openhab1.7.0 to openhab2.1.0 and i’m having trouble with the http binding. i get the following error:
19:43:00.212 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.lang.NullPointerException
at org.eclipse.smarthome.transform.javascript.internal.JavaScriptTransformationService.transform(JavaScriptTransformationService.java:70)[220:org.eclipse.smarthome.transform.javascript:0.9.0.b5]
at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:60)[176:org.openhab.core.compat1x:2.1.0]
at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:189)[221:org.openhab.binding.http:1.10.0]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:157)[176:org.openhab.core.compat1x:2.1.0]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169)[176:org.openhab.core.compat1x:2.1.0]
I have no idea what is causing this error becouse the following worked in openhab1.6 without any problem:
Number Photo_WattsPhoto "Watt (Photovoltaik) [%.0f Watt]" (gPhoto,gPhotoWatt) {http="<[batterie:3000:JS(getWattPhoto.js)]"}
getWattPhoto.js:
(function(i) {
var txt = i.split('service="urn:psi-storage-com:serviceId:Photovoltaics1" variable="Watts" value="');
var txt2 = txt[1].split('"');
return txt2[0];
})(input)
# timeout in milliseconds for the http requests (optional, defaults to 5000)
#timeout=
# the interval in milliseconds when to find new refresh candidates
# (optional, defaults to 1000)
#granularity=
# whether to substitute the current time or state value into the URL
# (optional, defaults to true)
#format=
# configuration of the first cache item
batterie.url=http://192.168.0.12:3400/data_request?id=status&output_format=xml
batterie.updateInterval=3000
In the logs of openhab2 I can see the xml answer from the URL above. It was much to long to post it. Here a short snippet of the relevant part:
First of all, please read the readme @rlkoshak pointed to you, it shows the correct syntax for items in OH2 utilising the http-binding, which you are NOT using.
Secondly on your question concerning the “cache”;
Using the http-binding, you have the binding updating the information in the set interval. The updated information is held in the channel and can be used, displayed, persisted… in timesteps of your desire without further actual web-requests. Does that answer your question concerning the cache?
Sorry, I must have been looking something else! Yes, your item syntax is correct.
From reading the error, I would say the script is trying to get an array member which doesn’t exist. So you might not in your array “txt” or “txt2” what you think you are having.
thank you for your fast reply again. You are right I also thought this is the problem, but when I change the getWattPhoto.js for testing to:
(function(i) {
return 12;
})(input)
I get the same error. And the strange thing is that it is working in openhab1.7 with no problem.
So I think there must be another problem.
I do not know java really good but can you perhaps give me a hint where I can find the file JavaScriptTransformationService.java
So perhaps I can look at line 70 and see what is going on…
Because the source is shown in my log I think the problem perhaps is a not defined engine. So manager.getEngineByName(“javascript”) cannot find this engine. Is that possible?
I activeted the transform in PaperUI. Is there a way to check if it is working?
thank you for your help. I now found the real problem, while I was trying to use
bundle:list | grep JavaScript
The response was:
220 | Active | 75 | 0.9.0.b5 | Eclipse SmartHome JavaScript Transformation Service
So it seemed okay. But for some reason I switched to the log again and uninstalled and reinstalled the http binding. And then I saw the real error:
11:58:44.484 [ERROR] [ab.binding.http.internal.HttpBinding] - given config key 'format' does not follow the expected pattern '<id>.<url|updateInterval>'
So I changed the http.cfg config file (format=false):
# timeout in milliseconds for the http requests (optional, defaults to 5000)
#timeout=
# the interval in milliseconds when to find new refresh candidates
# (optional, defaults to 1000)
#granularity=
# whether to substitute the current time or state value into the URL
# (optional, defaults to true)
format=false
# configuration of the first cache item
batterie.url=http://192.168.0.12:3400/data_request?id=status&output_format=xml
batterie.updateInterval=3000
and now everything works again. That real error is only shown once at the installation and I have not seen it.
I thought the problem is fixed but after restarting openhab there was the problem again. I have not found a solution after a day searching so I now switch back to openhab 1.7 and stay there until there is a new version of the http binding which is working