Skip to content

Instantly share code, notes, and snippets.

@jadonk
Last active September 21, 2020 11:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jadonk/a031ab33f9846d7233bf99e3776056d9 to your computer and use it in GitHub Desktop.
Save jadonk/a031ab33f9846d7233bf99e3776056d9 to your computer and use it in GitHub Desktop.

What is AWS IoT Greengrass?

BeagleBone AI intial device setup

  • Quick Start Guide
  • System Reference Manual
  • Defaults
    • username: debian
    • password: temppwd
  • Where not specified below, commands are to be executed on BeagleBone AI's Linux command shell
  • If on the same local network as BeagleBone AI and using a typical Linux host development PC (recommended), you can login via:
ssh debian@beaglebone.local

Latest image (optional)

Using the latest image is likely to save time over updating the pre-installed image. Use the BalendaEtcher tool to write this image to a microSD card (at least 8GB). You can follow the getting started instructions on BeagleBoard.org, but note 2 things:

  1. The image linked below is a different one than on https://beagleboard.org/latest-images, possibly a bit newer and it is also a flasher image.
  2. Being a flasher image, this will therefore overwrite your eMMC. See the wiki page on the Debian images for more information about flasher images.

Update

  • Update instructions
  • Use instructions to get on a network
  • The kernel update is most important
  • You may want to point a fan towards the board during the initial update process

Commands to check the current system status

CPU temperature

/opt/scripts/device/x15/test_thermal.sh

CPU frequency

cpufreq-info

Network IP addresses

hostname -I

Security, system and dependencies setup

Change the default user password (recommended)

passwd

Disable password-based logins (recommended)

Host

ssh-keygen -t ed25519
ssh-copy-id -i ~/.ssh/id_ed25519.pub debian@beaglebone.local

Beagle

sudo perl -pe "s/\#?PermitRootLogin .*$/PermitRootLogin no/" -i /etc/ssh/sshd_config
sudo perl -pe "s/\#?PasswordAuthentication .*$/PasswordAuthentication no/" -i /etc/ssh/sshd_config
sudo perl -pe "s/\#?UsePAM .*$/UsePAM no/" -i /etc/ssh/sshd_config
sudo perl -pe "s/\#PermitRootLogin .*$/PermitRootLogin no/" -i /etc/ssh/sshd_config

Disable unused services (recommended)

sudo systemctl disable nodered.socket
sudo systemctl disable bonescript.socket
sudo systemctl disable bonescript-autorun

Disable Cloud9-IDE (recommended)

sudo systemctl disable cloud9.socket
sudo systemctl disable nginx

Disable GUI (optional)

sudo systemctl set-default multi-user.target

Disable access point (optional)

sudo systemctl disable hostapd
sudo systemctl disable bb-bbai-tether

Disable USB gadgets (optional)

sudo perl -pe 's/^\# (USB_IMAGE_FILE_DISABLED=yes)$/$1/' -i /etc/default/bb-boot
sudo perl -pe 's/^\# (USB_NETWORK_DISABLED=yes)$/$1/' -i /etc/default/bb-boot

Add ggc user/group (requireed)

sudo adduser --system ggc_user
sudo addgroup --system ggc_group

Enable hardlink and softlink (symlink) protection (may be required)

cat <<EOF | sudo tee /etc/sysctl.d/98-beagle.conf
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
EOF

Enable cgroups (already in default, so not necessary)

echo "cmdline=coherent_pool=1M net.ifnames=0 rng_core.default_quality=100 quiet cgroup_enable=memory cgroup_memory=1" >> /boot/uEnv.txt

Install Java 8 (required)

sudo apt install openjdk-8-jdk
sudo ln -s /usr/lib/jvm/java-8-openjdk-armhf/jre/bin/java /usr/bin/java8

Install nodejs8 (optional)

sudo apt install snapd
sudo snap install core
sudo snap install node --channel=8/stable --classic
sudo ln -s /snap/bin/node /usr/bin/nodejs8.10

Build and install Python3.7 (optional)

sudo apt install -y libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev llvm
sudo apt install -y libncurses5-dev libncursesw5-dev tk-dev
cd
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar xzf Python-3.7.0.tgz
cd Python-3.7.0/
./configure --enable-optimizations --with-ensurepip=install
make -j2
sudo make altinstall

