Since its arrival in 2012, the Raspberry Pi board series has taken the embedded industry by storm and introduced a new generation to embedded computing. With its ready availability, it is also the perfect board to show how to implement DevOps and continuous integration (CI) for embedded systems.
In this tutorial, you will be learning about a basic setup that will allow you to connect a Raspberry Pi 4 device to a CI server and then run commands directly on that Pi. We will be using our own CI platform, BeetleboxCI. If you would like access to a free trial, our team would be happy to chat.
BeetleboxCI is a continuous integration (CI) and continuous delivery (CD) platform for IoT, embedded, and hardware projects. It helps teams to automate the building, testing, and deployment of their code, saving time and reducing errors.
The key features are:
BeetleboxCI has the capability to communicate with external devices and run commands on them. It can also transfer files to and from devices as well as program microcontrollers. It communicates with external devices based on the protocol and settings defined by the user.
This tutorial demonstrates the use of the devices feature of BeetleboxCI to run commands on an external device, namely a Raspberry Pi. We will use BeetleboxCI to access the Raspberry Pi through SSH and print Hello World to the terminal.
For this exercise, the Raspberry Pi device needs to be wired to the same network as the server running BeetleboxCI, such that the server will have SSH access to the device. If the Raspberry Pi is connected to the same router or switch as the BeetleboxCI server, then its IP address would have been automatically assigned.
Make sure you know the IP address and login details of the Raspberry Pi before you proceed.
You can check the IP addresses of the devices on your network by running the ‘arp –a’ command from the BeetleboxCI server or any other Linux device on the network. If you have the right permissions, you can check the DHCP table on the router or DHCP server on your network to see the IP address of the device.
If you do not have the permissions to access network details, you can alternatively wire up the Raspberry Pi directly to an ethernet port on the BeetleboxCI server. This requires the IP addresses of the ethernet connection on the server side and the device side to be manually assigned through ifconfig, but the details of this are beyond the scope of this tutorial.
For this exercise, we assume the following details to log in to the Raspberry Pi:
IP: 192.168.1.92
Username: pi
Password: raspberry
BeetleboxCI maintains a registry of devices that are available. To communicate with the device through the built-in features of BeetleboxCI, the device needs to be registered on the application.
In this example, we set up the Raspberry PI such that the webapp can form an SSH connection with the device through password authentication, where sshpass will input the password automatically.
devices:
raspberry-pi:
connection: sshpass -p raspberry ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" pi@192.168.1.92
prompt: "$"
The definition of the device consists of a connection field, which tells BeetleboxCI how to communicate with the device, and the prompt specifies the character or string present in the terminal of the device (e.g. $ for a linux terminal).
BeetleboxCI requires every pipeline to be linked to a code repository which forms the code base of that pipeline. For this tutorial, we will use Github, but BeetleboxCI also supports Bitbucket and Gitlab and those will work too for this tutorial.
runners:
local-runner:
image: public.ecr.aws/y2s4f3y9/ubuntu-generic:latest
jobs:
pi-hello-world:
resource_spec: small
runner: local-runner
current_working_directory: ~/
device: raspberry-pi
steps:
- run:
name: Setup
command: apt-get install sshpass
- run:
name: Run device
on-device: True
command: |
echo Hello World
workflows:
pi-hello-world-workflow:
jobs:
- pi-hello-world
This code defines a runner to use to execute the commands, and it has one workflow which contains one job. The job runs on the runner, and uses the raspberry-pi device. There are two steps in the job: The first step installs sshpass on the runner, and the second step runs a command on the device, which was defined earlier on.
Now that the device has been registered, we can create a pipeline which uses both the code repository and the device you created above.
Pipeline Name: pi-hello-world
Repository URL: https://github.com/<username>/<repo_name>
Authentication Settings — Username: <The name of your git account>
Authentication Settings — Password: <Github personal access token>
If you created your repository with public access, then the authentication information will not be necessary. Note that Github no longer supports password authentication for cloning repositories, so a personal access token is required. If you do not already have a personal access token for Github, you can follow this link from Github which shows how to create one.
As an alternative to your username and a personal access token, you can generate an SSH key to authenticate access to private git repositories (given that the public key is added either to your Github account or just as a deploy key to the repository). More information on this can be found in the VCS Integration section of the BeetleboxCI documentation.
You can check the logs to check if the output looks correct. In the page you are currently on, you will be able to view the workflows of the pi-hello-world project. There will be a single workflow named pi-hello-world-workflow, which will take us to the jobs that make up that workflow.
Raspberry Pis are a brilliant first step on your way to learning embedded DevOps. You are now able with BeetleboxCI to: