Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Beaglebone Python Programming

You're reading from  Learning Beaglebone Python Programming

Product type Book
Published in Jul 2015
Publisher
ISBN-13 9781784399702
Pages 196 pages
Edition 1st Edition
Languages

Chapter 9. Using the Network

In this chapter, you will learn about using the BeagleBone's network connection to stream data to web services and control hardware remotely through web interfaces. We will cover the following topics:

  • TCP/IP and TCP servers for remote hardware access

  • HTTP servers for remote hardware access

  • Streaming data to remote storage and visualization services

TCP/IP


The BeagleBone has an Ethernet, or IEEE 802.3, connection. This provides a physical layer over which TCP/IP is implemented. TCP/IP, or Transmission Control Protocol/Internet Protocol, is a suite of networking layers that makes up the base of what we call the Internet. It is named after its two most important layers, TCP, which provides error-checked data transfer between endpoints, and IP, which provides routing of packets between hosts based on their IP addresses.

Pretty much all modern operating systems provide interfaces called network sockets, which are created and used to abstract an Internet connection using a model like TCP/IP. A socket is defined by its protocol (for example, TCP), its local IP address, and its local port number. A port is a software abstraction that allows any number of processes on a computer with a single IP address to exchange data over the network independently of each other, by each having their own unique ID, called a port number. Once a connection has...

HTTP


HTTP, or Hypertext Transfer Protocol, is an application protocol that's implemented on top of the TCP/IP suite, and is what the World Wide Web (WWW) is built on. The HTTP protocol defines the request-response structure, in which a client (such as a web browser) requests a resource from a server whose address is given by a Uniform Resource Locator (URL), and the server responds with a resource, such as an HTML file. So instead of opening a TCP socket and keeping it open while passing raw TCP/IP packets, as in the preceding example, the HTTP client connects to the server over a TCP socket and sends an HTTP request packet, then the server sends back an HTTP response packet, and the socket is closed.

PyBBIO includes a library called BBIOServer, which provides an API for creating simple HTML pages for web based user interfaces using HTTP. Let's run a simple example:

from bbio import *
from bbio.libraries.BBIOServer import BBIOServer, Page

server = BBIOServer(8000)

def setup():
  page1 =...

IoT Services


There are a number of services targeting the Internet of Things market that provide a place to store and view data over the Internet. These services typically include a simple HTTP API for streaming data to them, as well as a web interface for viewing the stored data, both as raw samples and in various visual ways. The idea is that you'd have a device like a BeagleBone on a local network, say at your home, and it would be routinely sampling some sort of sensor, say measuring temperature. Every time it reads a new temperature value, the BeagleBone will send it to the remote service's database over the Internet. Then you would be able to go to a website from anywhere, say if you were traveling, and look at the current temperature in your home, as well as track your home's temperature in the past. This is not the most exciting example, but even this could be practical as you could know right away if your heating has stopped working, and you could call to have it serviced before...

Summary


In this chapter, you learned how to take advantage of the BeagleBone's network connection to communicate with external hardware remotely, as well as to stream data to remote servers for storage and viewing.

In the next chapter, we will build upon what you've learned throughout the book to create some larger and more useful programs.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Learning Beaglebone Python Programming
Published in: Jul 2015 Publisher: ISBN-13: 9781784399702
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}