AWS SSM Agent on an RPi 4

So as part of the work I do with AWS DeepRacer I use SSM Agent on the cars and (finally) now also on the Raspberry Pi based timing system, to make things easier I thought I’d “quickly” install and activate SSM on the RPi so I can access them remotely and show the timer online as part of DeepRacer Event Manager (DREM – more on which in another blog post)

Installing SSM on a 32bit OS on an RPi Zero or 4 was easy, just works, however on a 64bit OS I was getting errors:

dpkg: dependency problems prevent configuration of amazon-ssm-agent:armhf:
 amazon-ssm-agent:armhf depends on libc6.

dpkg: error processing package amazon-ssm-agent:armhf (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 amazon-ssm-agent:armhf

Took me a while to find the answer as I didn’t happen to have the time to get an uninterrupted run at fixing the issue and more importantly testing the fix (because I was activating SSM as part of a scripted process) each attempt meant I needed to re-install the OS on the RPi to ensure it was working correctly.

Anyway, the solution was to install libc6:armhf so now my code to install SSM on an RPi 4 running 64bit OS is as follows:

sudo dpkg --add-architecture armhf
sudo apt-get update
sudo apt-get install -y libc6:armhf

mkdir /tmp/ssm
sudo curl https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_arm/amazon-ssm-agent.deb -o /tmp/ssm/amazon-ssm-agent.deb
dpkg -i /tmp/ssm/amazon-ssm-agent.deb
rm -rf /tmp/ssm

And once installed activate SSM as normal.

Hopefully this helps someone, and if not it will probably help future me.

Getting your (Pi) dev on

Update and install some things, this is of course biased to how I like things to be setup ;-)

$ sudo apt-get update && sudo apt-get upgrade -y
$ sudo apt-get install -y vim-nox git zsh python3-pip python3-smbus i2c-tools python3-envirophat python3-blinkt python3-inkyphat
$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
$ mkdir -p ~/.vim/pack/<github_username>/start && $_
$ git clone https://github.com/python-mode/python-mode.git
$ cd python-mode
$ git submodule update --init --recursive

note: just using my github_username above as a handy folder name, probably good if you’re using the dotfiles pattern as well.

And then this guide to configure I2C helped with get the EnviroPhat working

Debugging headless Raspberry Pi Zero W

So of course having posted about setting up a Raspberry Pi Zero W there now follows the inevitable debugging connection problems post ;-)

Without a monitor to use, or a working connection to the Pi debugging was going to be less than simple as I need to look at the logs.

So how do I mount an ext4 volume on a Mac to take a look at the logs?

$ brew cask install osxfuse
$ brew install ext4fuse

So now I can plug the SD card into a reader and mount up the volume which in my case was as simple as:

$ sudo ext4fuse /dev/disk2s2 /Volumes/pi -o allow_other

Then I could navigate into /Volumes/pi and start poking around at the log files to try and find what the issue was.

$ more /var/log/syslog

In my case it was down to user error and not checking the types of WiFi the Zero could support. 5Ghz isn’t supported it would appear, switching to my 2.4Ghz WiFi resolved the problem.

Headless wifi setup on a Raspberry Pi Zero W

So after drawing inspiration from a couple of people and the fact my daughter is now attending the local Coder Dojo. I thought maybe I should get into a bit of hacking and playing around with coding more so I can help answer some of the inevitable questions.

I now have a Pi Zero (W) sitting on my desk with no easy way of setting it up.
Download the latest Raspbian from here. I’m using 2017-11-29-raspbian-stretch-lite in this example which was the latest as of writing.

Oh and because I still can’t solder very well I got the hammer header set to make things a bit easier. (and so I can use a hammer as a soldering iron!)

So this was completed using OSX and serves mainly as a reference for me, but might also be useful for anyone else trying to get Wifi working on a headless Raspberry Pi Zero W

To get the image on to the SD card:

$ brew cask install etcher

And use the simple interface to select the previously downloaded image and your SD card, if the SD card isn’t showing, unplug it from the card reader and plug it back in.

Once etcher has finished writing the image to the card you should be able to use terminal to access the boot volume of the card:

$ cd /Volumes/boot

Create the files you need:

$ touch wpa_supplicant.conf ssh

ssh remains empty and is just there so that SSH is enabled on the Pi at boot time.

** Note: ** If you look at the boot volume of the SD card once it has been used in a Pi you will find that the two files created aren’t present, it’s ok they are moved to the correct location on start up.

You need to configure the wpa_supplicant.conf with your wireless connection(s):

$ vim wpa_supplicant.conf

Add your wifi configuration(s):

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="ESSID"
    psk="Your_wifi_password"
}

Or for multiple connection profiles:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="ESSID1"
    psk="Your_wifi_password"
    priority=100
}
network={
    ssid="ESSID2"
    psk="Your_wifi_password"
    priority=90
}

Save the file

For added winning following this gist you can also set up your Pi Zero W so that you can ssh into it using a USB connection (just plug your USB cable into the right connection, not the power one)

All done? (maybe) unmount the SD card plug into your Pi and power on.

Once you the Pi has successfully booted up you should be able to access it using ssh pi@raspberrypi.local

To get around the inconvenience of having to type your password:

$ scp ~/.ssh/id_rsa.pub pi@raspberrypi.local:~/.ssh/authorized_keys

Don’t forget to still change the default password on the Pi, every time you log in it will be there just above the prompt until you do anyway.