JSON API for external charting libraries (e.g. ios-charts)

Hi,

disclaimer: I am new and using OH2. Maybe this is not the right section…

I would like to have an API to retrieve historical data in JSON format for charting to display e.g. temperature graphs, etc. My idea would be to have a rest service to retrieve this data from OH2 in JSON format (querying the rrd4j persistence service). Similar to the chart servlet but the output should be JSON. I would access it via ios-charts framework on iOS.

My question would be on the implementation side:

  • easy/hard/impossible?
  • where should I look and add stuff for implementation? (packages, ESH?, )
  • if someone has a quick summary on how he would do it…(add a servlet, access X by Y etc. pp)

I have OH2 in Eclipse and have some Java know how.

Christian

You could do this using InfluxDB persistence, since InfluxDB already provides a JSON REST API which OH uses to store data.

This solution wouldn’t use OpenHAB directly for the data retrieval, but is available today without having to write any code. I’m sure there is an InfluxDB library available for iOS which would make developing the client easier.

As far as I know, there are many users waiting for something like this.

In my opinion, the chart servlet is one of the more unattractive features of OH.

But a new JSON API should support all available persistance addons.
Only supporting one addon (or the above mentioned workaround with InfluxDB) only serves a small user base.

Hi Christian,

There is already an issue for this since 2 years, but it hasn’t yet been implemented: https://bugs.eclipse.org/bugs/show_bug.cgi?id=423547

So to answer the right “place”: This is clearly something to go into ESH.
@chris already has such an REST API within HABmin since a long time. The idea was to port this over to ESH (and maybe enhance it if necessary).

So if you want to go for it, this is great! I’d suggest to first discuss the detailed requirements on the bugzilla entry before starting with the implementation.

Cheers,
Kai

Thanks, I contacted @chris and I’ll review and will write up a suggestion for implementation on the bug ticket.

Christian

Currently I have an API for retrieving item data in HABmin - I can easily move this into another bundle either the rest.core or somewhere else (rest.chart?). It currently provides simply a GET method (GET {service}/{item}?start/finish times etc). I’ve had this running for about 2 years - I tried a few different ways of returning the data and what I have here works well, and is quick and simple.

I’m happy to discuss this further, or I’m also happy to move over my current implementation so people can play with it - or of course you can use the existing HABmin JAR to also see what it’s doing.

Chris

I’d suggest to put it into the existing org.eclipse.smarthome.core.persistence bundle, e.g. in a new package org.eclipse.smarthome.core.persistence.rest.

Would be great if you could create a PR based on your code - we can than also directly discuss on this PR, if this is all we need or if anybody has any suggestions to change or enhance it.

That would be great (to put it into ESH). If you have a branch I’d really like to try it out.

Btw, noob question: how do I set up my Eclipse IDE to include the OH2 source AND the eclipse smart home sources? I currently have the OH2 sources and the ESH are retrieved through maven I think. Or is it just a Eclipse Installer target?

Christian

Sounds good - I’ll do this in the next day or two and we can discuss from there…

The easiest way is to use the dedicated profile that I have created for OH2+ESH development. You can find it directly in the Eclipse Installer:

PR created. I’ve not really done any testing or anything - just moved it from HABmin to the persistence bundle… Any comments welcome and I’ll look to update and tidy if it’s what you’re after…

Chris

1 Like