Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Learning Raspberry Pi
Learning Raspberry Pi

Learning Raspberry Pi: Unlock your creative programming potential by creating web technologies, image processing, electronics- and robotics-based projects using the Raspberry Pi

Arrow left icon
Profile Icon Serge Schneider Profile Icon Shah
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7 (3 Ratings)
Paperback Apr 2015 258 pages 1st Edition
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Serge Schneider Profile Icon Shah
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7 (3 Ratings)
Paperback Apr 2015 258 pages 1st Edition
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Learning Raspberry Pi

Chapter 2. Developing Web Applications

Modern web technologies allow web pages to be used as full-featured applications to replace traditional programs. The most important of these is AJAX, which allows a page to communicate with the server and dynamically alter web page elements. In this chapter, you will learn the basics of web development by creating a simple web page, changing its visual appearance, and making it interactive. Then, you will learn how a web server can serve dynamic pages generated by Python, before putting all of these skills together to create a media player and radio station that you can access from anywhere. We will cover the following topics in this chapter:

  • Adding page content with HTML
  • Customizing the visual appearance
  • Adding interactivity with JavaScript
  • Simplifying scripts with jQuery
  • An introduction to Python
  • Creating an Internet radio station

Getting started with HTML, JavaScript, and jQuery

In the previous chapter, you were introduced to Raspberry Pi and installed LAMP server on your Raspberry Pi. You also installed WordPress to host your personal website/blogs. So, how do you create your blog/website? This section will give a high-level overview of HTML, CSS, JavaScript, and jQuery.

Tip

If you are familiar with HTML, CSS, JavaScript, and jQuery, you might want to jump directly to the An introduction to Python section. You can get the source code from the book website.

Adding page content with HTML

HTML is used by the web browser to display content. To get started, replace /srv/www/index.php with the index.html file, which contains the following code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Hello world</title>
</head>

<body>
  <h1>Hello World!</h1>
  <p>This is a <em>simple</em><abbr title=
  ...

An introduction to Python

So far, only the client side of a web application or website has been covered. However, the bulk of the work is usually done on the server, rather than in the browser. Python is an excellent language to handle the backend of web applications and it is very well supported on Raspberry Pi. Moreover, it is the official programming language suggested by Raspberry Pi Foundation. Apart from web development, Python can also be used to develop desktop and command-line applications or games and to the interface of the Raspberry Pi to the real world. This makes it easy to create a web application to display sensor data, or to control the Raspberry Pi.

Python code can be tested directly by running the python command to enter the Python shell. Within the shell, statements can be entered directly. In order to exit the shell, enter quit() or press Ctrl + D. To run the code as a proper program, enter it into a file with the .py extension. The program can then be executed by running...

Creating an Internet radio station

Although the previous example had no practical applications, it introduced most of the concepts needed to make something useful. To put the skills together in a more interesting way, the next example will show you how to create your own Internet radio station. A screenshot of the piMusic interface is shown here:

Creating an Internet radio station

The piMusic interface

The aim is to develop a site to play music stored on your Raspberry Pi from anywhere. This will integrate a small file browser that will allow you to browse your music collection and click a file to play it. Clicking Home will return to the top of the music folder, whereas Up will go up one directory level. Instead of playing individual files, clicking Radio will allow you to play a radio station, which you can manage from your Raspberry Pi.

First, create and enter a directory for the new Flask application as follows:

$ mkdir -p ~/piMusic/static/music
$ mkdir ~/piMusic/templates
$ cd ~/piMusic/templates

Creating the user interface...

Deploying Flask applications

As mentioned earlier, running Flask applications by directly launching the script works for testing, but is extremely unsafe and slow. In order to use nginx as the server for Pi MusicBox, the following needs to be added to the server block of the nginx site's configuration file (/etc/nginx/sites-available/pisite):

location = /piMusic { rewrite ^ /piMusic/; }
location /piMusic { try_files $uri @piMusic; }
location @piMusic {
include uwsgi_params;
    uwsgi_param SCRIPT_NAME /piMusic;
    uwsgi_modifier1 30;
    uwsgi_passunix:/tmp/uwsgi.sock;
}

For consistency, the Pi MusicBox directory should be moved to /srv.

Next, uWSGI needs to be installed and configured. You can think of it as the glue that will connect your application to nginx. You can install it by running this:

# apt-get install uwsgi uwsgi-plugin-python

Then, create the app configuration file /etc/uwsgi/apps-available/piMusic.ini as follows:

[uwsgi]
plugins = python
socket =  /tmp/uwsgi.sock
module...

Summary

In this chapter, an important set of technologies for web development was covered and an application that takes advantage of them was developed. The skills gained here can be used to create rich web applications to control Raspberry Pi and attach hardware remotely.

In the next chapter, you will get introduced to Raspberry Pi electronics and some of the electronics components that you will use later in this book. Using this knowledge, you will develop a digital clock, an e-mail notifier, and an alarm clock.

Left arrow icon Right arrow icon

Description

If you have a passion for technology and want to explore the world of Raspberry Pi, then this book provides you with all the tools and information you are looking for. Although being familiar with basic programming concepts is useful, you can still learn a lot from this book as a wide variety of topics are covered.

Who is this book for?

If you have a passion for technology and want to explore the world of Raspberry Pi, then this book provides you with all the tools and information you are looking for. Although being familiar with basic programming concepts is useful, you can still learn a lot from this book as a wide variety of topics are covered.

