Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Rocking the IoT world with Bulldog Library

DZone's Guide to

Rocking the IoT world with Bulldog Library

An introduction to Bulldog: a Java library for single board computer platforms like Raspberry Pi.

· IoT Zone
Free Resource

Discover why Bluetooth mesh is the next evolution of IoT solutions. Download the mesh overview.

Bulldog 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 PiBeagleBoneBlack, 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

Take a deep dive into Bluetooth mesh. Read the tech overview and discover new IoT innovations.

Topics:
java ,raspberry pi ,beaglebone black ,iot development

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}