Space Bunny is the IoT platform that makes it easy for you and your devices to send and exchange messages with a server or even with each other. You can store the data, receive timely event notifications, monitor live streams and remotely control your devices. Easy to use, and ready to scale at any time.
This is the source code repository for Java SDK. Please feel free to contribute!
Gradle:
compile 'io.spacebunny:device-sdk:0.1.0'
Maven:
<dependency>
<groupId>io.spacebunny</groupId>
<artifactId>device-sdk</artifactId>
<version>0.1.0</version>
</dependency>
Download library: Jar file
Devices can publish messages on configured channels and receive messages on their inbox channel
Configure the instance of the SpaceBunny's Client with a valid Device Key, or with a custom device:
try {
finalSpaceBunny.ClientspaceBunny = newSpaceBunny.Client("your_device_key");
} catch (SpaceBunny.ConfigurationExceptionex) {
ex.printStackTrace();
}Build an instance of a device, configure and use it:
try {
Stringhost = "host_to_connect";
Stringdevice_name = "name_of_the_device";
Stringdevice_id = "device_identifer";
Stringsecret = "password_for_connection";
Stringvhost = "virtual_host_to_connect";
ArrayList<SBChannel> channels = newArrayList<>();
SBDevicedevice = newSBDevice.Builder()
.setDeviceId(device_id)
.setDeviceName(device_name)
.setHost(host)
.setSecret(secret)
.setVHost(vhost)
.setChannels(channels)
.getDevice();
SBDevicecustom_device = newSBDevice(<device_custom_configuration>);
finalSpaceBunny.ClientspaceBunny = newSpaceBunny.Client(device);
} catch (SpaceBunny.ConfigurationExceptionex) {
ex.printStackTrace();
}Add a FinishConfigiurationListener to reach all device information:
[...]
finalSpaceBunny.ClientspaceBunny = newSpaceBunny.Client(device_key);
spaceBunny.setOnFinishConfigiurationListener(newSpaceBunny.OnFinishConfigiurationListener() {
@OverridepublicvoidonConfigured(SBDevicedevice) throwsSpaceBunny.ConnectionException {
System.out.println(device.toString());
}
});
[...]After configuration, set up the client if needed:
[...]
// Turn off secure connection or certificate verificationspaceBunny.setTls(false);
spaceBunny.setVerifyCA(false);
// Set a custom certificatespaceBunny.setPathCustomCA("<absolute_path>\\cert.pem");
[...]After you have configurated your Space Bunny client connect with simple methods. Connection use default protocol AMQP, to use a different one please contact us.
release/Release_0.1.0
[...]
spaceBunny.connect();
// Connection with custom callbackspaceBunny.connect(newSpaceBunny.OnConnectedListener() {
@OverridepublicvoidonConnected() throwsSpaceBunny.ConnectionException {
}
});
[...]Close connection when you have done:
[...]
try {
spaceBunny.close();
} catch (SpaceBunnyConfigurationExceptionex) {
ex.printStackTrace();
}In this example a device publishes a single message on one channel:
[...]
spaceBunny.publish(channel_name, msg, headers, callBack);
[...]channel_name [String] is the name of the selected channel (It would be send a warning if channel does not exist.); msg [String] is the message to send to channel headers [@Nullable HashMap<String, Object>] are the headers to send to the channel callBack [@Nullable com.rabbitmq.client.ConfirmListener] callBack to publish Ack and Nack
It can be useful to get all avaiable channel of the device with:
[...]
ArrayList<SBChannel> channels = spaceBunny.getChannels();
[...]In this example a device waits for incoming messages on its inbox channel.
You have to configure and connect your client, then you can add a callBack function on subscribe to inbox channel.
[...]
spaceBunny.subscribe(newRabbitConnection.OnSubscriptionMessageReceivedListener() {
@OverridepublicvoidonReceived(Stringmessage, Envelopeenvelope) {
System.out.println(message);
}
});
[...]The library is available as open source under the terms of the MIT License.
