Setting up a Beaglebone Black with Debian Buster for IoT

This post describes how to setup a BBB with Debian Buster with an image designed for IoT use in the year 2021.In the past we have built embedded systems that use single board computers, like the Raspberry Pi and the Beaglebone Black (BBB), for custom products and prototypes. Recently, we have been trying to build a prototype for a system that would be used for converting a non-internet capable machine to be internet-capable and join the Internet of Things (IoT) space.

Our requirements were to use a low powered device that would be capable of running off a n off the shelf Lithium-ion (Li-ion) battery for at least 4-6 hours. With this in mind we dusted off a set of 3 Beaglebone Black (BBB) boards we have had since 2013. The BBB comes with a 2GB eMMC card on the board, a 10/100 Mbps ethernet PHY chip and connector, a USB-A and USB mini-B connector and 512MB of RAM. It also is capable of booting off a microSD card, which is the method we would be using.

However, the operating system on those BBB boards were so old, we had to catch up on updating it to the latest Debian Buster images that are designed for IoT use. Many years ago, we were compiling our own Angstrom distribution from scratch for the 2GB eMMC chip, but now Debian is capable of running on the BBB so we are switching to that. Debian uses more space than 2GB, so using a 16GB microSD card from SanDisk serves our purpose for this task.

This post describes how to setup a BBB with Debian Buster with an image designed for IoT use in the year 2021. This process can be run on any modern Linux distribution like Debian, Ubuntu, Kali Linux or other equivalents. The system that runs the download, such as your laptop, will be called the host system and the BBB device will be referred to as the target system.

Setting up the Debian Buster image on the microSD card

  • First download the latest Debian image from here on your host system. We selected the AM3358 Debian 10.3 2020-04-06 4GB SD IoT image.

  • Verify the SHA-256 sum after the download completes.

  • Install the package called xz-utils on the host system, if not already installed. This will have a tool called xzcat which will be used to decompress the image that was downloaded in the earlier step.

  • Now connect the 16GB or larger microSD card to the host system using an SD-card slot or a USB adapter.

  • Find the device name of the inserted microSD card by doing an ls in the /dev/ folder or by checking dmesg and looking at the latest inserted device. It should look like /dev/sdX where X represents an alphabet between a-z. In our case it is /dev/sdb and we shall be using this device name.

  • Our image size is 4GB and our microSD card is 16GB. So we will write the 4GB image to the microSD card first, use it to boot up the BBB device and then resize the file system using a script provided in the Debian image.

  • Let’s write the image now to the microSD card using the one-liner below:

    $ xzcat bone-debian-10.3-iot-armhf-2020-04-06-4gb.img.xz | sudo dd of=/dev/sdb bs=1M status=progress
  • This will take anything between 10 to 20 minutes to complete and once it is done pop out the microSD card from the host system.

  • Insert the microSD card into the BBB device’s microSD card slot and boot the device up using either a USB cable connected to its mini-B USB port, or using a dedicated 5V 2A power adapter. We had a 5V adapter, so we used that.

  • In case your BBB has an older operating system on the eMMC card, you have to press and hold the USR button, which is near the microSD card slot, then power up the BBB and once the 4 LEDs have lit up you can let go of the button. Now the device will boot up using the microSD card.

Connecting to the BBB

  • Once the BBB has booted up fully, which should take about 30 seconds or less, you can plug in an ethernet cable into the ethernet port and ssh into the device. The default image comes with ssh enabled. The default username is debian and password is temppwd.

  • To find the IP address of the BBB, you can check your router DHCP status page and locate the IP address of the device named beaglebone. You may not need the IP address if you can ping the hostname using ping beaglebone and see if the host system can find the BBB IP address.

  • Or, if you have a HDMI to mini-HDMI cable available you can connect the BBB to a monitor using the cable and then attach a keyboard to the USB A port and directly access the BBB.

  • Since our goal is to make this BBB IoT capable, we want to access it remotely without adding a keyboard to the actual device.

    $ ssh debian@beaglebone
  • The BBB image comes with USB based internet as well, and that may be a way to access the BBB too. Those IP addresses by default are 192.168.7.2 and 192.168.6.2. But for this post we will not be using this method. In fact, later in the post we will show how to change these default IP addresses to avoid conflicts in your network if you have several BBB devices connected.

