tags:

views:

198

answers:

3

Does anyone know of a "standardized" Java API for working with sensors, and which is closely tied to J2ME 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 J2ME, and my library is mostly used by Android devices or laptops running the full J2SE.

+1  A: 

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 J2SE, for as far as I know, there is no J2SE sensor api.

Bex
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
+1  A: 

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
A: 

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

Werner Keil