6

Does anyone know of a "standardized" Java API for working with sensors, and which is closely tied to Java ME as is the case with JSR 256?

I'm writing a Java library for interfacing with a sensor network consisting of several different types of sensors (mostly simple stuff such as temperature, humidity, GPS, etc.).

So far I've rolled my own interface, and users have to write apps against this. I would like to change this approach and implement a "standard" API so that implementations aren't that closely tied to my library.

I've looked at JSR 256, but that really isn't a great solution as it's for Java ME, and my library is mostly used by Android devices or laptops running the full Java SE.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
  • JSR-256 is intended for J2ME, according to this: http://jcp.org/en/jsr/tech?listBy=1&listByType=platform – skaffman Feb 25 '10 at 23:11
  • Yes, unfortunately the JSR-256 doesn't allow you to extend with your own sensors. You're limited to your device' sensors. In my case, I need to interface a sensor network that isn't part of a mobile device, so that isn't an option (apart from JSR-256 being meant for J2ME which rules it out to begin with). – Martin Strandbygaard Mar 05 '10 at 07:06
  • Examples of sensors for temperature, humidity, and location (GPS) are given on pages 68-69 of version 1.2 of the JSR-256 spec. – shadit Mar 11 '10 at 21:26

4 Answers4

1

In android there is the android.hardware package that contains a class Sensor, all in all quite similar to tje JSR 256 sensor api. Please see what you can do using that. Maybe it's even a reasonable approach to implement that in Java SE, for as far as I know, there is no Java SE sensor api.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Bex
  • 2,905
  • 2
  • 33
  • 36
  • 1
    I've looked at android.hardware, but it's even less extensible than JSR-256, it's limited to Android, and it doesn't allow me to extend with my own sensors (aka being limited to the handset's sensors). – Martin Strandbygaard Mar 05 '10 at 07:07
1

JSR-256 does not seem to be limited or restricted in the types of sensors it supports. Appendix E contains sensor definitions, but those are just the recommended data a certain type of sensor should handle. There does not seem to be anything stopping somebody from defining additional sensor types.

I would suggest you implement to JSR-256 and then just include its packages:

  • javax.microedition.sensor
  • javax.microedition.sensor.control

...in your distribution. Since they're targeting limited devices, the library is bound to be very compact. As long as you would not be prohibited from re-distributing the reference implementation of JSR-256 it would make sense to plan to do so.

shadit
  • 2,536
  • 1
  • 16
  • 21
1

Not quite. JSR-275 was intended to have part of its functionality (Quantities and a Unit type very similar to that in 256) but the SE/EE EC turned it down.

Consolidation between SE and ME as mentioned by Oracle may lead to a more common Sensor API and Unit framework some time, but it's unlikely before Java 8.

Werner

1

Indeed, Oracle now spread the news, some form of SE Sensor API was desired for Java 8.

It was added to OpenJDK after Java 8: http://openjdk.java.net/projects/dio/ Works both with Java ME and SE (Embedded).

Werner Keil
  • 592
  • 5
  • 12
  • Where was that announced? – Werner Keil Mar 02 '17 at 19:25
  • That is a good question. I guess I assumed it, because it was accepted as OpenJDK project. Anyway, I was wrong. Comment deleted. – Tuupertunut Mar 02 '17 at 20:51
  • No, that alone means nothing;-) There is also an OpenJDK project Kona: http://openjdk.java.net/projects/kona/ but it has not seen much activity after July 2015, neither on the mailing lists: http://mail.openjdk.java.net/pipermail/kona-dev/ nor elsewhere. – Werner Keil Mar 03 '17 at 16:35
  • Device I/O has some recent threads on its mailing list: http://mail.openjdk.java.net/pipermail/dio-dev/ However we have to see, how Java 9 Embedded looks like to tell, if DIO is offered as optional module then. – Werner Keil Mar 03 '17 at 16:40
  • BTW if you know DIO, you might take a look at my question about it: http://stackoverflow.com/questions/42539556/reading-motherboard-sensors-with-java-device-i-o – Tuupertunut Mar 03 '17 at 19:54