Access and control Raspberry Pi remotely with RaspCTL

Lead Image © Kenny Kiernan, 123RF.com

Distant Connection

Need to access and control a remote Raspberry Pi machine? RaspCTL can help with that, and we show you how to deploy and use the software.

When you enable the OpenSSH server on Raspberry Pi, you can log in to it from any other machine on the local network or on the Internet. Many Raspberry Pi users choose this approach when they need to control Raspberry Pi remotely. This method provides full control over your Raspberry Pi, but it's not the best solution in every situation.

If you need to check vital aspects of the machine, run a script or command, monitor and manage essential services, and perform other mundane tasks, RaspCTL [1] might be a better tool for the job. This application lets you monitor and control a remote Raspberry Pi using a simple web-based interface. Using RaspCTL, you can keep an eye on key aspects like memory and disk usage, define and execute specific commands, start and stop specific services, and even turn your Raspberry Pi into an alarm clock and a radio station. Sound good? Then read on.

Dynamic DNS

Assuming you want to be able to access and control your Raspberry Pi from the Internet, you have to make the little machine accessible from the outside world. The first step is to configure port forwarding in your router so you can access the Raspberry Pi sitting on your local network. Once you've done that, you can connect to Raspberry Pi from the outside world; however, you will need to know the public IP address of your network.

Most Internet Service Providers (ISPs) assign IP addresses dynamically by picking one from a pool of currently available addresses, so your network's IP address is pretty much a moving target. Fortunately, this problem is easy to solve using a so-called dynamic DNS service. Instead of using popular services like No-IP and DynDNS, however, you might opt for the RaspCTL Dynamic DNS service [2] designed specifically for use with Raspberry Pi and maintained by the RaspCTL developer (Figure 1).

Figure 1: RaspCTL Dynamic DNS dashboard.

Using RaspCTL Dynamic DNS offers several advantages. It is a non-commercial service, so there are no "premium" packages, additional for-pay features, ads, and other annoyances, and because the RaspCTL Dynamic DNS client software is developed specifically for Raspberry Pi, installation and configuration can be done in a matter of minutes. Before you do that, though, you need to create an account with the RaspCTL Dynamic DNS service. Go to the sign-up page [3], create an account, log in using the specified credentials, and note the UUID value.

Next, install the raspctl-dynamicdns utility on your Raspberry Pi. This utility is available through a dedicated software repository, so you have to add it to the software sources of your Raspberry Pi. You can start by obtaining and installing the developer's public GPG key:

wget debrepo.krenel.org/raspctl.asc
cat raspctl.asc | sudo apt-key add -

Then, add the repository and install the raspctl-dynamicdns package:

echo "deb http://debrepo.krenel.org/ raspctl main" | sudo tee /etc/apt/sources.list.d/raspctl.list
sudo apt-get update && sudo apt-get install raspctl-dynamicdns

Next, open the raspctl-dynamicdns.conf configuration file in the nano text editor using the

sudo nano /etc/raspctl/raspctl-dynamic-dns.conf

command and add your UUID. Save the file and start the utility with:

sudo raspctl-dynamicdns

Even if your network has a static public IP address, you still might want to use the RaspCTL Dynamic DNS service, because a domain like myrpi.raspctl.com is easier to remember than a multidigit IP address.

Installing and Using RaspCTL

Now that you can find your Raspberry Pi in the vast expanses of the web, you are ready to deploy RaspCTL by running the

sudo apt-get install raspctl

command to install the raspctl package. Then, point your browser to http://<raspberrypi>:8086/ (where <raspberrypi> is the actual IP address of your Raspberry Pi) and log in using the default admin/admin username and password.

After you log in, the first thing you should do is change the default password. Switch to the Configuration section and specify the desired password in the Authentication subsection. You might want to tweak other settings here, too. For example, you can change the default port and enable the help and debug information. The latter displays useful information about various features in RaspCTL.

When you log in to RaspCTL, it automatically drops you into the dashboard section, which shows Raspberry Pi's basic information, such as memory and disk usage and processor info (speed, temperature, and load), as well as processes that consume the most memory and CPU power (Figure 2). Although the dashboard won't replace a dedicated monitoring solution, it can be useful to check the vital stats of your Raspberry Pi quickly.

