My current job involves me mostly working in the upper layers of the desktop software stack however I started out working in what was then called embedded engineering but now would probably be know as the Internet of Things (IoT). I worked on a number of projects which normally involved taking some industrial equipment (radio infrastructure, camera control system) and adding a stripped down Linux kernel and an application.
While this was cutting edge at the time, there were a number of issues with this approach:
The above issues meant a large overhead building and maintaining the platform instead of spending that time and money on your application. If you wanted to make a hobby project it was going to be expensive.
But we live in exciting times! It’s now possible to use cheap hardware and easily accessible software to make a robust IoT device. For around $USD60 you can make a highly capable device using Ubuntu Core and Raspberry Pi. I decided to make a device that showed a scrolling LED display, but there are many other sensors and output devices you could attach.
The Raspberry Pi 3 A+ is a good choice to build with. It was just recently released and is the same as the B+ variant but on a smaller board. This means you save some money and space but only lose some connectors that you can probably live without in an IoT device.
I added an SD card and for protection put it in a case. I chose an nice Ubuntu orange colour.
Next step was to connect up a display (also in Ubuntu orange). Note this didn’t need the wires – it should fit flat onto the case but I spent too much time photographing the process that I accidentally soldered on the connector backwards. So don’t make that mistake… 😕
Final step was to connect a USB power supply (e.g. a phone charger). The hardware is complete, now for the software…
Using Ubuntu Core 18 is as simple as downloading a file and copying it onto the SD card. Then I put the SD card into the Raspberry Pi, powered it on and all I had to do was:
The last step is magically easy. If you connect a screen to the Pi it shows you the exact ssh command to type to log into it (i.e. you don’t have to work out the IP address) and it uses the SSH key you have attached to your Ubuntu SSO account – no password necessary!
$ ssh firstname.lastname@example.org
Now to write my application. I decided to write it in C so it would be fast and have very few dependencies. The easiest way to quickly develop was to cross-compile it on my Ubuntu laptop, then ssh the binary over the the Pi. This just required installing the appropriate compiler:
$ sudo apt install gcc-arm-linux-gnueabihf $ arm-linux-gnueabihf-gcc test.c -o test $ scp test email@example.com: $ ssh firstname.lastname@example.org ./test
Once I was happy my application worked the next step was to package it to run on Ubuntu Core. Core doesn’t use .deb packages, instead the whole system is built using Snaps.
All that is required to generate a snap is to fill out the following metadata (running snapcraft init creates the template for you):
name: little-orange-display base: core18 version: git summary: Demonstration app using Ubuntu Core and a Raspberry Pi description: | This is a small app used to demonstrate using Ubuntu Core with a Raspberry Pi. It uses a Scroll pHAT HD display to show a message. architectures: - build-on: all run-on: armhf grade: stable confinement: strict apps: little-orange-display: daemon: simple command: display-daemon plugs: - i2c parts: little-orange-display: plugin: make source: .
This describes the following:
To test the package I built it on my laptop and installed the .snap file on the Raspberry Pi:
$ snapcraft $ scp little-orange-display_0+git.aaa6688_armhf.snap email@example.com: $ ssh firstname.lastname@example.org $ snap install little-orange-display_0+git.aaa6688_armhf.snap $ snap connect little-orange-display:i2c pi:i2c-1 $ snap start little-orange-display
And it ran!
The last stage was to upload it to the Snap store. This required me to register the name (little-orange-display) and upload it:
$ snapcraft register little-orange-display $ snapcraft push little-orange-display_0+git.aaa6688_armhf.snap
And with that little-orange-display is in the store. If I wanted to make more devices I can by installing Ubuntu Core and enter the following on each device:
$ snap install little-orange-display $ snap connect little-orange-display:i2c pi:i2c-1 $ snap start little-orange-display
And that’s the end of my little project. I spent very little time installing Ubuntu Core and doing the packaging and the majority of the time writing the app, so it solved the issues I would have traditionally encountered building a project like this.
Using Ubuntu Core and Snaps this project now has following functionality available:
This post originally appeared here.
From home control to drones, robots and industrial systems, Ubuntu Core and Snaps provide robust security, app stores and reliable updates for all your IoT devices.
It was another busy iteration for the web and design team, trying to get a lot of work wrapped up before we head off to Lyon, France for our 19.10 Roadmap cycle kick-off.
First steps are always hard, especially in technology. Most of the time, you need a primer, just the right dose of knowledge, to get started with a platform. This tutorial and upcoming sequels are designed to provide developers with…
We often feature and promote applications and games in the Snap Store and via our social media channels. Perhaps unsurprisingly, games are popular among our followers, and our users. There are a few great games already in the Snap Store,…