This document will walk you through installing and running the essential EdgeX Foundry microservices on a Raspberry Pi for testing and evaluation. This is not an officially supported way of running EdgeX Foundry, and should not be used in a production environment. This guide is for developers who want to learn EdgeX by running it as a mock gateway device.
Know your device:
This guide has been tested to work on a Raspberry Pi 3B+, it may work on other models of the Raspberry Pi 3, but it will not work on any older or lighter variations of the Raspberry Pi as it requires a 64-bit capable CPU.Step-by-Step GuideInstall the OS
For this setup we will be running a 64-bit OS on our Raspberry Pi 3. While there is no supported 64-bit OS for this device, a number of people have been building their own to meet their needs. We will be using one of these:
Download the OS disk image file from the link above, then insert your microSD card into your computer so that you can flash the disk image onto it. If you are running Ubuntu or any other Linux distro, you can flash the image using this command:
unzip -p Bamarni-desktop-full64bit-pi3bplus-V2.zip |sudo dd bs=4M of=/dev/mmcblk0 iflag=fullblock oflag=direct status=progress; sync
Note that you will need to replace the part in bold with the path to your own microSD card, and that it should point to the device and not a partition on the device.
After this is done, insert the microSD card into your Raspberry Pi 3 and power it on. You should see a screen with the Raspberry Pi logos at the top. On the first boot it will expand the filesystem on your microSD card and setup the system, this can take quite a while (10-30 minutes) so be patient and don't shutdown or reboot your device. It will reboot itself when it is done, and take you to the login screen. The default username is 'pi' and default password is 'raspberry'.
Install System DependenciesOnce you have logged in, it's time to install the system dependencies needed to run EdgeX Foundry. Connect your device to your network using an ethernet cable (wifi isn't currently supported) and run the following commands:
sudo apt update
sudo apt install build-essential git pkg-config curl wget libzmq3-dev
You may also want to be able to connect and manage your device remotely, in which case you should also install:
sudo apt install openssh-server vim-tiny
Create Swap FileThe Raspberry Pi 3B+ has a full gig of ram, but between building the EdgeX Foundry source code and running MongoDB this may not be enough. So before going any further you will first want to create some additional memory capacity by adding a swap file to your filesystem. Run the following command to create a new 2GB swap file:
sudo touch /tmp/theswap
sudo chmod 600 /tmp/theswap
sudo dd if=/dev/zero of=/tmp/theswap bs=1M count=2048
sudo mkswap /tmp/theswap
sudo swapon /tmp/theswap
Install Go & GlideTo get the exact same version of GoLang as used by the EdgeX Foundry, install it from the upstream source rather than through the apt repositories:
wget https://dl.google.com/go/go1.10.1.linux-arm64.tar.gz
sudo tar -C /usr/local -xvf go1.10.1.linux-arm64.tar.gz
cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF
source ~/.bashrc
Glide is used to manage go dependencies for EdgeX Foundry. Install it with:
curl https://glide.sh/get | sudo PATH=$PATH GOPATH=/usr/local/go sh
Get the EdgeX Foundry Source CodeNow that you have Go and Glide installed, you can tell them to fetch the EdgeX services and their dependencies:
go get github.com/edgexfoundry/edgex-go
Then cd into the directory with the EdgeX source code:
cd ~/go/src/github.com/edgexfoundry/edgex-go
Building EdgeX Go MicroservicesThere are two steps for building the EdgeX Go microservices, the first to prepare the build, and the second to compile it:
make prepare
make build
Install and Set Up MongoDBEdgeX used MongoDB for local data storage. You can install it with:
sudo apt install mongodb-server
and verify that it's running with:
systemctl status mongodb
Once it's up and running, it needs to be initialized with data for the EdgeX services, you can do that with the init_mongo.js file:
wget https://github.com/edgexfoundry/docker-edgex-mongo/raw/master/init_mongo.js
sudo -u mongodb mongo < init_mongo.js
Test Run EdgeX ServicesNow that you have the EdgeX go services built and all the dependencies installed and running, you can run the EdgeX services themselves. The sourcecode contains a convenient script for doing this, in the same directory as your can make build above, run:
make run
This will start all of the EdgeX go services and leave them running until you terminate the process (with Ctrl-C). While it's running you can make EdgeX API calls to it using the IP address of your Raspberry Pi.
Make EdgeX a System ServiceIn order to keep the EdgeX services running when you're not logged in or connected to the Raspberry Pi, and to have it start automatically when it boots, you can create a SystemD service to manage it. Create a new file at /etc/systemd/system/edgex.service with the the following content:
[Unit]
Description=EdgeX Foundry Microservices
After=network.target auditd.service
ConditionPathExists=/home/pi/go/src/github.com/edgexfoundry/edgex-go/bin
[Service]
WorkingDirectory=/home/pi/go/src/github.com/edgexfoundry/edgex-go/bin
ExecStart=/home/pi/go/src/github.com/edgexfoundry/edgex-go/bin/edgex-launch.sh
Restart=on-failure
RestartPreventExitStatus=255
Type=simple
[Install]
WantedBy=multi-user.target
Alias=edgex.service
Update the systemd configuration with:
sudo systemctl daemon-reload
and then you can start the EdgeX service with:
sudo systemctl start edgex
This will now be run every time you boot your Raspberry Pi. You can verify that it's running with:
sudo systemctl status edgex
Comments