Figure 2: RaspCTL monitors key aspects, such as memory and disk usage, CPU load, etc.

The Commands section is probably the most important part of RaspCTL. Here, you can define a list of commands and run them when needed. You need to keep in mind a couple of things when working with commands in RaspCTL, however. All commands are executed non-interactively, meaning you don't see a command's output. Thus, you can't run commands that require user input or display information (e.g., uptime, top, etc.). Also, because you can run practically any command (including dangerous commands like rm -rf /), you should be careful when defining commands in RaspCTL.

You can also create commands that execute scripts on Raspberry Pi, but you have to specify the full path to a specific script when defining a command. Finally, if a certain command takes a long time to execute, RaspCTL can become unresponsive. To avoid that, you might want to run the command in the background by appending an &.

Commands in RaspCTL consist of three elements. The Class element defines a generic name that is used to group similar commands by type. For example, you can use RSYNC as a class name for all commands that use the rsync tool. The Action element is used to give the command a descriptive name (e.g., back_up_important_files). The Command element contains the command itself.

As an example, I'll create a simple command that plays a radio stream using the mpg321 audio player (Figure 3). First, install the mpg321 package with:

Figure 3: Creating a command in RaspCTL.
sudo apt-get install mpg321

In the Commands section of RaspCTL, press the New command button. Type RADIO in the Class field, and provide a short description in the Action field (e.g., play_radio_stream).

Next, specify the command in the Command field (e.g., mpg321 http://netradio.radioalfa.dk – replace the example URL with the actual radio stream URL), then press the Save changes button, return to the Commands section, and plug a speaker or headphones into the Raspberry Pi's audio jack. Press the Launch button next to the created command to play the radio stream.

Commands in RaspCTL can also be launched via a URL API, which means you can trigger an existing command by simply pointing your browser to the command's URL. You can use the following URL to trigger the command you've just created:

http://raspberrypi/execute?class=RADIO&action=play_radio_stream

When you create a new command, RaspCTL automatically generates and displays the command's URL for your convenience.

Speaking of streaming radio, RaspCTL is capable of transforming your Raspberry Pi into an Internet radio station, and the application has the dedicated Radio section for that. When you switch to this section for the first time, RaspCTL redirects you to the page containing detailed instructions on how to enable and configure the required software. Basically, you need to install the mpd and mpc packages and make some changes to the /etc/mpd.conf file. Once you've done that, you can use the Radio section to add radio stations and listen to them (Figure 4). Better still, the Alarm section lets you configure alarms that will start playing a radio station at a specific time. Using this functionality, you can turn your Raspberry Pi into a nifty alarm clock.

Figure 4: The Radio section can be used to add radio stations and listen to them.

Finally, the Services section lists system services and lets you manage them (Figure 5). Using the buttons next to each service, you can view the current status of the service as well as start, restart, and stop it. RaspCTL also provides a convenient feature for marking frequently used services as favorites for faster access.

Figure 5: In the Services section, you can view and manage system services.

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • All the Pi

    Raspberry Pi users think small and dream big, imagining ingenious projects that put the unobtrusive Raspberry Pi to work on practical problems. And along the way, they learn things you don't ever discover by pointing and clicking with a smartphone or MacBook.

  • Overclocking the CPU of a Rasp Pi running OpenELEC

    Overclocking the Raspberry Pi CPU improves performance when running the OpenELEC media center.

  • Extending the Raspberry Pi to a miniature music center

    MPD, the Music Player Daemon, converts the Raspberry Pi into a small jukebox. However, configuration is not always easy. We show you what to look out for.

  • Cayenne for Raspberry Pi

    New to the whole Internet of Things (IoT) idea? The Cayenne platform provides a friendly gateway to the world of IoT. Built specifically for Raspberry Pi, this IoT platform can help you transform the little machine into a versatile IoT device and put it to some practical uses.

  • Installing WiFi on the Raspberry Pi

    Integrated Bluetooth and WiFi are important additions to the Raspberry Pi 3. We show you three different methods for adding your Pi to a wireless LAN.