Http binding using a port number

Hi,

I just started playing with openHAB this weekend. I would like to query my CouchDB for data using the http binding. However, I am getting an error when it hits the port number section of the url. I’ve tried escaping the colon using the backslash.

How does one use the http binding when there’s a port number in the url?

Thanks for your help in advance!

Hi Michael,

You can easily use your own portnumbers in the http binding. If it works in a browser it usually also works in your items and rules. Below an example of my own installation, which gets the ON/OFF status from a wallplug.
String Circle_plus_stat “Circle_plus stat [%s]” (Switches) {http="<[http://localhost:8088/api/read.xml?mac=000D6F000278D3CF:6000:REGEX(.?(.?).*)]"}

Thanks! I just tried it and get the following error:
2015-11-08 15:42:49.354 [ERROR] [.service.AbstractActiveService] - Error while executing background thread Souliss Refresh Service
java.lang.NullPointerException: null
at org.openhab.binding.souliss.internal.SoulissBinding.execute(SoulissBinding.java:343) ~[na:na]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) ~[na:na]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) ~[na:na]

Here’s the offending line in my .items file:
String Text_ML_Living_2 “[%s]” (ML_Living) {http="<[http://10.0.0.251:5984/dev_home_data_v2/_design/views/_view/get_latest_temp_humid_by_iot_id:5000:REGEX(.?(.?).
)]"}

I suspect it is due to the httpbinding parsing the colon token where the port number is?

That error is coming from the Souliss binding, not the HTTP binding.

Yes, it is confusing. However, when I comment out this line of code everything works again as expected.

Michael,

I do not know the details of the soulis binding, so i cannot say if you need a regular expression like me. could you post here a working http request with its response in a browser as a first step ?
I assume something like “http://ip-addres of the soulis host:6000/anything else you need to get the desired value”

Gert

Sure. Here is the request url:
http://10.0.0.251:5984/dev_home_data_v2/_design/views/_view/get_latest_temp_humid_by_iot_id

Here is the response string:
{“rows”:[
{“key”:null,“value”:{“datetime”:“2015-11-08T21:06:24.501Z”,“temp”:“71.90”,“humid”:“32.70”}}
]}

I have 9 sensors working around my home using the ESP8266 module to publish temperature and humidity to an mqtt broker every 5 minutes. From there, I have the data sent to a CouchDB database in JSON format. I’ve been using Node-Red to orchestrate the system and an AngularJS page I developed to display the data. I recently came across openHAB and wanted to see if I could start porting my existing solution over as openHAB appears to be a more robust platform. I have plans to add controllers for lights, garage, etc.

Thanks!

Which version of the Souliss binding are you using? It looks like this line is causing a NullPointerException, but the code has changed since then. Try replacing the binding JAR in your addons folder with the one from a recent build.

Current Souliss version I have is 1.7.1. I’ll try 1.8.0 and post back the results.

Thanks!

Looks like installing 1.8.0 for Souliss solved the issue. Now I just need to parse the JSON result.

Thanks!

1 Like

The HTTP binding enables you to process JSON responses, I have added a few items this morning doing exactly that :wink:

Yes, it is! Here is the JSON from my CouchDB IoT database I’m parsing:
{ "_id": "bab615607fe75c0e4c8e50d19e00533a", "_rev": "1-04e43e3e3132156859d6090f3098b3f2", "datetime": "2015-08-26T05:50:56.587Z", "iot_type": "Device", "category": "Sensor", "type": "TempHumid", "iot_id": "ESP0001", "temp": 75.5, "humid": 34.9, "path": [ "Home", "Upstairs", "Office" ] }
Here is the js I used in my transform folder to parse it:
JSON.parse(input).rows[0].value.temp