Rocking the IoT world with Bulldog Library
An introduction to Bulldog: a Java library for single board computer platforms like Raspberry Pi.
Join the DZone community and get the full member experience.
Join For FreeBulldog Library
It is a Java library providing developers with GPIO and other low-level IO interfaces like I2C, SPI, or PWM. Currently supports various Single Board Computer (SBC) platforms, including Raspberry Pi, BeagleBoneBlack, and CubieBoard.
Bulldog aims to be platform agnostic - to write a single piece of code that can be run on multiple platforms. The only thing that needs to be changed in the following snippet is the string identifier of GPIO pin to work on different SBCs.
public class BulldogLED {
public static void main(String[] args) {
//Detect the board we are running on
Board board = Platform.createBoard();
//Set up a digital output
DigitalOutput output = board.getPin("P1_11").as(DigitalOutput.class);
// Blink the LED
output.high();
BulldogUtil.sleepMs(1000);
output.low();
}
}
The latest 0.2.0 release was mainly about stabilizing and finishing platform detection capabilities, however we are already looking into our ultimate goal, that is to get rid of all filesystem interaction and omiting all the kernel modules, and interact directly with memory of the controlled SBC. This will boost the performance to the sky, so stay tuned!
Integration
There is also a component for Apache Camel that wraps Bulldog Library features. At the moment it supports only GPIO, however support for the rest of Bulldog features is already knocking on the door.
An example is worth a thousand words. The following snippet is all you need to build a REST endpoint which controls a GPIO pin on your SBC. It will work on all platforms supported by Bulldog Library.
<camelContext trace="false" xmlns="http://camel.apache.org/schema/spring">
<restConfiguration bindingMode="auto" component="jetty" port="8080" />
<rest path="/rest">
<post uri="/led">
<to uri="bulldog://gpio?pin=P1_11" />
</post>
</rest>
</camelContext>
So don't hesitate, grab the library and rock the IoT world!
References
Opinions expressed by DZone contributors are their own.
Comments