What you will learn

  • Get to grips with the basics of Linux administration, along with the inner workings of Linux distributions
  • Develop a web interface that can be used to upload selected files and create playlists
  • Discover how to connect your Raspberry Pi to the real world using analog inputs
  • Build your own remotecontrolled robot
  • Get to know about different image processing operations
  • Explore troubleshooting tips and tricks
  • Create your own Twitterenabled Raspberry Pi camera

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 24, 2015
Length: 258 pages
Edition : 1st
Language : English
ISBN-13 : 9781783982820
Vendor :
Raspberry Pi
Category :
Languages :
Concepts :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Apr 24, 2015
Length: 258 pages
Edition : 1st
Language : English
ISBN-13 : 9781783982820
Vendor :
Raspberry Pi
Category :
Languages :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 103.97
Raspberry Pi Blueprints
€36.99
Raspberry Pi Android Projects
€29.99
Learning Raspberry Pi
€36.99
Total 103.97 Stars icon
Banner background image

Table of Contents

8 Chapters
1. Getting Started with Raspberry Pi Chevron down icon Chevron up icon
2. Developing Web Applications Chevron down icon Chevron up icon
3. Introduction to Electronics Chevron down icon Chevron up icon
4. Getting into Robotics Chevron down icon Chevron up icon
5. Introduction to Image Processing Chevron down icon Chevron up icon
6. Image Processing Algorithms Chevron down icon Chevron up icon
7. Troubleshooting, Tips/Tricks, and Resources for Advanced Users Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7
(3 Ratings)
5 star 66.7%
4 star 33.3%
3 star 0%
2 star 0%
1 star 0%
CWJ Koster Jun 01, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book just takes you a bit further on what you can do with a Raspberry Pi. It is a great way to learn more and generate ideas on what to make with your Raspberry Pi. The subjects are chosen well and give a broad range of projects. Although the projects are simple they are good starting points for staring your own projects. Learning Raspberry Pi is a good book with lots of information to start experimenting even more with your Raspberry Pi.
Amazon Verified review Amazon
Heleen Durston Jun 06, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
“Learning Raspberry Pi” by Samarth Shah is not the introductory book to the Raspberry Pi that you might think from the title. The book is meant for someone who already has some experience with the device and is looking to expand their knowledge of what’s possible. The book assumes that you have a model B Raspberry Pi and the special camera that was designed especially for the Raspberry Pi which you usually have to buy separately. Additional hardware is required to complete some of the exercises in the book. The book begins by explaining how to set-up your Raspberry Pi and use New Out Of the Box Software (NOOBS) to load the Linux operating system on the device. Once this is done all sorts of wonderful things are possible! Each chapter in the book covers different projects that you can complete with your Raspberry Pi (usually some extra pieces of equipment). The second chapter discusses how you can set-up a web server and create web pages with the Python computer language and Wordpress. By the end of the chapter you can have your own music station running from the Raspberry Pi.The third chapter does a brief explanation of basic electronics and then helps you create your own digital clock and finally an actual alarm clock. This all requires extra parts that you would need to purchase separately. On a side note I got my Raspberry Pi in the form of a kit (many of which are available online) that came with several pieces of extra equipment including diodes, resistors, etc. Most of what you need for the clock is contained within that kit.The fourth chapter covers robotics, one of my favorite aspects of having a Raspberry Pi. The projects in this chapter definitely require you to purchase extra equipment including the special Raspberry Pi camera. Three separate projects are created and then these three are combined together to make a robot. Lots of scripting in Python is required to make each part of the robot work.The next chapter is about image processing and some of the amazing things that can be done with the camera and your Raspberry Pi. The OpenCV image processing software is used to let you manipulate pictures that you capture with the camera. You also learn how to take time-lapsed pictures and how to set-up a Twitter controlled camera.Chapter six dives into software algorithms that can help with the image processing. Details are given on how to set-up facial recognition and even object tracking. So your Raspberry Pi can be set-up to be a surveillance camera of sorts. How cool is that?!! All of this takes patience and determination but is achievable with the details provided in the book.The book ends with some tips for using the Raspberry Pi as well as help with common problems that can occur. Resources for more advanced projects are listed and author provides his email address so that you can tell him of any Raspberry Pi problems you may have.This is a very interesting book and is great for someone who has completed a couple of projects from the Raspberry Pi website. Many hours of enjoyment and learning can be had from following the projects provided in this book.
Amazon Verified review Amazon
Dustin Marx Jun 12, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
"Learning Raspberry Pi" starts with introductory details regarding Raspberry Pi, but quickly broadens and deepens in its coverage. It provides more lower-level details than one might expect in a "Learning..." book."Learning Raspberry Pi" covers subjects as diverse as Linux commands, web development with Python and HTML5 technologies, a nice introduction to electronics, robotics, and two chapters on image processing. I really liked the final chapter's collection of miscellaneous tips and tricks for dealing with common issues one might run into when working with a Raspberry Pi.Although "Learning Raspberry Pi" does provide introductory coverage of these different technologies, it also goes into depth on some of the topics, particularly image processing. On many of the topics, the book provides just enough introductory information to get going on the subject and additional research might be warranted for deeper learning. There are several highly detailed projects that illustrate the covered concepts.The images and screen snapshots in "Learning Raspberry Pi" are clear and helpful in understanding the concepts. The code listings are comprehensive and are black text on white background with no line numbers and no color syntax.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.