Upgrading the Operating System

Now that you have connected to the BBB via ssh let us upgrade the Debian operating system to get all the latest packages and security updates. But first we resize the disk.

  • Using /opt/scripts/tools/grow_partition.sh you can expand the 4GB image on the microSD card to take up the full 16GB space on the card. This script must be run as the root user or under sudo. This takes about 1 second to complete.

    $ sudo /opt/scripts/tools/grow_partition.sh
  • Now reboot the device by running sudo reboot.

  • Once the device boots back up again, you should connect back using ssh and be able to run df -h to see it use the full 16GB disk space in the file system display.

  • Upgrading the packages may kill your existing ssh session, so run a screen session first. Then run the following command:

    $ screen -
    $ sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y dselect-upgrade && reboot
  • Break out of the screen session by pressing Ctrl A Ctrl D and wait at least 30-40 minutes for the BBB to fully upgrade the packages.

  • Once the packages have upgraded, the BBB will eventually reboot and be ready to login via ssh.

  • Follow any other upgrade commands that you may like to do by reading this page. One such command we ran was the kernel upgrade by running the following script and followed by a reboot.

    $ sudo /opt/scripts/tools/update_kernel.sh

Disabling Unnecessary Services

  • The default Debian image comes with certain services that may not be necessary for you and may instead become a security issue. We can check which TCP and UDP network services are running by the following command:

    $ sudo netstat -vnatpul
  • Once you have decided which services you do not need, you can disable them and shut these services down. I have left the dnsmasq and ssh services running and disabled the nginx and cloud9 services.

    $ sudo systemctl stop cloud9
    $ sudo systemctl disable cloud9
    $ sudo systemctl stop nginx
    $ sudo systemctl disable nginx
    $ sudo systemctl disable bonescript-autorun
  • If you plan to run a web-service on the BBB, then do not disable nginx as you will need it as your reverse proxy.

  • If the eMMC drive is filled with old data that you do not want to use then for safety you should clean up the drive so that the BBB does not accidentally use that drive for booting. This also frees up the eMMC device for acting like swap space or for storing a custom boot loader in the future. Using lsblk find the correct 2GB device name for the eMMC. It is likely to be /dev/mmcblk1. Then run dd on it to clear it up.

    $ sudo dd if=/dev/zero of=/dev/mmcblk1 bs=1M status=progress

Customizing Hostname, USB network and Login Banners

  • To change the hostname of the BBB device, edit the /etc/hosts and /etc/hostname file with the new hostname you want to use by replacing every occurrence of beaglebone with your new hostname, say beaglebone01. Then reboot the device for it to update to the new name.

  • To edit the default login banner change the /etc/issue and /etc/issue.net files. We edited these files to remove the prompt of the default username and password.

  • We highly recommend to change your default password using the passwd command.

  • To change the USB network IP addresses, you have to edit /etc/default/bb-boot and change the default USB network IP addresses to the appropriate ones for your use case or disable the USB network altogether. Then reboot the system once done.

Setting up WiFi

