fbpx
How to set up ObjectBox Go on Raspberry Pi

How to set up ObjectBox Go on Raspberry Pi

ObjectBox is a fast object-oriented database for IoT and Mobile edge computing. With its Go support, ObjectBox is a perfect match for Raspberry Pi and will add instant speed to your next Raspberry project.

To get started right away, jump straight to the Installation section.

Local data persistence

In general, databases are great to add data persistence to your project. If you need to turn off the device or if there is a power outage, your sensor statistics or other interesting information are safe. The next time you boot up the application it’s there again as if nothing happened. Another rather obvious advantage is speed and independence from an Internet connection. Storing data on a local drive is just faster than sending it to the cloud and back. And when you store your data locally, your application works with or without an Internet connection. This also means, you have full control over all your data, especially regarding who shall be able to access it… Finally, this reduces cloud costs.

For many databases (e.g. SQLite, PostgreSQL or MySQL), you need to know SQL. And for managing complex datasets, you need to be really good at it. Some like it, but for many developers this is annoying. Also, you might worry about SQL injection attacks.

Advantages of ObjectBox

ObjectBox is a database uniquely designed to sit on IoT and Mobile devices and fix these issues.

Firstly, you do not formulate your queries in SQL. ObjectBox comes with easy APIs allowing you to use the constructs and syntax native to the language you are using anyway. In this way ObjectBox is a NoSQL database. Secondly, benchmarks show that ObjectBox is faster than alternatives. So, even if you’d like to insert the data of a lot of sensors simultaneously, you don’t need to worry about speed anymore. This has the nice side effect that more speed means less CPU and thus is resourceful in every respect. Last not least, because ObjectBox is designed for small devices, it just needs about 1 MB of disk space. If you need something smaller, you can check out the ObjectBox client for Azure Sphere.

If you want to use ObjectBox in your next Raspberry Pi project, here is how you get started:

Installation

We’ll talk about the Go version of ObjectBox here. There are bindings for C, Java and Swift as well – and we will publish articles in the future about them too.

First, you need to have access to the shell (i.e. command line) of your Raspberry Pi. It does not matter if you’re connected via SSH or directly, just make sure that your Raspberry Pi has a working internet connection. Then, just execute the following command to get started right away:

This creates a folder named go in your home directory with the following subdirectories:

  • go with the binaries of Go 1.12.5 for ARMv6l
  • objectbox with the shell script update-objectbox.sh you can execute to easily update ObjectBox upon a new release
  • projects/objectbox-go-test mainly with the file main.go which contains a tiny demo application

Note: The script will install libobjectbox.so globally (confirm by typing “y”), so it might prompt you to enter your root password.

Working with ObjectBox Go

The first tool you will come across is objectbox-gogen. It generates the correct Go files out of a Go structure to make it usable with ObjectBox. Assuming your main.go looks something like this:

As long as you only change the program’s logic, you don’t need to do anything. If you change the model, simply execute objectbox-gogen -source main.go to update the auto-generated files for the ObjectBox model interface.

After that, you can execute the commands specified above to run and execute this source. The setup script does this automatically for you. As a result, you’ll get a directory called objectbox with the files data.mdb and lock.mdb; these are the underlying database files and they will be reused when you execute the program again.

Summary

So, that’s basically it! Setting up ObjectBox and using ObjectBox is easy. Check it out yourself and please share your thoughts with us; we appreciate any feedback. 🙂

Until we release the next part of this tutorial discussing the features of ObjectBox in Go more thoroughly, feel free to check out the fully-fledged demo application in its official repository. Also, if you’d like to learn more about all other features of ObjectBox Go, have a look at the official documentation!

If you encounter any problems during this process, please reach out to us. The best way is to ask a question and tag it “ObjectBox” on Stack Overflow. Finally, we would love hearing your thoughts on ObjectBox via TwitterFacebook, or Mail (contact [at] objectbox . io).

Azure Sphere & ObjectBox: IoT Sensor Demo

Azure Sphere & ObjectBox: IoT Sensor Demo

A few weeks ago, we published ObjectBox for Azure Sphere. Today, we are adding IoT sensor data collection to this. It’s a working demonstration that you can run on your machine along with an Azure Sphere board. To jump straight to it, here is the repository.

Forwarding Sensor Data to ObjectBox Database

We added an example to the Azure Sphere ObjectBox repository illustrating how to read IoT sensor data and forward them to an ObjectBox database. For integrating the sensors, the example relies on the Grove Shield library from the manufacturers of Azure Sphere, Seeed Studio. This library makes reading sensor information super simple. Next, the collected sensor data is sent via an ObjectBox REST Client to a device running a ObjectBox database. Here, sensor data can be processed further.

The demo setup comes with a ready-made ObjectBox HTTP server for download. The Azure Sphere client application has to be built from sources as the IP of the server needs to be white-listed here. Please find a step-by-step guide in the repository.

Setup Overview

Have a look at the general application architecture to get the gist of the demo:

Browsing collected Sensor Data

Once you collected sensor information like light intensity, temperature, and humidity, you may want to view it. The most simple option is the “ObjectBox Browser” that comes embedded with the ObjectBox HTTP server.

Let us know what you think

So, of course we are looking forward to your feedback again! Do you have a use case in mind that you want to discuss with us? Also, please feel free to open a new GitHub issue if you run into a problem or ask a question tagged ObjectBox on Stack Overflow. And finally, don’t hesitate to share your thoughts on ObjectBox / Azure Sphere with us via Twitter, Facebook, or Mail (contact [at] objectbox . io).