Create a powerful, secure IoT hub running Debian on the BBB in under an hour.
As it's a Xively-fest in the lab these days, I figured I'd share our quick-clone Xively image for the BBB and the configuration steps. Briefly, we are going to:
- Install the latest official version of Debian
- Initial configuration (passwords, Wifi, etc.)
- Install the Xively client
- Connect to Xively's MQTT broker
Create a Debian microSD
Pop your microSD card into a card reader on your laptop or desktop. Locate it using
fdisk as you see fit. If you're unfamiliar with these commands, this is worth a read, as is this.
Make darn sure you know which device is actually the microSD. Flashing the wrong device with
dd (below) has a high probability of irreversibly mangling a hard drive.
Download the latest stock Recommended Debian image from https://beagleboard.org/latest-images.
The image comes as an .xz. To decompress:
$ xz -d bone-debian-*.xz
Once you've extracted the .img image file you can write it to the microSD card. Again, make sure you know which device is the microSD before proceeding. If you have downloaded multiple bone-debian-*.img files, replace bone-debian-*.img with the complete filename. There are three variations on this depending on what OS you're running on the host:
Stock dd if you don't yet have GNU Coreutils 8.24 (Earlier than Ubuntu 16.04)
$ sudo dd if=./bone-debian-*.img of=/dev/sdX-be-sure-this-is-correct
If you have GNU Coreutils 8.24+ (Ubuntu 16.04 or newer)
$ sudo dd if=./bone-debian-*.img of=/dev/sdX-be-sure-this-is-correct status=progress
If you have an older version of Coreutils, but you don't want to wait in the blind, you can install
pv and pipe it through that:
$ sudo dd if=./bone-debian-*.img | pv | dd of=/dev/sdX-be-sure-this-is-correct
(More detailed, and frankly, better, instructions on how to do this from a Windows rel="noopener noreferrer" host over on Derek Molloy's Blog. If you're doing anything with a BeagleBone you might as well bookmark his blog now anyway.)
Assuming you're connected to your BeagleBone via USB, you can now SSH to it at 192.168.7.2:
$ ssh 192.168.7.2
Debian GNU/Linux 8
BeagleBoard.org Debian Image 2016-05-13
default username:password is [debian:temppwd]
Last login: Fri May 13 18:11:11 2016 from 192.168.7.1
Change the password for the debian user:
root@beaglebone:~# passwd debian
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Remove the "default username:password is [debian:temppwd]" from the default SSH greeting by removing that line from
/etc/issue.net. To remove it for local logins you'll want to remove it from
/etc/issue as well.
Configuring rel="noopener noreferrer" WiFi
We're using the Edimax EW-7811Un Wi-Fi USB Adapter, but with no- or minor-adjustment this should work for pretty much any wireless adapter.
If we want our nameservers in
/etc/network/interfaces to populate
/etc/resolv.conf, we need to install the optional package
resolvconf. (I never got connman to work with our setup. If you know how, please post a comment.)
First, we need to bootstrap the stock
/etc/resolv.conf so that we can run apt-get this one time. I'm using Google's:
nameserver 184.108.40.206 nameserver 220.127.116.11
root@beaglebone:~# apt-get install resolvconf Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: cmst connman rcnee-access-point The following NEW packages will be installed: resolvconf 0 upgraded, 1 newly installed, 3 to remove and 48 not upgraded.
Here's our stock
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # Adjust as appropriate allow-hotplug wlan0 iface wlan0 inet static wpa-ssid "<your-network-ssid>" wpa-psk "<your-network-password>"
address 10.10.2.16 netmask 255.255.255.0 gateway 10.10.2.1
dns-nameservers 18.104.22.168 22.214.171.124
# This is a handy place to do an initial script launch for IoT stuff.
# Just make sure you're not launching multiple processes on a reconnect.
# post-up /home/debian/yourscript/start &
# Ethernet/RNDIS gadget (g_ether) # ... or on host side, usbnet and random hwaddr # Note on some boards, usb0 is automaticly setup with an init script iface usb0 inet static address 192.168.7.2 netmask 255.255.255.0 network 192.168.7.0 gateway 192.168.7.1
reboot, and you should be able to SSH in over the network. Obviously sub in your device IP:
$ ssh email@example.com The authenticity of host '10.10.2.16 (10.10.2.16)' can't be established. ECDSA key fingerprint is 03:1e:9b:1e:c1:a6:64:1c:ae:ae:ad:a6:66:a9:51:51. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.10.2.16' (ECDSA) to the list of known hosts. Debian GNU/Linux 8 BeagleBoard.org Debian Image 2016-05-13 firstname.lastname@example.org's password: debian@beaglebone:~$
w00t, we're in.
Verify that resolv.conf was generated correctly:
# cat /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 126.96.36.199 nameserver 188.8.131.52
# ping www.google.com PING www.google.com (184.108.40.206) 56(84) bytes of data. 64 bytes from static-173-44-125-251.cpe.metrocast.net (220.127.116.11): icmp_seq=1 ttl=61 time=12.2 ms 64 bytes from static-173-44-125-251.cpe.metrocast.net (18.104.22.168): icmp_seq=2 ttl=61 time=16.8 ms ^C --- www.google.com ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1001ms rtt min/avg/max/mdev = 12.226/14.550/16.875/2.327 ms
Connect to Xively
From here, all you need to do is complete the steps outlined in Part 1: Install xiPy of the Up and Running on Xively with Python series, and your image is ready to clone. You now have a solid base on which to prototype your next IoT project.
Hit me up with any questions.