Skip to Content

Sensor Data: Custom Java Adapter for Streaming Lite

I now have a Streaming Lite project on my Raspberry Pi device. I have followed the blog and now have a similar Java adapter setup on my the device which writes events to the Streaming Lite program.

Q. 1. However, if I have to connect it to read the values from the sensors. Would it be ok if the sensors talk to a python script on the pi, and then when the python script is capable of displaying temperature sensor readings on its console, would I just have to change the command value to say "sudo python" for my Java program to capture the output of the Python script?

As shown in the blog post below:

For example, if cmd = “echo 90” is passed in, the function will return “90”. Additionally, if we had a python script called, we can pass in cmd = “sudo python”. This will return the output of the sensor being polled.

private static String exec(String cmd) throws IOException{ 

Process p = Runtime.getRuntime().exec(cmd); 

BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); 

String s = stdInput.readLine(); return s; 


Q.2. And, the line sudo is mentioned here (below). Am I getting this right?

String val_sensorId ="RaspberryPi";
String val_Temperature_Command = "echo 90";

Q. 3. Does the(current) java program expect only the "Temperature" value from the python console? If I have a python program which just prints numbers like:




Will the (current) Java code be happy with this Python output and would it be capable of incorporating these temperature values as input to the Streaming Lite program?

Link to the tutorial:

Kindly let me know your views.

Thanks you.

Add comment
10|10000 characters needed characters exceeded

1 Answer

  • Best Answer
    Posted on Nov 21, 2016 at 04:34 PM

    1) Yes the sample code is set up to make an external call to "read" the sensor. In the sample code we simply execute an "echo 90" which will feed the value "90" into the adapter. You can replace the "echo" statement with the command line of a Python script or other executable that will return a single numeric value.

    2) Yes, if you wanted to call "sudo python" then you would update the line "String val_Temperature_Command ="echo 90";" to replace the "echo 90" with the "sudo python"

    3) Yes the expected output of the external call for this particular example is a single numeric value.

    Keep in mind that this tutorial example has been kept simple on purpose, for example by only retrieving a single input value from the sensor. If your sensor generates multiple values as a single event or record, then you would build your custom adapter to retrieve the full event record. Similarly this example was built to make it easy to read input from a python script as many sensors available for the Pi are readily accessible from Python scripts, but if you prefer to read the sensor directly from your Java code then you can do that.

    Add comment
    10|10000 characters needed characters exceeded