Book Image

BeagleBone Black Cookbook

Book Image

BeagleBone Black Cookbook

Overview of this book

There are many single-board controllers and computers such as Arduino, Udoo, or Raspberry Pi, which can be used to create electronic prototypes on circuit boards. However, when it comes to creating more advanced projects, BeagleBone Black provides a sophisticated alternative. Mastering the BeagleBone Black enables you to combine it with sensors and LEDs, add buttons, and marry it to a variety of add-on boards. You can transform this tiny device into the brain for an embedded application or an endless variety of electronic inventions and prototypes. With dozens of how-tos, this book kicks off with the basic steps for setting up and running the BeagleBone Black for the first time, from connecting the necessary hardware and using the command line with Linux commands to installing new software and controlling your system remotely. Following these recipes, more advanced examples take you through scripting, debugging, and working with software source files, eventually working with the Linux kernel. Subsequently, you will learn how to exploit the board's real-time functions. We will then discover exciting methods for using sound and video with the system before marching forward into an exploration of recipes for building Internet of Things projects. Finally, the book finishes with a dramatic arc upward into outer space, when you explore ways to build projects for tracking and monitoring satellites.
Table of Contents (16 chapters)
BeagleBone Black Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

SSH / Remote access


Local control of your BBB should always be supplemented with the ability to control it remotely. There are a variety of reasons you may want to do this. For example, you may want to operate the device from one location while you are in another location.

The primary and most typical reason for remote access, however, is to run the board headlessly. This means running it without a display, keyboard, or mouse. Headless control is, in fact, the way I operate the board about 99 percent of the time. I rarely even use an external monitor with the BBB since it requires fewer pieces of hardware and reduces headache.

There are two basic recipe types for remote usage:

  1. Command line via SSH

  2. GUI-centric via VNC

Using SSH to control your BBB

Using SSH (secure shell) on a desktop PC or other client will give you control over your BBB across a network. Here is the recipe.

How to do it…

On your BBB:

  1. Open LXTerminal.

  2. Now, enter the following command:

    ~$ sudo ifconfig
    
  3. In the onscreen text, get the IP address of your BBB. Under etho0, look for inet addr: xxx.xxx.xxx.xxx.

On your PC/Mac/Linux box:

  1. Open your preferred terminal app. On the Mac, it's just called Terminal.

  2. At the command prompt, type the following:

    ~$ ssh-keygen -R <your_ip_address>
    
  3. You should then get the following:

    /Users/username/.ssh/known_hosts updated.
    Original contents retained as /Users/ username/.ssh/known_hosts.old
    username@hrh:~$
    
  4. Next, type the following:

    username@devicename:~$ ssh debian@<your_ip_address>
    
  5. Now, you will see the following on screen:

    The authenticity of host '<your_ip_address> (<your_ip_address>)' can't be established.
    RSA key fingerprint is 97:b4:04:f5:24:f3:75:f9:90:3c:cc:ff:78:36:f3:d9.
    Are you sure you want to continue connecting (yes/no)?
    
  6. Type yes (no quotes, all lowercase).

  7. You will then see the following with a new prompt:

    Warning: Permanently added '<your_ip_address>' (RSA) to the list of known hosts.
    debian@<your_ip_address>'s password:
    
  8. Type the password of your BBB login (the default is temppwd).

  9. If you typed in your password correctly, you will end up back here:

    debian@beaglebone:~$
    

Congratulations! You've now gained control over your BBB using the command line from another box.

Using VNC to control your BBB

So, are you still not entirely comfortable with the command line and want access to some of the GUI-based tools? Or, do you need to test and control using an actual GUI? Or, perhaps, is your app not running properly from only the command line? Then, it's time for VNC.

Virtual Network Computing (VNC) allows remote access to a device that's running an X session or windows/GUI-based system from a remote device or client machine. With the current Debian distribution, running VNC is easier than ever as the BBB arrives preloaded with the relevant package, the TightVNC server. On your client box, you need to install a remote viewer.

Getting ready…

For your client box, download and install one of the following remote viewer applications:

Once again, we're cooking up a recipe from a Mac perspective, so VNC Viewer it will be.

How to do it...

As noted, the BBB now comes with the remote server installed, so the only new installation required is the one for your client box. For this, perform the following steps:

  1. Install the client app on your desktop box.

  2. From the terminal window, run the VNC server on the BBB through the following command:

    $ vncserver
    
  3. Next, you will need your BBB's port address. You will find it in the status message now running in the CLI window:

    New 'X' desktop is beaglebone:1
    

    Note

    Your port number may differ.

  4. On your desktop box:

    • Open up VNC viewer (or whichever client app you're using)

    • Type in the IP address of your BBB and the port number at the end of the VNC server field: 123.456.78.9:1. The default my be "beaglebone:1.

  5. You will then have a window pop up Unencrypted Connection.

  6. Click Continue.

  7. Select Connect.

You will now be logged in to your BBB, be able to see the desktop, and have full control over the device using the mouse on your client box.

There's more...

  • Security: Using the default or basic settings in VNC is not secure. Unless you're familiar with doing so, the sessions are not encrypted. One quick, though imperfect, measure is to change from the default server port 5900 to a spare, randomly chosen port.

  • Getting the IP address on a headless BBB: From another computer on the network, use the following steps to list a network's basket of IP addresses:

    ifconfig | grep inet
    
    • Note that this will show the IP address range and only name specific host devices but not other addresses.

    • This method may only be feasible in a smaller network, where the number of addresses is more limited and you do not have to look for a needle in a haystack.

    • You will likely need to install the NMap security scanner (http://nmap.org/). Check whether it's installed first.

    • Then, type in sudo nmap -sn -PE 192.168.1.0/24 (with the IP address of the host machine and then /xxx from the end range shown in Step 1).

  • Browse to the local router admin address: Find the configuration options that show all computers/devices on the network with their IP addresses.

  • Set a static IP address: This takes several steps, but one of the best tutorials is Derek Molloy's at http://derekmolloy.ie/set-ip-address-to-be-static-on-the-beaglebone-black/.