Raspberry Pi 2 Server Essentials - Piotr J Kula - E-Book

Raspberry Pi 2 Server Essentials E-Book

Piotr J Kula

0,0
26,39 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Transform your Raspberry Pi into a multi-purpose web server that supports your entire multimedia world with this practical and accessible tutorial!

About This Book

  • Host websites, games, and even stream HD videos with the impressive power of Raspberry Pi 2
  • Get to grips with embedded programming by turning your Pi into the cloud server that can be used to power Internet of Things projects
  • Make the Raspberry Pi 2 the center of your latest tech experiments and discover how it can manage and host resources

Who This Book Is For

Seeking inspiration for some new tech projects? Want to get more from your Raspberry Pi? This book has been created especially for you!

What You Will Learn

  • Host your Raspberry Pi as a web server using the minimum power resources
  • Connect your Pi to the Internet and perform network benchmarking
  • Explore the cross-platform features of the Pi as you run Python, Node.JS, ASP.NET, and PHP all in one place
  • Share files over the Internet using your Pi as a file server
  • Turn your Pi into a game server, host and engage into playing
  • Enjoy live HD video streaming and exclusive real-time text overlays

In Detail

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.

Style and approach

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:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 212

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Raspberry Pi 2 Server Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Getting Started with the Raspberry Pi
Hardware requirements
Power supply
USB hub
SD cards
Extra peripherals
Essential peripherals
Useful peripherals
Internet 3G dongles
Audio recording
Other media add-ons
Fun peripherals
Installing Raspbian on the Raspberry Pi
Understanding the design of the Raspberry Pi
Boot process
Other capabilities
Hardware limitations
Network speeds
USB bottlenecks
Time
References
Summary
2. Preparing a Network
Local Area Network (LAN)
The eth0 port
The wlan0 interface
The loopback (LO) interface
A wireless configuration (Wi-Fi)
Recommended wireless adapters
Setting up from a desktop
Setting up from a console
Using wicd-curses
A static network address
Testing and benchmarking your network
Basic tests
Advanced benchmarking tools
A speedtest application
iPerf
Recommended bandwidth
Internet configurations
Home packages
Business packages
Dynamic DNS
Installing a client
The free Dynamic DNS domain workaround
Summary
3. Configuring Extra Features
Updating Raspberry Pi
Updating the firmware
Updating packages
Updating distribution
Outcomes
Hardware watchdog
Enabling the watchdog and daemon
Testing the watchdog
Enabling extra decoders
Buying licenses
MPEG-2
VC-1
Hardware monitoring
Summary
4. Using Fast Web Servers and Databases
Apache versus nginx versus Kestrel
Installing nginx
Configuring the nginx virtual hosts
Extra frameworks for nginx
Python API
Executing Python
Node.js
Installing Node.js
What is NPM
The Node.js server
.NET and ASP.MVC
Prerequisites for .NET 5
Installing DNVM, DNU and DNX
Installing DNX
Running the MVC website
MVC and nginx
Other .NET applications
Installing PHP
Installing a database
Installing MySQL
Installing phpMyAdmin
Installing SQLite
Summary
5. Setting Up the Raspberry Pi as a File Server
Connecting the external storage
Preparing the storage medium
Listing the available drives
Formatting a drive
Creating a EXT4 partition
Mounting the drives
Remounting a disk after reboot
Accessing files
The FTP service
Connecting with FileZilla
Connecting with WinSCP
The Samba service
Installing and configuring Samba
Network shares
AFP for Macintosh
Installing and configuring Netatalk
Shares and Time Machine
BitTorrent Sync
Installing BTSync 2
The hardware RAID
Configuration
Massive storage
Redundant storage
Summary
6. Setting Up Game Servers
Updating to Jessie
Selective settings
Game servers
OpenTTD
Installing OpenTTD
Configuring OpenTTD
Playing OpenTTD
Freeciv
Installing Freeciv
Configuring Freeciv
Playing Freeciv
OpenArena
Installing OpenArena
Configuring OpenArena
Playing OpenArena
Minecraft
Installing the Java Hard-Float
Installing the Minecraft server
Configuring Minecraft
Playing Minecraft
Summary
7. Streaming Live HD Video
Installing UV4L
Configuring the UV4L-RaspiCAM
Installing WebRTC
WebRTC streaming
Real time HTTP streaming
Web conferencing
Streaming the X desktop
Text overlay
Object detection and tracking
Removing the overlay watermark
The HUD sample
Using the overlay binary
Inline variables
Compiling the overlay code yourself
Summary
8. Setting Up the Pi as a Media Center Server
Slideshows
Using fbi
Playing videos
OMXPlayer for video playback
Playing audio
Aplay for audio playback
OMXPlayer for audio playback
Using AirPlayer
Using alsamixer
Installing OSMC
Configuring OSMC
Enabling other codecs
Wireless configuration
Media sources
Using add-ons
AirPlay
Enabling CEC and remotes
Performance optimization
Overclocking
Summary
9. Running Your Pi from a Battery's Power Source
Hardware requirements
Charging stations
Battery packs
Voltage regulator
Ohm's Law
Discharge curves
Discharge characteristics
Putting it all together
How long will it last?
Summary
10. Windows IoT Core
Getting started
Flashing IoT
Python for Linux or Windows 7 and 8
The first boot
Remote connections
Visual Studio (VS)
Installing Visual Studio 2015
The Hello World application
Deploying the application
Debugging
Breakpoints
Unhandled exceptions
Samples
Windows 10 IoT WebGUI
Setting up the startup app
Peripherals
Bluetooth
Wireless
Summary
11. Running Your ownCloud
Installation
Requirements
MySQL
nginx and PHP
Permissions
The first configuration
The admin configuration
The server admin
Installing apps
Calendar
Other apps
Daily functionality
The World Wide Access
Summary
12. The Internet of Things – Sensors in the Cloud
What is IoT?
Ohm's law
How much power?
Choosing sensors
Resistors, fuses, and diodes
Transistors
Integrated Circuit Packages
Putting it all together
Accurate data using Arduino
Building a weather station
Real-time embedded devices
The data communication
Real-time events
Analog inputs
Parts required
Storing data on the Cloud
Phant
Summary
Index

Raspberry Pi 2 Server Essentials

Raspberry Pi 2 Server Essentials

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

Credits

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

About the Author

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.

About the Reviewers

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.

www.PacktPub.com

eBooks, discount offers, and more

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.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Preface

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.

What this book covers

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.

What you need for this book

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.

Who this book is for

Seeking inspiration for some new tech projects? Want to get more from your Raspberry Pi? This book has been created especially for you!

Conventions

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:

auto lo iface lo inet loopback iface eth0 inet dhcp

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

allow-hotplug wlan0 auto wlan0 iface wlan0 inet dhcp

Any command-line input or output is written as follows:

sudo touch wpa_supplication.conf nano wpa_supplication.conf

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."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

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.

Customer support

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.

Downloading the example code

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:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

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:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

Downloading the color images of this book

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.

Errata

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

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.

Questions

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.

Chapter 1. Getting Started with the Raspberry Pi

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.

Hardware requirements

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.

Power supply

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:

Tip

Search the Internet for tips on how to identify counterfeit chargers.

USB hub

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

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.

Extra peripherals