26,39 €
Transform your Raspberry Pi into a multi-purpose web server that supports your entire multimedia world with this practical and accessible tutorial!
Seeking inspiration for some new tech projects? Want to get more from your Raspberry Pi? This book has been created especially for you!
There's no end to what you can do with a Raspberry Pi – it makes a huge range of tech projects possible. This book shows you how to transform it into a multipurpose web server, able to store and manage resources that lets you build some truly innovative and impressive computing creations. You'll learn how to use your Raspberry Pi 2 to host a website using a range of different languages, host a game server, store files, and run everything from a media center to a cloud network. If you want to take control of your technological world, start building your own server and find out what's possible with the Raspberry Pi microcomputer.
Begin by getting your Pi set up – follow each step as the book shows you how to prepare a network and configure the additional features that you'll need to build your projects. Once you've done this you'll dig a little deeper and set up your pi as a file server, making sure it's built for speed using a range of different tools, including Python, Node.js and ASP.NET. Following this the book shows you how to extend your server to allow you to host games, and stream live HD video before customizing it even further to create a fully-fledged media center.
It doesn't stop there however – the book then dives into the exciting world of the Internet of Things (IoT). You'll learn how to install Windows IoT onto your Raspberry Pi, the operating system that's driving embedded software projects all around the world. Once you've done this you'll be ready to explore IoT further, as the book shows you how to use your device to host a cloud network that can form the basis of a wider IoT project.
Packed with plenty of practical examples that walk you through a number of Raspberry Pi projects, this book is an accessible journey into embedded computing and Internet of Things.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 212
Veröffentlichungsjahr: 2016
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: April 2016
Production reference: 1220416
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78398-569-2
www.packtpub.com
Author
Piotr J Kula
Reviewers
Ian McAlpine
Cédric Verstraeten
Commissioning Editor
Priya Singh
Acquisition Editors
Usha Iyer
Reshma Raman
Content Development Editor
Sanjeet Rao
Technical Editor
Jayesh Sonawane
Copy Editor
Yesha Gangani
Project Coordinator
Judie Jose
Proofreader
Safis Editing
Indexer
Monica Ajmera Mehta
Graphics
Disha Haria
Production Coordinator
Nilesh Mohite
Cover Work
Nilesh Mohite
Piotr J Kula started his passion for computer technologies when he took apart his father's IBM PC/XT machine at the age of 6. It became clear that Piotr had a natural ability with technology after he reconstructed the machine, and it booted.
After 25 years, Piotr has worked for various companies in different countries. He has always solved complex problems or engaged in new experiences. As long as it had a processor of some sort, Piotr was always the first to try, fix, or configure it.
Today, Piotr is the CEO of his own company, Kula Solution Ltd., in the United Kingdom. Piotr is certified in several Microsoft technologies, and he specializes in Microsoft and Linux technologies.
Piotr's dream is for a unified experience between Linux and Microsoft. He has never been deterred by negativity from either side, and instead, he has strived to find a way to build a bridge between these distant giants. After discovering Raspberry Pi, he completely replaced every other embedded device that he owned and was successful at releasing Raspberry Pi Server Essentials, with Packt Publishing.
Today, Piotr is one step closer to fulfilling his dream with the release of Raspberry Pi 2 Server Essentials. This book is mostly about Linux, but it also talks about integrating and running Windows on your beloved Raspberry Pi.
I would like to thank Katarzyna Kula, my amazing wife who helps me decide when enough work, is enough! For always supporting me through all my projects and countless hours spent on my computers. I would also like to thank the entire Raspberry Pi community, especially the members on Stack Exchange, everybody at Packt Publishing, and those who helped me in various ways to complete this book.
Ian McAlpine's first introduction to computers was his school's Research Machines RML-380Z and his Physics teacher's Compukit UK101. This was followed by a Sinclair ZX81 and then a BBC Micro Model A, which he still has. This interest resulted in a MEng in Electronic Systems Engineering from Aston University and an MSc in Information Technology from the University of Liverpool. Ian is currently a product expert in the BI & Analytics Competency Centre, at SAP Labs, in Vancouver, Canada.
The introduction of Raspberry Pi not only rekindled his desire to tinker but also provided an opportunity to give back to the community. Consequently, Ian was a very active volunteer working on The MagPi, a monthly magazine for Raspberry Pi, which you can read online or download for free from https://www.raspberrypi.org/magpi. He also holds an amateur radio license (callsign VE7FTO) and is a communications volunteer for his local community Emergency Management Office. He was a technical reviewer for the Raspberry Pi Cookbook for Python Programmers and Raspberry Pi Projects for Kids books, both published by Packt Publishing.
I would like to thank my darling wife, Louise, and my awesome kids Emily and Molly for allowing me to disappear into my "office"… and for training our dog to fetch me!
Cédric Verstraeten is an MSc in Engineering who's primarily active in the C++ community. He works as a software engineer and is a huge open source enthusiast. He spends most of his time on side projects that can automate and simplify people's lives. He's the organizer of the Raspberry Pi Belgium meetup and the founder of the Open Source video surveillance system called Kerberos.io.
I would like to thank Packt Publishing for allowing me to be part of this as a reviewer. I really think their books can give people an in-depth overview of a particular topic.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
The purpose of this book is to get you started with Raspberry Pi, but this book has chapters focused on Raspberry Pi 2. The main goal here is to get your projects started with some solid hardware and programming tips, which are essential.
Chapter 1, Getting Started with the Raspberry Pi, will cover the basic equipment that we need to use with this book. We will have to look into other peripherals that we have bought to see how the Raspberry works. We will then see how to flash the newest Raspbian image to our SD card.
Chapter 2, Preparing a Network, will illustrate how to set up LAN and a wireless connection to our network to connect to the Internet. We will set some network benchmarks and understand some of its limitations. We will also look into Dynamic DNS hosting.
Chapter 3, Configuring Extra Features, will illustrate how to update the software and firmware of Raspberry Pi. You will learn about the watchdog and understand how to buy extra decoder licenses.
Chapter 4, Using Fast Web Servers and Databases, will illustrate how to set up a quick web server using nginx with PHP, and we can decide whether we want to use MySQL or SQLite.
Chapter 5, Setting Up the Raspberry Pi as a File Server, will illustrate how to attach and format a USB storage medium. We will not only look into the various ways of sending data to Raspberry Pi, but we will also understand how to share media on the network. As an extra task, we will look into creating the hardware RAID!
Chapter 6, Setting Up Game Servers, will explore open source game engines that are available on the repository. We will also have a sneak peek at the Jessie repository, which is in beta testing.
Chapter 7, Streaming Live HD Video, will explore the camera module and illustrate a simple technique to stream a video. This chapter contains exclusive streaming tutorials.
Chapter 8, Setting Up the Pi as a Media Center Server, will illustrate how to connect an HD monitor and play some videos that were recorded or stored earlier. We will also look into OSMC, and we will explore the benefits of running it as a dedicated media player.
Chapter 9, Running Your Pi from a Battery's Power Source, will explain the benefits of various types of battery technology and how to get the best performance without spending too much money.
Chapter 10, Windows IoT Core, is finally available on the embedded ARM, and it will explore the capabilities of running IoT as an Operating System with a basic programming tutorial with C#.
Chapter 11, Running Your ownCloud, will discuss how to install the ownCloud software on your Pi, and it will free you from privately owned services.
Chapter 12, The Internet of Things – Sensors in the Cloud, is more of a case study about how to complete your projects by storing accurate data accessible anywhere in the cloud.
You need at least a Raspberry Pi 2 with a recommended 8 GB SD card, 1 amp micro USB power supply, and a network cable connected to a router with the Internet.
Seeking inspiration for some new tech projects? Want to get more from your Raspberry Pi? This book has been created especially for you!
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."
A block of code is set as follows:
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
Any command-line input or output is written as follows:
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Clicking the Next button moves you to the next screen."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/RaspberryPi2ServerEssentials_ColorImages.pdf.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
Connecting to a network should be as easy as plugging in a cable. The question is, what can we do on the Raspberry Pi after we are connected to the Internet or a local network? This is why it is essential to learn about the hardware prerequisites and capabilities of the Raspberry Pi, so that your idea is theoretically possible to accomplish. Also, knowing your hardware inside out will make troubleshooting problems much easier to deal with later in the book.
The most common problems associated with the Raspberry Pi are related to power. These problems can cause it to restart, cause unexpected behavior, or may show a rainbow screen during the boot process if you have an external monitor connected.
This chapter is all about identifying your Raspberry Pi and the peripherals that you are using or may want to use along with it. There are two main pieces of information you should know about your Raspberry Pi: the model and version.
This book assumes that you are using a Raspberry Pi 2, Model B.
The Raspberry Pi 2 is mostly backwards compatible with all its predecessors. Whenever a compatibility issue occurs, it will be made clear to the user and an alternative solution will be provided, if possible.
The latest versions of Raspberry Pi at the most basic level only need a power supply and Micro SD card to run. To make initial configurations easier, it is recommended that you also have an HDMI cable, a wide screen monitor or television with HDMI input, an Ethernet cable, and a USB keyboard.
The following table describes the main differences between the various models:
Model
Generation 2 Model B
Model B+
Model A+
Soc
BCM2836
BCM2835
CPU
900 MHz Quad Core ARMv7
700 MHz single core ARMv6
GPU
VideoCore IV @ 250Mhz / OpenGL ES 2.0 / H.264/MPEG-4 AVC
SDRAM
1 GB
512 MB
256 MB
USB
4
2
1
Audio in
No direct input and two revision boards via I2S, all of which use a USB
Network
10/100 Mbit/s
None
GPIO
17
17
17
Header
40 pins
26 pins
26 pins
Power
800 mA (4.0 W)
800 mA (4.0 W)
200 mA (1 W)
SD card
Micro SD slot
With the latest models of the Raspberry Pi, most peripherals should work out of the box, as these versions have been upgraded with a dedicated power circuit to handle peak loads but also reduce overall power consumption. Only the plus models have this new circuit, and all the older versions of Raspberry Pi might suffer from power problems caused by inefficient circuits. The most power-efficient Raspberry Pi is Model A+ and is commonly powered using batteries. We will discuss powering your Raspberry Pi from batteries in a later chapter of this book.
The Raspberry Pi 2 should ideally be powered using a 2 amp USB power supply if you plan to connect peripherals to the USB ports. The most common power supplies found at home are 1 amp power supplies, which are typically supplied with smartphones, tablets, or mini computers. These chargers are usually made from good quality components and can easily handle the stress of additional power, power spikes, and produce a clean DC power source, which is very important for Wi-Fi or serial peripherals.
You should also pay attention to the USB cable that you are using as some cables are produced cheaply and the copper wire inside them is very thin, which struggles to deliver 1 amp or more of current when needed.
In an independent test, the best USB charger turned out to be the HP TouchPad charger (P/N 157-10157-00), and the next best ones are Apple A1265, Apple iPad A1357, and Samsung Cube ETA0U80JBE. They are considered to be the best because they produce very clean DC power and can handle peak loads for extended periods of time. Be careful, though, as a lot of counterfeit chargers are also being sold now, especially Apple A1265. As time passes, some of these power supplies may become obsolete. Try and search for newer tests.
To help visualize the DC noise problem, examine the following image. The waveform on the left-hand side is extremely noisy and will cause serious problems for communication peripherals such as Wi-Fi, bluetooth, or even serial. The waveform on the right-hand side is considered to be clean and stable:
Search the Internet for tips on how to identify counterfeit chargers.
When you purchase a powered USB hub, it is usually supplied with a 2 or 3 amp power supply. This is enough to power USB devices such as a Wi-Fi adapter, a USB hard drive, a few other peripherals, and even the Raspberry Pi itself.
A typical problem occurs with HD USB cameras where the picture goes black after a running for some time. Using a powered USB hub will solve this problem.
SD cards all look alike, but, in fact, some use a multitude of different controllers and NAND Flash memory chips. All these combinations make up the reliability and speed of the card; the cheapest is the worst, usually. That said, spending a fortune on an SD card is not a good idea either. The speeds of SD cards are marked with a numeric symbol ranging from 1, the slowest, to 10, the fastest. A class 6 or 8 SD card is a good balance between performance and price.
However, not all Class 10 cards are the best choice either. The only way to be sure is to use a trusted speed test application to verify that the card is performing at the advertised read and write speeds; this is the best way to identify counterfeit cards:
The SD card should only act as the primary partition for an operating system and applications installed on it. Using an SD card for frequently changing data, such as databases, is not a good idea as it degrades the life of the card faster than expected. Instead, we should use external storage devices, such as hard drives or Network Attached Storage (NAS), to handle frequently changing data but also help with storing large amounts of media.
This book assumes that you are using at least an 8 GB SD card.
