Book Image

BeagleBone Home Automation

By : Juha Lumme
Book Image

BeagleBone Home Automation

By: Juha Lumme

Overview of this book

<p>Home automation lets you control daily activities such as changing the temperature, opening the garage door, or dimming the lights of your house using microprocessors. BeagleBone is a low-cost, high-expansion, hardware-hacker-focused BeagleBoard. It is small and comes with the high-performance ARM capabilities you expect from a BeagleBoard. BeagleBone takes full-featured Linux to places it has never gone before.</p> <p>Starting with the absolute basics, BeagleBone Home Automation gives you the knowledge you will require to create an Internet-age home automation solution. This book will show you how to set up Linux on BeagleBone. You will learn how to use Python to control different electronic components and sensors to create a standalone embedded system that also accepts control remotely from a smartphone.</p> <p>This book starts with the very basics of Linux administration and application execution using terminal connections. You will learn the basics of the general purpose input/output pins and discover how various electronic sensors and electronic components work. The “hardware jargon” is explained, and example applications demonstrating their practical use are created so that you will feel in control of the capabilities provided.</p> <p>Network programming is also a big part of this book, as the created server will be made accessible from the Internet through a smartphone application. You will also learn how to create a fully working Android application that communicates with the home automation server over the Internet.</p>
Table of Contents (14 chapters)

Echo server


Now that you have a basic understanding of how a socket can work, we will create our own custom server and another client so that we have full control over both parts of the transaction.

All the examples that we have created so far have been more or less demonstrative in nature. Let's start building something larger and more functional now, and also re-use some code from Chapter 2, Input and Output, as well. We will need to modularize some of our previous code so that they can be easily re-used and extended.

Create a file called server_socket.py. This utility class won't do much by itself; its sole purpose will be to set up and manage the incoming socket connections. First, let's define a method called initialize_server. In it, we create and bind a socket in much the same way as we did in the client:

def initialize_server(host, port):

  print "Starting server on %s:%s" % (host,port)
  srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

  #Set the socket reuse to 1, so that...