Sometimes you may be in a situation where your device needs to connect to a WiFi access point and cannot use the ethernet port. In that case you will need a WiFi dongle on the BBB since it does not come with an in-built WiFi chip. The newer Beaglebone boards and the Raspberry Pi boards do come with a WiFi chip. For the BBB, an Edimax USB WiFi dongle is what we have used. Any other USB based WiFi dongle that is supported on Debian will work as well. Insert the WiFi dongle in the USB A port of the BBB device and follow the below steps to set it up.

  • First locate the wireless device on the system.

    $ iwconfig
    wlan0     IEEE 802.11  ESSID:off/any                                                                                                                                                                Mode:Managed  Access Point: Not-Associated   Tx-Power=20 dBm                                                                                                                               Retry short limit:7   RTS thr=2347 B   Fragment thr:off                                                                                                                                    Encryption key:off                                                                                                                                                                         Power Management:off
  • Then get the list of SSIDs this device is able to scan for.

    $ iwconfig wlan0 scan | grep -i essid
    ESSID: “mywifi”
  • Let us assume mywifi is the WiFi network we want to connect to and that it is using WPA2 Personal authentication mode with a password.

  • Let’s encrypt the password correctly and generate a config file that the WiFi daemon wpa_supplicant can read successfully. For the purpose of this post, the password for the WiFi is mypassword.

    $ wpapassphrase “mywifi” "mypassword$" | sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf
    $ cat /etc/wpa_supplicant/wpa_supplicant.conf
    network={                                                                                                                                                                                            ssid="mywifi"                                                                                                                                                                                #psk="mypassword$"                                                                                                                                                                               psk=0818b5551fd6aa10c8e1bb454a694e76a89daa119b57bbb8f2fd9dc8ead81829                                                                                                                         }
  • Now test if the config file works by running the following command:

    $  wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlan0                                                                                                                               Successfully initialized wpa_supplicant                                                                                                                                                              wlan0: SME: Trying to authenticate with f8:c8:29:bb:88:df (SSID='mywifi' freq=2412 MHz)                                                                                                              wlan0: Trying to associate with f8:c8:29:bb:88:df (SSID='mywifi' freq=2412 MHz)                                                                                                                      wlan0: Associated with f8:c8:29:bb:88:df                                                                                                                                                             wlan0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0                                                                                                                                                      wlan0: WPA: Key negotiation completed with f8:c8:29:bb:88:df [PTK=CCMP GTK=CCMP]                                                                                                                     wlan0: CTRL-EVENT-CONNECTED - Connection to f8:c8:29:bb:88:df completed [id=0 id_str=]
  • Setup the systemd service file for the WiFi daemon next.

    $ cp /lib/systemd/system/wpa_supplicant.service /etc/systemd/system/wpa_supplicant.service
  • Edit the file to change the ExecStart line with the following:

    ExecStart=/sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlan0
  • The final file should look like this for example:

    [Unit]                                                                                                                                                                                               Description=WPA supplicant                                                                                                                                                                           Before=network.target                                                                                                                                                                                After=dbus.service                                                                                                                                                                                   Wants=network.target                                                                                                                                                                                 StartLimitInterval=200                                                                                                                                                                               StartLimitBurst=5                                                                                                                                                                                                                                                                                                                                                                                    [Service]                                                                                                                                                                                            Type=dbus                                                                                                                                                                                            BusName=fi.w1.wpa_supplicant1                                                                                                                                                                        ExecStart=/sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlan0                                                                                                             Restart=always                                                                                                                                                                                       RestartSec=30                                                                                                                                                                                                                                                                                                                                                                                          [Install]                                                                                                                                                                                            WantedBy=multi-user.target                                                                                                                                                                           
  • Now enable the service using

    $ systemctl enable wpa_supplicant.service
  • Kill any pre-running services

    $ pkill —QUIT wpa_supplicant
  • Restart the service manually

    $ systemctl start wpa_supplicant
  • Wait for the service to connect to the WiFi network and check the IP address

    $ ifconfig wlan0
    wlan0: flags=-28605<UP,BROADCAST,RUNNING,MULTICAST,DYNAMIC>  mtu 1500                                                                                                                               inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255                                                                                                                           inet6 fe80::76da:38ff:fe70:1be1  prefixlen 64  scopeid 0x20<link>                                                                                                                            ether 77:dd:33:77:aa:dd  txqueuelen 1000  (Ethernet)                                                                                                                                         RX packets 481  bytes 76824 (75.0 KiB)                                                                                                                                                       RX errors 0  dropped 0  overruns 0  frame 0                                                                                                                                                  TX packets 244  bytes 28439 (27.7 KiB)                                                                                                                                                       TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • Reboot the device to make sure that it connects to WiFi on reboot.

  • Try connecting to the device using ssh over the WiFI IP address.

Conclusion

With the above steps we have shown how to setup a Beaglebone Black device with the latest image of Debian Buster as of this writing. You can connect the BBB device using WiFi or Ethernet or both. Once the operating system has been setup, the next step would be to write some software that would take advantage of the BBB’s small form factor and the fact that it can be used as an IoT device.

Stay tuned for the next post in this space. If you or your company are interested in retro-fitting a non-internet connected system or machinery with the internet and remotely control it, reach out to us for help, advice and prototyping.