This part of the IoT Cookbook provides information, howtos and components for the Raspberry Pi and the Crossbar.io IoT Starterkit.
Use sudo raspi-config
to enable remote SSH access to the Pi - see here.
Then add your public key for password-less login:
ssh [email protected]
mkdir ~/.ssh
chmod 700 ~/.ssh
exit
scp /home/oberstet/.ssh/id_rsa.pub [email protected]:~/.ssh/authorized_keys
To update the system:
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get autoremove
sudo reboot
To install some useful tools:
sudo apt-get install -y wget curl vim git htop screen tmux fio glances
The official docs don't work for me, but this does:
sudo dpkg-reconfigure keyboard-configuration
Enable SPI and I2C by running
sudo raspi-config
Go to "Interfacing Options" and make SPI and I2C are enabled.
The onboard Pi audio and the Neopixels boths use PCM hardware and can't be used at the same time. See here. To disable the onboard audio:
sudo sh -c 'echo "blacklist snd_bcm2835" > /etc/modprobe.d/snd-blacklist.conf'
To check the hardware kernel support modules loaded:
pi@raspberrypi:~ $ lsmod
Module Size Used by
bnep 12051 2
hci_uart 19956 1
btbcm 7916 1 hci_uart
bluetooth 365511 22 hci_uart,bnep,btbcm
brcmfmac 222874 0
brcmutil 9092 1 brcmfmac
cfg80211 543027 1 brcmfmac
rfkill 20851 4 bluetooth,cfg80211
spidev 7373 0
bcm2835_gpiomem 3940 0
spi_bcm2835 7596 0
i2c_bcm2835 7167 0
evdev 12423 2
uio_pdrv_genirq 3923 0
uio 10204 1 uio_pdrv_genirq
fixed 3285 0
i2c_dev 6913 0
ipv6 406279 30
The components we provide are run inside Docker containers.
To install Docker, do
curl -sSL https://get.docker.com | sh
You also need to be able to run Docker without superuser rights (sudo
) which can be done like so
sudo usermod -aG docker pi
Remember to log back in & out or reboot afterwards for this to take effect.
Pull some images:
docker pull crossbario/crossbar-armhf
docker pull crossbario/autobahn-js-armhf
docker pull crossbario/autobahn-python-armhf
To get the Pis serial number:
pi@raspberrypi:~ $ cat /proc/cpuinfo | grep Serial
Serial : 000000005b0966b4
cd ~
git clone https://github.com/crossbario/iotcookbook.git
You'll often run your Pi headless (controlling it via SSH rather than mouse, keyboard and a monitor).
The following is how you set up Wi-Fi in this case. Additionally, this allows setting up Wi-Fi networks that are not presently in range, and to copy a Wi-Fi configuration across multiple devices.
SSH into the Pi and edit the following file:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
For example, here is mine (passwords stripped):
pi@raspberrypi:~ $ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
id_str="office"
ssid="ap-office"
psk="********"
priority=5
}
network={
id_str="home"
ssid="ap-home"
psk="********"
priority=3
}
network={
id_str="mobile"
ssid="ap-mobile"
psk="********"
priority=1
}
You can have multiple networks defined, and have priorities on networks as well (when multiple configured networks are in reach). Switching between networks only works for me when rebooting! There are also recipes for making that automatic using some scripts, eg here - I haven't explored that path yet.
To scan for Wifi networks in reach:
sudo iwlist wlan0 scan
To restart Wifi (without reboot):
sudo ifdown wlan0
sudo ifup wlan0
To get the current Wifi configuration of the Wifi interface:
ifconfig wlan0
To find a Pi on some network:
nmap 192.168.43.*
Eg given above, this Pi (MAC F4:F2:6D:14:1B:56
) will join one of the Wifi network (depending on which one is in reach):
- office: 192.168.1.142
- mobile: 192.168.43.105
- home: 192.168.55.104
The following describes how to clone a SD card, eg for the Crossbar.io IoT Starterkit.
You will need these tools (on your host, not the Pi):
sudo apt install -y pv pigz
Determine your SD card device:
sudo fdisk -l
WARNING: you must be absolutely positive on the device!
dd
is dangerous - it will happily overwrite your main disk if you ask it to.
Insert source SD card and copy the image to a local file (this take roughly 8 minutes on my box):
sudo dd if=/dev/sdb bs=1M | pv | pigz --fast > cb-iot-starterkit.img.gz
To copy the image to a target SD card (a 16GB):
sudo sh -c 'pigz -dc cb-iot-starterkit.img.gz | pv -s 15931539456 | dd of=/dev/sdb bs=1M' && sudo sync
IMPORTANT: do NOT forget
sudo sync
to actually flush all bytes to the SD card and wait until this is finished!
To upload the image to S3:
aws s3 cp cb-iot-starterkit.img.gz s3://package.crossbar.io/