Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Raspberry Pi Android Projects

You're reading from  Raspberry Pi Android Projects

Product type Book
Published in Sep 2015
Publisher
ISBN-13 9781785887024
Pages 138 pages
Edition 1st Edition
Languages
Author (1):
Gökhan Kurt Gökhan Kurt
Profile icon Gökhan Kurt

Chapter 2. Server Management with Pi

In the first half of this project, we will move from a desktop-based console to a text-based one that gives more power to the user and lets you perform more advanced tasks compared to the desktop. We will access the Pi's Linux console from an Android device and control it remotely. In the second half, we will send and receive files between the Pi and Android through FTP. We will even combine the two parts by managing our newly installed FTP server remotely using the text-based console. In this chapter, we will even install database and web servers on to the Pi to show how to manage them later on. To make it even more fun, we will implement a simple but useful mini project that makes use of both web and database servers. The following topics will be covered:

  • Remote console to the Pi from Android

  • Exchanging files between the Pi and Android

  • A simple database and web server implementation

  • Simple management of servers

Remote console to the Pi from Android


The administrators of Linux and Unix computers have been using text-based command-line interfaces called shell for many years to manage and administer their servers. As the Pi's OS, Raspbian, is a Linux variant, the most natural way to access and issue commands or check the status of running programs, services, and different servers on the Pi is again by issuing commands on this text-based shell. There are different shell implementations but the one that is used on Raspbian by default is bash. The most well-known way of accessing shell remotely on a Linux server is through the Secure Shell protocol known, in general, as SSH.

Note

Secure Shell (SSH) is an encrypted network protocol used to send shell commands to a remote machine in a secure way. SSH does two things for you. It enables, through different tools, such as the ones we will present to you in a moment, you to send commands to the remote machine and it does this using a secure channel established...

Exchanging files between the Pi and Android


In the second part of this chapter, we will use the Pi as an FTP server to share files between our Android devices or send files to the Pi to view them on a larger screen that you connect to the Pi HDMI port. The FTP server we will use is vsftpd. It is a lightweight FTP server used in many small projects. To install it on our Pi, we use the following command:

sudo apt-get install vsftpd

The preceding command will even start the FTP service.

However, we should make some changes in the configuration of the FTP server to use it effectively. For this purpose, we need to edit the FTP server configuration file using this command:

sudo nano /etc/vsftpd.conf

Find the two lines containing #local_enable=YES and #write_enable=YES and remove the # comment sign at the beginning of these lines before you save and exit. These changes will enable the user pi to login and be able to send files to the Pi. To restart the FTP server, issue this command:

sudo service...

A simple database and web server implementation


Next, we'll take our project one step further and install both a database and web server, which we can administer later on using ConnectBot. We will even make it more fun by implementing a real project that makes use of these servers. The best candidate for this purpose is a sensor measurement scenario. We will connect a temperature/humidity sensor to our Pi and save the measurements into a database that we will install on the Pi, which a web server will make available to clients. We can later on manage these servers remotely, which is the main objective in this chapter.

Connecting the sensor

For the purpose of this project, we will use a sensor, DHT11, which measures both temperature and humidity, but for the sake of easier connections, we will use an off-the-shelf module called Keyes DHT11 or DHT11 for short, which contains these sensors.

Tip

There is even an improved version of DHT11, which is DHT22. It costs a little bit more but has more accurate...

Simple management of servers


The following command simply checks the status of the FTP server:

service vsftpd status

This command restarts the FTP server if there's any problem with it:

sudo service vstfpd restart

The service utility that we have used lets you restart the database and web server using these two commands:

sudo service mysql restart
sudo service apache2 restart

Use the following command to check the status of the MySQL server:

mysqladmin -u root -p status

If you believe that the database has grown too much in size, you can start the MySQL console and run a SQL query to see the database size:

mysql –u root –p
mysql> SELECT table_schema "DB", Round(Sum(data_length + index_length) / 1024 / 1024, 1) "Size in MB" 
FROM   information_schema.tables 
GROUP  BY table_schema;

You can even delete records that are older than three days using the following query:

select measurements;
delete from measurements where ttime < NOW() - INTERVAL 3 DAY;

Or, as an alternative, you can check...

Summary


This chapter introduced you to the management of Raspberry Pi as a server and how to issue commands to it from Android. We installed an FTP server on the Pi and shared files between Android clients. To show an example of database and web servers, we implemented a useful project and learned to manage these servers remotely as well.

The next chapter will introduce you to the Pi camera and help you implement a surveillance solution.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi Android Projects
Published in: Sep 2015 Publisher: ISBN-13: 9781785887024
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}