IoT Material 3
IoT Material 3
is Everywhere
Connecting Things
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 1
3.1 Programming
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 2
Programming
3.1.1 What is Code?
What is a Program
• Code is a set of ordered instructions created to accomplish a specific task.
• A bread recipe can be seen as a program.
• Computer programs can be written in different programming languages.
Programs are Everywhere
• All computers need programs.
• Operating Systems, firmware, and applications are
examples of programs.
Why Learn Code?
• Programmers are valued in the job market.
• Today, programmers may work on firmware, device
drivers, mobile applications, web interfaces, data
analysis, and more.
• Programmers can create their own tools.
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 3
Programming
3.1.2 Code Does the Job!
What Makes Up a Program?
• Programs allow people impart logic to computers and are made out of logic structures.
• IF-THEN, FOR Loops, and WHILE Loops are a few logical structures commonly found in programs.
Interpreted Vs. Compiled
• Interpreted languages rely on another program to read, parse, and execute the code.
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 4
Programming
3.1.3 Lending Intelligence
IOT Devices and Data Processing
• A common IoT application uses sensors to collect data.
• Data is often not useful until it has been processed. Collected data is often transported and stored
in the cloud for processing at a later date.
IoT Devices Make Decisions
• Software must be written and uploaded onto IoT devices to allow them to make decisions.
• Decisions can be as simple as triggering an alarm or as
complex as facial recognition.
Software APIs
• Application Program Interface (API) is a set of routines
and software tools that facilitate one application
communicating with another.
• Different types of APIs exist: operating system APIs,
application APIs, website APIs.
• APIs allow applications to communicate, share data, or
ask for specific services from another application.
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 5
Programming
Lending Intelligence – cont’d
REST API
• REST APIs use HTTP based calls between applications to access and manipulate information stored
on powerful databases.
• Web resources used to be identified using a URL. Now resources can be any entity or thing that
can be addressed: today’s step goal, house temperature setting, glucose setting.
• A unique Uniform Resource Identifier (URI) can identify an entity. A URI typically begins with a
slash (/steps)
• REST API requests trigger responses in well-defined formats such as XML or JSON
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 6
Programming
Lending Intelligence – cont’d
Securing the Code
• Devices should protect themselves from attacks that impair its function or allow it to be used
for unintended purposes without authorization.
• Devices should protect the private authentication credentials and key material from
disclosure to unauthorized parties.
• Devices should protect the information received, transmitted, or stored locally on the device,
from inappropriate disclosure to unauthorized parties.
• Devices should protect themselves from being used as a vector to attack other devices or
hosts on the Internet.
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 7
3.2 The Raspberry Pi Single
Board Computer (SBC)
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 8
The Raspberry Pi Single Board Computer (SBC)
3.2.1 Raspberry Pi Hardware
The Raspberry Pi and its Ports
• The Pi is a small and inexpensive computer.
• It has a number of USB ports that can be used to connect various devices including
keyboards, mouse, external drives and cameras.
• The Pi includes an 10/100Mbps Ethernet port and 40 GPIO pins, operating at 3.3V.
• Other Pi ports include an audio out, a micro SD card slot, and a micro USB (used for power)
connector.
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 9
The Raspberry Pi Single Board Computer (SBC)
3.2.2 PL-App
The Raspberry Pi can be accessed locally:
1. Install an operating system image on the micro SD card.
2. Place the card in the micro SD card slot of the RaPi.
3. Connect a USB keyboard.
4. Connect a monitor or TV using the HDMI port.
5. Power the device with a power adapter.
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 10
The Raspberry Pi Single Board Computer (SBC)
3.2.3 Using the Linux Operating System
Understanding Linux
• Linux is open source, fast, reliable and small and requires very little
hardware resources to run.
• Linux is part of several platforms; from wristwatches to
supercomputers.
• Linux distributions include the Linux kernel, plus a number of
customized tools and software packages.
• Debian, Red Hat, Ubuntu and Slackware are just a few examples of
Linux distributions.
• Raspbian is a Linux distribution based on Debian and created
specifically for the Raspberry Pi.
Accessing the Linux Shell
• The Linux operating system can be divided into kernel and shell.
• The shell is a command interpreter.
• The shell is text based and also called CLI (command line interface
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 11
The Raspberry Pi Single Board Computer (SBC)
Using the Linux Operating System (Cont.)
Process Managing Commands
• In Linux, a process is any task or command being executed by the system.
• PIDs are unique numbers assigned to processes for identification.
• ps, top and kill are commands used to manage processes.
File Permissions
• In Linux, most everything is treated as a file.
• File Permissions provide a mechanism to define permissions to files.
• Possible permissions rights are Read, Write, and Execute and can be defined for the user who
owns the file, the group, and other system users.
• The root user can override file permissions.
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 12
The Raspberry Pi Single Board Computer (SBC)
Using the Linux Operating System (Cont.)
Package Managers
• Maintaining computer programs and their library
dependencies manually is not scalable
• Package managers facilitate the installation,
removal, and upgrade of computer programs.
• Package managers usually include user tools and a
remote package repository.
• The repository hosts software packages and their
dependencies.
• dpkg and rpm are popular package managers for
Debian Linux and Red Hat Linux, respectively.
• Raspbian includes dpkg and apt by default.
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 13
The Raspberry Pi Single Board Computer (SBC)
3.2.4 Blockly
Variables and Basic Statements
• Blockly allows the creation of a program without entering any lines of code; it uses colored
blocks.
• Blocks can be connected together by dragging and attaching the appropriate blocks.
• Creating a new variable in Blocky is a simple matter of dragging the variable block and filling in
the value slot.
IF-THEN
• Used to allow the code to make decisions.
FOR Loops
• Used to repeat the execution of a block of code
for a specific number of times.
WHILE Loops
• Used to execute a block of code while a condition
is true.
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 14
The Raspberry Pi Single Board Computer (SBC)
3.2.5 Python on the Raspberry Pi
Using Blocky to Learn Python
• Blockly can be used to enhance Python understanding.
• Beginners can create Blockly programs, convert them to Python and study the result.
The Python Interpreter
• The Python interpreter understands and executes Python code.
• Python code can be created in any text editor and Python interpreters are available for many
operating systems.
• Python developers can create and deploy Python programs in practically any operating system.
• When called with no arguments, the Python interpreter displays the “>>>” prompt and waits for
commands; this is called interactive mode.
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 15
The Raspberry Pi Single Board Computer (SBC)
Python on the Raspberry Pi (cont’d)
Variables and Basic Statements in Python
• Variables are labeled memory areas used to store runtime program data.
• To assign values to variables in Python, use the = (equal to) sign.
• Python’s interactive mode implements the special variable “_”.
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 16
The Raspberry Pi Single Board Computer (SBC)
Python on the Raspberry Pi (cont’d)
Importing Modules Into Your Code
• Use the import <module> keyword to import pre-written code into your programs.
IF THEN In Python
• Allows the execution a block of code based on the result of an expression.
FOR Loops in Python
• Iterates through the items of any sequence
WHILE Loops in Python
• Executes a block of code while the expression is true
Indentation is important in Python!
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 17
Presentation_ID © 2008 Cisco Systems, Inc. All rights reserved. Cisco Confidential 18