Add recent Docker (optional)

sudo apt install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg2 \
    software-properties-common
   
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo add-apt-repository \
   "deb [arch=armhf] https://download.docker.com/linux/debian \
   $(lsb_release -cs) \
   stable"
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
sudo pip3 install docker-compose

Reboot

sudo shutdown -r now

Verify settings after reboot

Verify hardlink and softlink protection

sudo sysctl -a 2> /dev/null | grep fs.protected

Verify Greengrass dependencies

wget https://github.com/aws-samples/aws-greengrass-samples/raw/master/greengrass-dependency-checker-GGCv1.10.x.zip
unzip greengrass-dependency-checker-GGCv1.10.x.zip
cd greengrass-dependency-checker-GGCv1.10.x
sudo ./check_ggc_dependencies 

Verify no ssh access via a password

Host

ssh debian@beaglebone.local -o PubkeyAuthentication=no

Install and run Greengrass

Configure IoT Greengrass on AWS

Install the assets onto the core device

Host

wget https://d1onfpft10uf5o.cloudfront.net/greengrass-core/downloads/1.10.0/greengrass-linux-armv7l-1.10.0.tar.gz
scp greengrass-linux-armv7l-1.10.0.tar.gz debian@beaglebone.local:
scp d956f9e660-setup.tar.gz debian@beaglebone.local:

Beagle

cd
sudo tar xzf greengrass-linux-armv7l-1.10.0.tar.gz -C /
sudo tar xzf d956f9e660-setup.tar.gz -C /greengrass
sudo wget https://www.amazontrust.com/repository/AmazonRootCA1.pem -O /greengrass/certs/root.ca.pem

Start up Greengrass

cd /greengrass/ggc/core/
sudo ./greengrassd start

Configure intialization for Greengrass at startup

cat <<EOF | sudo tee /etc/systemd/system/greengrass.service
[Unit]
Description=Greengrass Daemon

[Service]
Type=forking
PIDFile=/var/run/greengrassd.pid
Restart=on-failure
ExecStart=/greengrass/ggc/core/greengrassd start
ExecReload=/greengrass/ggc/core/greengrassd restart
ExecStop=/greengrass/ggc/core/greengrassd stop

[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable greengrass

Deploy a Lambda function on AWS IoT Greengrass

AWS IoT Device Tester for AWS IoT Greengrass (reference only)

Add sudo without a password

sudo usermod -aG sudo debian
cat <<EOF | sudo tee -a /etc/sudoers
debian ALL=(ALL) NOPASSWD: ALL
EOF

Install Greengrass device tester, configure and execute

  • Instructions
  • Download devicetester_greengrass_linux_2.2.0.zip from instructions linked above
  • You can use aws-cli from snapcraft.io as documented below
  • The IP address and keypath below are specific to my setup and you'll need to update

Host (Ubuntu 18.04)

sudo snap install aws-cli --classic
aws configure
unzip devicetester_greengrass_linux_2.2.0.zip
cd devicetester_greengrass_linux
cat <<EOF >configs/device.json
[
  {
    "id": "bbai1",
    "sku": "bbone-ai.a1",
    "features": [
      {
        "name": "os",
        "value": "linux"
      },
      {
        "name": "arch",
        "value": "armv7l"
      }
    ],
    "greengrassLocation": "/greengrass",
    "devices": [
      {
        "id": "bbai1.1",
        "connectivity": {
          "protocol": "ssh",
          "ip": "192.168.0.115",
          "auth": {
            "method": "pki",
            "credentials": {
              "user": "debian",
              "privKeyPath": "/home/jkridner/.ssh/id_rsa"
            }
          }
        }
      }
    ]
  }
]
EOF
cat <<EOF >configs/config.json
{
  "log": {
    "location": "../logs/"
  },
  "configFiles": {
    "root": "../configs",
    "device": "../configs/device.json"
  },
  "testPath": "../tests/",
  "reportPath": "../results/",
  "certificatePath": "../certificates/",
  "awsRegion": "us-west-2",
  "auth": {
    "method": "file",
    "credentials": {
      "profile": "default"
    }
  }
}
EOF
bin/devicetester_linux_x86-64 run-suite --suite-id GGQ_1 --pool-id bbai1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment