Unit 1
Unit 1
UNIT1
Gateway Design
A gateway connects two dissimilar networks so that data can flow between them.
Usually this is a connection between a proprietary network and the Internet.
Zigbee wireless technology is specially designed for sensors and control devices
that employ low cost connectivity and widely used for several applications.
Wi-Fi is the name of a popular wireless networking technology that uses radio
waves to provide wireless high-speed Internet and network connections. A
common misconception is that the term Wi-Fi is short for "wireless fidelity.
In home automation, different utilities companies may install a wide variety of IoT
devices in your house, each with their own gateway. These can include electricity
or gas, water, phone, Internet, cable/satellite, alarm system, medical devices, and
so on. Some of these gateways may require additional functions, such as local
storage, or a user interface.
SET UP:
Power the board by connecting it to a PC via USB cable
Launch the Arduino IDE
Set the board type and the port for the board
TOOLS -> BOARD -> select your board
TOOLS -> PORT -> select your port
TYPES:
2. LilyPad Arduino
3. RedBoard
5. Arduino Leonardo
NOTE: Do NOT use a power supply greater than 20 Volts as you will overpower
(and thereby destroy) Arduino. The recommended voltage for most Arduino
models is between 6 and 12 Volts.
The pins on your Arduino are the places where you connect wires to construct a
circuit (probably in conjunction with a breadboard and some wire. They usually
have black plastic ‗headers‘ that allow you to just plug a wire right into the board.
The Arduino has several different kinds of pins, each of which is labeled on the
board and used for different functions.
GND (3): Short for ‗Ground‘. There are several GND pins on the Arduino, any of
which can be used to ground your circuit.
5V (4) & 3.3V (5): As you might guess, the 5V pin supplies 5 volts of power, and
the 3.3V pin supplies 3.3 volts of power. Most of the simple components used with
the Arduino run happily off of 5 or 3.3 volts.
Analog (6): The area of pins under the ‗Analog In‘ label (A0 through A5 on the
UNO) are Analog In pins. These pins can read the signal from an analog sensor
(like a temperature sensor) and convert it into a digital value that we can read.
Digital (7): Across from the analog pins are the digital pins (0 through 13 on the
5
UNO). These pins can be used for both digital input (like telling if a button is
pushed) and digital output (like powering an LED).
PWM (8): You may have noticed the tilde (~) next to some of the digital pins (3,
5, 6, 9, 10, and 11 on the UNO). These pins act as normal digital pins, but can also
be used for something called Pulse-Width Modulation (PWM). We have a tutorial
on PWM, but for now, think of these pins as being able to simulate analog output
(like fading an LED in and out).
AREF (9): Stands for Analog Reference. Most of the time you can leave this pin
alone. It is sometimes used to set an external reference voltage (between 0 and 5
Volts) as the upper limit for the analog input pins.
Reset Button
Just like the original Nintendo, the Arduino has a reset button (10). Pushing it will
temporarily connect the reset pin to ground and restart any code that is loaded on
the Arduino. This can be very useful if your code doesn‘t repeat, but you want to
test it multiple times. Unlike the original Nintendo however, blowing on the
Arduino doesn‘t usually fix any problems.
Just beneath and to the right of the word ―UNO‖ on your circuit board, there‘s a
tiny LED next to the word ‗ON‘ (11). This LED should light up whenever you
plug your Arduino into a power source. If this light doesn‘t turn on, there‘s a good
chance something is wrong. Time to re-check your circuit!
TX RX LEDs
TX is short for transmit, RX is short for receive. These markings appear quite a bit
in electronics to indicate the pins responsible for serial communication. In our case,
6
there are two places on the Arduino UNO where TX and RX appear – once by
digital pins 0 and 1, and a second time next to the TX and RX indicator LEDs
(12). These LEDs will give us some nice visual indications whenever our Arduino
is receiving or transmitting data (like when we‘re loading a new program onto the
board).
Main IC
The black thing with all the metal legs is an IC, or Integrated Circuit (13). Think of
it as the brains of our Arduino. The main IC on the Arduino is slightly different
from board type to board
type, but is usually from the ATmega line of IC‘s from the ATMEL company. This
can be important, as you may need to know the IC type (along with your board
type) before loading up a new program from the Arduino software. This
information can usually be found in writing on the top side of the IC. If you want
to know more about the difference between various IC‘s, reading the datasheets is
often a good idea.p
Voltage Regulator
The voltage regulator (14) is not actually something you can (or should) interact
with on the Arduino. But it is potentially useful to know that it is there and what
it‘s for. The voltage regulator does exactly what it says – it controls the amount of
voltage that is let into the Arduino board. Think of it as a kind of gatekeeper; it will
turn away an extra voltage that might harm the circuit. Of course, it has its limits,
so don‘t hook up your Arduino to anything greater than 20 volts.
in C and C++ I/O Variables, pin modes are initialized in the Setup() function
Loop() function, as the name suggests, iterates the specified task in the
program DATA TYPES:
Void ,Long, Int ,Char ,Boolean, Unsigned char ,Byte, Unsigned int, Word
,Unsigned long ,Float, Double, Array ,String-char
array, String-object, Short
void setup()
{
pinMode(12, OUTPUT); // set the pin mode
} void loop()
{
digitalWrite(12, HIGH); // Turn on the LED
delay(1000); digitalWrite(12, LOW); //Turn of
the LED delay(1000);
}
Set the pin mode as output which is connected to the led, pin 12
in this case. Use digitalWrite() function to set the output as
HIGH and LOW
Delay() function is used to specify the delay between HIGH-LOW transition of the
output
Connect he board to the PC
□ Set the port and board type
□ Verify the code and upload,
notice the TX – RX led in the board starts flashing as the code is uploaded.
RASPBERRY PI:
It also has 256MB of RAM in a POP package above the SoC. The Raspberry Pi is
powered by a 5V micro USB AC charger or at least 4 AA batteries (with a bit of
hacking).
While the ARM CPU delivers real-world performance similar to that of a 300MHz
Pentium 2, the Broadcom GPU is a very capable graphics core capable of hardware
decoding several high definition video formats. The Raspberry Pi model available
for purchase at the time of writing — the Model B — features HDMI and
composite video outputs, two USB 2.0 ports, a 10/100 Ethernet port, SD card slot,
11
GPIO (General Purpose I/O Expansion Board) connector, and analog audio output
(3.5mm headphone jack). The less expensive Model A strips out the Ethernet port
and one of the USB ports but otherwise has the same hardware.
You will be needing an image writer to write the downloaded OS into the SD card
(micro SD card in case of Raspberry Pi B+ model). So download the "win32 disk
imager" from the website.
Insert the SD card into the laptop/pc and run the image writer. Once open, browse
and select the downloaded Raspbian image file. Select the correct device, that is
the drive representing the SD card. If the drive (or device) selected is different
from the SD card then the other selected drive will become corrupted. SO be
careful.
After that, click on the "Write" button in the bottom. As an example, see the image
below, where the SD card (or micro SD) drive is represented by the letter "G:\"
12
Fig 1. OS Installation
Once the write is complete, eject the SD card and insert it into the Raspberry Pi
and turn it on. It should start booting up.
3 Setting up the Pi
Please remember that after booting the Pi, there might be situations when the user
credentials like the "username" and password will be asked. Raspberry Pi comes
with a default user name and password and so always use it whenever it is being
asked. The credentials are:
login: pi
password: raspberry
When the Pi has been booted for the first time, a configuration screen called the
"Setup Options" should appear and it will look like the image below.
13
If you have missed the "Setup Options" screen, its not a problem, you can always
get it by typing the following command in the terminal.
sudoraspi-config
Once you execute this command the "Setup Options" screen will come up as
shown in the image above.
Now that the Setup Options window is up, we will have to set a few things. After
completing each of the steps below, if it asks to reboot the Pi, please do so. After
the reboot, if you don't get the "Setup Options" screen, then follow the command
given above to get the screen/window.
The first thing to do:
select the first option in the list of the setup options window, that is select the
"Expand Filesystem" option and hit the enter key. We do this to make use of
all the space present on the SD card as a full partition. All this does is, expand
the OS to fit the whole space on the SD card which can then be used as the
storage memory for the Pi
14
Select the third option in the list of the setup options window, that is select
the "Enable BootTo Desktop/Scratch" option and hit the enter key. It will
take you to another window called the "choose boot option" window that
looks like the image below.
In the "choose boot option window", select the second option, that is, "Desktop
Log in as user 'pi' at the graphical desktop" and hit the enter button. Once done
you will be taken back to the "Setup Options" page, if not select the "OK" button
at the bottom of this window and you will be taken back to the previous window.
We do this because we want to boot into the desktop environment which we are
familiar with. If we don't do this step then the Raspberry Pi boots into a terminal
each time with no GUI options.Once, both the steps are done, select the "finish"
button at the bottom of the page and it should reboot automatically. If it doesn't,
then use the following command in the terminal to reboot.
sudo reboot
After the reboot from the previous step, if everything went right, then you will end
15
sudorpi-update
Updating the firmware is necessary because certain models of the Pi might not
have all the required dependencies to run smoothly or it may have some bug. The
latest firmware might have the fix to those bugs, thus its very important to update it
in the beginning itself.
5 Conclusion
So, we have covered the steps to get the Pi up and running. This method works on
all the different models of Raspberry Pi (model A, B, B+ and also RPi 2) as
Raspbain was made to be supported on all models. However, while installing other
software or libraries, the procedure might change a bit while installing depending
on the model of the Pi or the version of Raspbian itself. The concept of Raspberry
is to keep trying till you get the result or build that you want. This might involve a
16
lot of trial and error but spending the time will be worth it. The actual usage doesn't
end here. This is just the beginning. It is up to you to go ahead to build something
amazing out of it.
GPIO:
Open terminal
sudonanofilename.py
This will open the nano editor where you can write
17
clock line for various types of computer bus, You will probably find I2C
devices that come with their own userspace drivers and the linux kernel includes
some as well. Most computers have an I2C bus, presumably for some of the
purposes listed by wikipedia, such as interfacing with the RTC (real time clock)
and configuring memory. However, it is not exposed, meaning you can't attach
anything else to it, and there are a lot of interesting things that could be attached --
pretty much any kind of common sensor (barometers, accelerometers, gyroscopes,
luminometers, etc.) as well as output devices and displays. You can buy a USB to
I2C adapter for a normal computer, but they cost a few hundred dollars. You can
attach multiple devices to the exposed bus on the pi.
UART, TXD & RXD: This is a traditional serial line; for decades most computers
have had a port for this and a port for parallel. 1 Some pi oriented OS distros such as
Raspbian by default boot with this serial line active as a console, and you can plug
the other end into another computer and use some appropriate software to
communicate with it. Note this interface does not have a clock line; the two pins
may be used for full duplex communication (simultaneous transmit and receive).
1. Sensing
The first step in IoT workflow is gathering information at a ―point of
activity.‖ This can be information captured by an appliance, a wearable device, a
wall mounted control or any number of commonly found devices. The sensing can
be biometric, biological, environmental, visual or audible (or all the above). The
unique thing in the context of IoT is that the device doing the sensing is not one
that typically gathered information in this way. Sensing technology specific to this
purpose is required.
2. Communication
This is where things start to get interesting. Many of the new IoT devices we are
seeing today are not designed for optimal communication with cloud services. IoT
devices require a means for transmitting the information sensed at the device
level to a Cloud-based service for subsequent processing. This is where the great
value inherent in IoT is created. This requires either WiFi (wireless LAN based
communications) or WAN (wide area network… i.e. cellular) communications. In
addition, depending on the need short range communication, other capabilities may
also be needed. These could include Bluetooth, ZigBee, Near-field or a range of
other short range communication methods. For positioning, GPS is often
required as well.
4. Delivery of Information
The last step is delivery of useful information to the end user. That may be a
consumer, a commercial or an industrial user. It may also be another device in the
M2M workflow. The goal in a consumer use case is to provide the information in
as simple and transparent a method as possible. It requires execution of a well
thought out, designed and executed user interface that provides an optimized
experience across multiple device platforms – tablets, smartphones, desktop –
across multiple operating systems – iOS, Android, Windows, etc.
COMMUNICATIONS LAYER
The communication layer supports the connectivity of the devices. There are
multiple potential protocols for communication between the devices and the cloud.
The most wellknown three potential protocols are
• HTTP/HTTPS (and RESTful approaches on those)
• MQTT 3.1/3.1.1(Message Queuing Telemetry Transport)
• Constrained application protocol (CoAP)
Let‘s take a quick look at each of these protocols in turn.
HTTP is well known, and there are many libraries that support it. Because it is a
simple text based protocol, many small devices such as 8-bit controllers can only
partially support the protocol – for example enough code to POST or GET a
resource. The larger 32-bit based devices can utilize full HTTP client libraries that
properly implement the whole protocol. There are several protocols optimized for
IoT use. The two best known are MQTT6 and CoAP7. MQTT was invented in
1999 to solve issues in embedded systems and SCADA. It has been through some
iterations and the current version (3.1.1) is undergoing standardization in the OASIS
MQTT Technical Committee8. MQTT is a publish-subscribe messaging system
based on a broker model. The protocol has a very small overhead (as little as 2
bytes per message), and was designed to support lossy and intermittently connected
23
to choose an ongoing protocol to tunnel over the connection. For the reference
architecture we once again recommend using MQTT as a protocol with
WebSockets. In some cases, MQTT over WebSockets will be the only protocol.
This is because it is even more firewall-friendly than the base MQTT specification
as well as supporting pure browser/JavaScript clients using the same protocol. Note
that while there is some support for WebSockets on small controllers, such as
Arduino, the combination of network code, HTTP and WebSockets would utilize
most of the available code space on a typical Arduino 8-bit device. Therefore, we
only recommend the use of WebSockets on the larger 32-bit devices.
AGGREGATION/BUS LAYER
An important layer of the architecture is the layer that aggregates and brokers
communications. This is an important layer for three reasons:
1. The ability to support an HTTP server and/or an MQTT broker to talk to the devices
2. The ability to aggregate and combine communications from different devices and
HTTP based APIs that are mediated into an MQTT message going to the device.
The aggregation/bus layer provides these capabilities as well as adapting into legacy
protocols. The bus layer may also provide some simple correlation and mapping
from different correlation models (e.g. mapping a device ID into an owner‘s ID or
vice-versa). Finally the aggregation/bus layer needs to perform two key security
roles. It must be able to act as an OAuth2 Resource Server (validating Bearer
Tokens and associated resource access scopes). It must also be able to act as a policy
enforcement point (PEP) for policy-based access. In this model, the bus makes
requests to the identity and access management layer to validate access requests.
The identity and access management layer acts as a policy decision point (PDP) in
this process. The bus layer then implements the results of these calls to the PDP to
either allow or disallow resource access.
25
reaction and autonomic actions based on the data and activity of devices and other
systems
• In addition, this layer may support traditional application processing platforms,
processing. Finally, we need to be able to interact with systems outside this network
using machine-to-machine communications (APIs). These APIs need to be managed
and controlled and this happens in an API management system. The recommended
approach to building the web front end is to utilize a modular front-end architecture,
such as a portal, which allows simple fast composition of useful UIs. Of course the
architecture also supports existing Web server-side technology, such as Java
Servlets/ JSP, PHP, Python, Ruby, etc. Our recommended approach is based on the
Java framework and the most popular Java-based web server, Apache Tomcat. The
dashboard is a re-usable system focused on creating graphs and other visualizations
of data coming from the devices and the event processing layer.
The API management layer provides three main functions:
• The first is that it provides a developer-focused portal (as opposed to the user
focused portal previously mentioned), where developers can find, explore, and
subscribe to APIs from the system. There is also support for publishers to create,
version, and manage the available and published APIs;
• The second is a gateway that manages access to the APIs, performing access
control checks (for external requests) as well as throttling usage based on policies. It
also performs routing and load- balancing;
• The final aspect is that the gateway publishes data into the analytics layer where it
is stored as well as processed to provide insights into how the APIs are used.
DEVICE MANAGEMENT
Device management (DM) is handled by two components. A server-side system (the
device manager) communicates with devices via various protocols and provides
both individualand bulk control of devices. It also remotely manages software and
applications deployed on the device. It can lock and/or wipe the device if necessary.
The device manager works in conjunction with the device management agents.
There are multiple different agents for different platforms and device types. The
device manager also needs to maintain the list of device identities and map these
into owners. It must also work with the identity and access management layer to
27
manage access controls over devices (e.g. who else can manage the device apart
from the owner, how much control does the owner have vs. the administrator, etc.)
There are three levels of device: non-managed, semi-managed and fully managed (NM,
SM, FM).
Fully managed devices are those that run a full DM agent. A full DM agent supports:
• Managing the software on the device
• Enabling/disabling features of the device (e.g. camera, hardware, etc.)
• Management of security controls and identifiers
• Monitoring the availability of the device
• Maintaining a record of the device‘s location if available
• Locking or wiping the device remotely if the device is compromised, etc.
Non-managed devices can communicate with the rest of the network, but have no
agent involved. These may include 8-bit devices where the constraints are too small
to support the agent. The device manager may still maintain information on the
availability and location of the device if this is available.
Semi-managed devices are those that implement some parts of the DM (e.g. feature
control, but not software management).