1

I am having a hard time understanding where exactly do we bind the hardware for example a TMP35 temperature sensor with the software (i.e. in the Java API).

Is there any documented example for this or any custom sensor (where the driver isn't already available)?

Or can anyone outline the approach to accomplish the same? Do I need to extend the c8y.lx.driver.Driver class?

Any pointers appreciated.


I believe that TMP35 has no means of communication to the cumulocity server. So maybe anyone can please provide a way to make a custom sensor (which has a means for communication as well and is Java-enabled) link with Cumulocity? That is what I am interested in knowing?

I know that there are some certified devices which are being supported out of the box.

rents
  • 768
  • 1
  • 7
  • 22
  • Can you say a bit more on what your environment is? I assume that you want to connect the sensor to a box that has some GPIO inputs and that runs Java? Is it a Raspberry Pi? – André Jan 19 '16 at 07:54
  • An example of a trivial sensor with raspberry pi will also help – rents Jan 19 '16 at 09:49
  • I am going through the Agent.java and PiHardwareDriver.java and that has helped in understanding what is actually happening. – rents Jan 19 '16 at 11:52

1 Answers1

2

There are two steps:

  1. Get the data from your analogue sensor with Java.
  2. Send the data to Cumulocity.

Step 1 is unrelated to Cumulocity. You need an ADC, and Google provides a few examples on how to connect those (like http://www.lediouris.net/RaspberryPI/ADC/readme.html).

Step 2 is then quite simple. Create a subclass of "MeasurementPollingDriver" and implement run(). Inside run(), query the sensor using the method from Step 1 and convert that into a measurement. Send that measurement using super.sendMeasurement(measurement). Here is an example.

If you have a device library with callbacks, you could just copy the code from MeasurementPollingDriver

TemperatureMeasurement measurement = ...;
MeasurementRepresentation measurementRep = new MeasurementRepresentation();
measurementRep.setSource(mo);
measurementRep.set(measurement);
measurementRep.setTime(new Date());
measurements.create(measurementRep);
André
  • 668
  • 6
  • 11
  • Thanks, that helped a lot. Can you also point to an example where we will need to register a callback. For example, in case of a Firealarm, there is no need to poll, what we actually need is an ISR – rents Jan 20 '16 at 07:19
  • Edited the answer to cover your comment. – André Jan 20 '16 at 16:55
  • found MotionDetectorBricklet.java, which is what I was looking for. thanks – rents Jan 21 '16 at 06:38