0% found this document useful (0 votes)
2 views

Unit IV Raspberry Pi

Unit IV discusses IoT communication models, protocols, and APIs, including Bluetooth, WiFi, ZigBee, and GSM modules. It outlines various communication models such as request-response, publish-subscribe, push-pull, and exclusive pair models, along with the significance of IoT APIs like REST and WebSocket for seamless device communication. The document also covers the architecture and characteristics of Bluetooth and WiFi technologies, highlighting their roles in IoT applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Unit IV Raspberry Pi

Unit IV discusses IoT communication models, protocols, and APIs, including Bluetooth, WiFi, ZigBee, and GSM modules. It outlines various communication models such as request-response, publish-subscribe, push-pull, and exclusive pair models, along with the significance of IoT APIs like REST and WebSocket for seamless device communication. The document also covers the architecture and characteristics of Bluetooth and WiFi technologies, highlighting their roles in IoT applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

UNIT IV IOT COMMUNICATION AND OPEN PLATFORMS

IoT Communication Models and APIs – IoT Communication Protocols – Bluetooth – WiFi –
ZigBee – GPS – GSM modules – Open Platform (like Raspberry Pi) – Architecture –
Programming – Interfacing – Accessing GPIO Pins – Sending and Receiving Signals Using
GPIO Pins – Connecting to the Cloud.

"Internet of Things is the network of physical objects or ‘things’ embedded with electronics,
software, sensors and connectivity to enable it to achieve greater value and service by
exchanging data with the manufacturer, operator and/or other connected devices.
Each thing is uniquely identifiable through its embedded computing system but is able to
interoperate within the existing Internet infrastructure.
• An effective communication models shows how the process works and helps one
understand how communication can be done.
• Internet of things enables People and things (devices)to be connected wherever they
are, using any network or service they like.
• IoT allows to connect multiple devices (things) to communicate with each other.
There are four basic types of communication models as given are as follows
1.Request response Model
2.Publisher subscriber Model
3.Push pull model
4.Exclusive pair model
Request & Response Model:
• In the request Response Model client requests information from the server and waits
till the response is served from the server.
• HTTP protocol is used by request Response Model.
• For example, a browser client may request a web page from the server through a
request and the corresponding web page will be served by the server as a response.
• The client and the server can communicate one to one or one to many with more
requests.
• This model is stateless communication model and each Request Response pair is
independent of others.
The communication takes place between a client and a server.
• Whenever required, the client will request information from the server.
• This request is usually in the encoded format.
• So in this model, basically a client sends requests to the server and the server responds
to the requests.
• That is why it is called as Request-Response model.
• After receiving the request from the client, the server decides how to respond, fetches
the data from the database and its resource representation, prepares a response and
ultimately sends the response to the client.
Publish-Subscribe Model(Pub-Sub):
• In this model, you will find three main entities:-
• Publisher, Broker and Consumer.
• Let us see the roles of each of these 3 entities.
• Publishers, send the data to the topics that are managed by the broker.
• They are the source of data.
• The Man in the Middle, the Broker, has the responsibility to accept the data sent by the
publisher and deliver that data to the consumers.
• What is the task of the Consumers? Consumers will subscribe to the broker-managed
topics.
• Once the data is published on a topic, the broker sends this message to all consumers
who have subscribed to the specific topic.
• It works a bit like YouTube. When you subscribe to a channel and tap the Bell icon,
you'll get notifications if the YouTube channel posts a video.
Push-Pull Model:
The push-pull model constitutes data publishers, data consumers, and data queues.
Publishers and Consumers are not aware of each other.
Publishers publish the message/data and push it into the queue. The consumers, present on the
other side, pull the data out of the queue. Thus, the queue acts as the buffer for the message
when the difference occurs in the rate of push or pull of data on the side of a publisher and
consumer.
Queues help in decoupling the messaging between the producer and consumer. Queues also act
as a buffer which helps in situations where there is a mismatch between the rate at which the
producers push the data and consumers pull the data.
Exclusive Pair Model:
 Exclusive Pair Model This communication model is full duplex, bi directional
communication model.
 It uses persistent connection between client and server.
 Client sends request to server for opening the connection.
 This connection is open till the client sends a request for closing the connection.
 It's a bi-directional, full duplex communication model in which a dedicated
communication link is set between the client and the server.
 The connection remains open until the client sends a request to close the connection.
 The client and server can send messages to one another after configuring the
connection.
 As soon as the connection is terminated, no exchange of messages would take place
between the client and the server.

*************
IoT Communication APIs :
• An API is an interface used by programs to access an application. It enables a program
to send commands to another program and receive replies from the app.
• IoT APIs are the interface points between an IoT device and the Internet and/or
other network components.
• Here we will talk about the REST-based API and the Websocket based API.
The Internet of Things (IoT) has changed how we interact with devices and created new
opportunities for businesses to gather and analyze data. However, this has created a demand for
device−to−device communication that is seamless. This is where IoT Communications APIs
come to play a major role in communication systems.

IoT Communications APIs are a set of protocols and interfaces that allow IoT devices and
platforms to communicate with one another.

Internet of Things Communications APIs standardizes how IoT devices communicate with one
another and with other systems. They enable developers to design applications and services that
can access and operate IoT devices without worrying about underlying communication protocols
and interfaces.
 An API is an interface used by programs to access an application. It enables a program
to send commands to another program and receive replies from the app.
 IoT APIs are the interface points between an IoT device and the Internet and/or other
network components.
 Here we will talk about the REST-based API and the Websocket based API.

1.REST-based APIs (Representational state transfer):

• Representational state transfer (REST) is a set of architectural principles by which you


can design Web services the Web APIs that focus on the system's resources and how
resource states are addressed and transferred. URIs(example:- example.com/api/tasks)
are used to depict resources in the RESTful web service.
• Client tries to access these resources via URIs using commands like GET, PUT,
POST, DELETE and so on that are defined by HTTP.
• In response, the server responds with a JSON object or XML file. The REST APIs
follow the request-response model.
The rest architectural constraints are as follows:
Client-server:
• Let me explain it to you by giving a suitable example.
• The client should not be concerned with the storage of data which is a concern of the
server, similarly, the server should not be concerned about the user interface, which is
the concern of the client.
• Separation makes it possible for the client and server to be developed and updated
independently.
Stateless:
The status of the session remains entirely on the client.
Cache-able:
• This property defines whether the response to any request can be cached or not.
• If a response can be cached, then a client cache is granted the right to reuse that
response data for subsequent matching requests.
Layered system:
• A layered system defines the boundaries of the components within each specific layer.
• For example, A client is unable to tell whether it is connected to the end server or an
intermediate node. As simple as that!
Uniform interface:
This specifies that the technique of communication between a client and a server must be
uniform throughout the communication period.
Code on Demand
• Servers may provide executable code or scripts for execution by clients in their context.
Websocket based APIs
• Websocket APIs enable bi-directional and duplex communication between customers
and servers.
• Unlike REST, There is no need to set up a connection every now and then to send
messages between a client and a server.
• It works on the principle of the exclusive pair model. Can you recall it? Yes. Once a
connection is set up, there is a constant exchange of messages between the client and
the server.
• All we need is to establish a dedicated connection to start the process. The
communication goes on unless the connection is terminated.
• It is a stateful type.
• Due to onetime dedicated connection setup, there is less overhead, lower traffic and less
latency and high throughput.
2.WebSocket based APIs:
 WebSocket is a protocol that provides for bidirectional, real−time communication
between a client and a server. WebSocket is frequently used in the context of IoT
Communications APIs to provide low−latency, real−time data streaming between IoT
devices and cloud services.
 WebSocket, unlike HTTP, is a persistent connection between the client and server,
allowing for real−time communication without the need for constant polling. This
makes it perfect for Internet of Things (IoT) applications requiring real−time data
updates, such as monitoring and control systems.
3.CoAP :
 Constrained Application Protocol (CoAP) is a protocol used in Communications APIs
for resource−constrained devices and networks. It is a simple protocol for exposing and
manipulating IoT device resources via the internet.
 CoAP is a low−overhead protocol with tiny message sizes and minimum header
information. As a result, it is well suited for use in IoT devices with low processing
power and memory. CoAP is also intended to function with restricted networks, such as
those based on the IEEE 802.15.4 or 6LoWPAN standards.

4.MQTT:
• MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol
used in IoT Communications APIs to link devices to the cloud. MQTT was created to
be efficient, dependable, and simple to use, making it an excellent choice for IoT
applications.
• MQTT is a publish or subscribe messaging model that allows devices to submit
messages to particular topics and receive messages from topics to which they are
subscribed.
******************

BLUETOOTH:
Bluetooth is a wireless LAN technology designed to connect devices of different functions
such as telephones, notebooks, computers (desktop and laptop), cameras, printers, coffee
makers, and so on.
• A Bluetooth LAN is an ad hoc network, which means that the network is
formed spontaneously.
• Bluetooth was originally started as a project by Ericsson Company.
• It is named for Harald Blaatand, the king of Denmark (940-981) who united
Denmark and Norway.
• Blaatand translates to Bluetooth in English.
• Today, Bluetooth technology is the implementation of a protocol defined by the
IEEE
802.15 standard.
• The standard defines a wireless personal-area network (PAN) operable in an
area the size of a room or a hall.

General Characteristics
 Universal wireless interface
 Ad-hoc networking architecture
 80 MHz in unlicenced ISM band at 2.45 GHz
 Short range (10 m), low power consumption
 Gross bitrate 1 Mbps
 Simultaneous voice and high speed data support
 Evolves from cable replacement -> networking solution

Architecture
• Bluetooth defines two types of networks:
• Piconet
• Scatternet.
Piconets
• A Bluetooth network is called a piconet, or a small net.
• A piconet can have up to eight stations, one of which is called the primary; the
rest are called secondaries.
• All the secondary stations synchronize their clocks and hopping sequence with
the primary.
• Note that a piconet can have only one primary station.
• The communication between the primary and the secondary can be one-to-one or
one-to-many.
• Although a piconet can have a maximum of seven secondaries, an additional
eight secondaries can be in the parked state.
• A secondary in a parked state is synchronized with the primary, but cannot take
part in communication until it is moved from the parked state.
• Because only eight stations can be active in a piconet, activating a station from
the parked state means that an active station must go to the parked state

Scatternet
• Combined form of piconet->scatternet.
• A secondary station in one piconet can be the primary in another piconet.
• This station can receive messages from the primary in the first piconet (as a
secondary) and, acting as a primary, deliver them to secondaries in the second
piconet.
• A station can be a member of two piconets

Bluetooth Devices
• A Bluetooth device has a built-in short-range radio transmitter.
• The current data rate is 1 Mbps with a 2.4-GHz bandwidth.
• This means that there is a possibility of interference between the IEEE 802.11b
wireless LANs and Bluetooth LANs.
Bluetooth Layers
Bluetooth uses several layers that do not exactly match those of the Internet model

Radio Layer
• The radio layer is roughly equivalent to the physical layer of the Internet model.
• Bluetooth devices are low-power and have a range of 10 m.
• Bluetooth devices will be integrated into typical mobile devices and rely on battery
• Tpohw
isere.quires small, low power chips which can be built into handheld devices.
• The combined use for data and voice transmission has to be reflected in the
design, i.e., Bluetooth has to support multi-media data.
Band
• Bluetooth uses a 2.4-GHz ISM band divided into 79 channels of 1 MHz each.

FHSS
• Bluetooth uses the frequency-hopping spread spectrum (FHSS) method in the
physical layer to avoid interference from other devices or other networks.
• Bluetooth hops 1600 times per second, which means that each device changes its
modulation frequency 1600 times per second.
• A device uses a frequency for only 625 µs (1/1600 s) before it hops to another
frequency; the dwell time is 625 µs.

Modulation
• To transform bits to a signal, Bluetooth uses a sophisticated version of FSK,
called GFSK (FSK with Gaussian bandwidth filtering;
• GFSK has a carrier frequency. Bit 1 is represented by a frequency deviation
above the carrier; bit 0 is represented by a frequency deviation below the carrier.
• The frequencies, in megahertz, are defined according to the following formula for
each channel:
• For example, the first channel uses carrier frequency 2402 MHz (2.402 GHz),
and the second channel uses carrier frequency 2403 MHz (2.403 GHz).

Baseband Layer
• The baseband layer is roughly equivalent to the MAC sublayer in LANs.
• The access method is TDMA .
• The primary and secondary communicate with each other using time slots.
• The length of a time slot is exactly the same as the dwell time, 625 µs.
• This means that during the time that one frequency is used, a sender sends a
frame to a secondary, or a secondary sends a frame to the primary.
• Note that the communication is only between the primary and a secondary;
• secondaries cannot communicate directly with one another.

**********
WiFi :
WiFi stands for Wireless Fidelity. It is based on the IEEE 802.11 family of standards and is
primarily a local area networking (LAN) technology designed to provide in- building
broadband coverage.
Current WiFi systems support a peak physical-layer data rate of 54 Mbps and typically
provide indoor coverage over a distance of 100 feet.
WiFi has become the de facto standard for last mile broadband connectivity in homes, offices,
and public hotspot locations. Systems can typically provide a coverage range of only about
1,000 feet from the access point.

A wireless network uses radio waves, just like cell phones, televisions and radiosdo. In
fact, communication across a wireless network is a lot like two-way radio communication.
Here's what happens:

1. A computer's wireless adapter translates data into a radio signal and transmits it using
an antenna.
2. A wireless router receives the signal and decodes it. The router sends the information
to the Internet using a physical, wired Ethernet connection.
The process also works in reverse, with the router receiving information from the Internet,
translating it into a radio signal and sending it to the computer's wireless adapter.

The radios used for WiFi communication are very similar to the radios used for walkie-
talkies, cell phones and other devices. They can transmit and receive radio waves, and they can
convert 1s and 0s into radio waves and convert the radio waves back into 1s and 0s.

But WiFi radios have a few notable differences from other radios:

 They transmit at frequencies of 2.4 GHz or 5 GHz. This frequency is considerably


higher than the frequencies used for cell phones, walkie-talkies and televisions. The
higher frequency allows the signal to carry more data.

They use 802.11 networking standards, which come in several flavours:


 802.11a transmits at 5 GHz and can move up to 54 megabits of data per second. It
also uses orthogonal frequency-division multiplexing (OFDM), a more efficient
coding technique that splits that radio signal into several sub-signals before they reach
a receiver. This greatly reduces interference.
 802.11b is the slowest and least expensive standard. For a while, its cost made it
popular, but now it's becoming less common as faster standards become less expensive.
802.11b transmits in the 2.4 GHz frequency band of the radio spectrum. It can handle up to
11 megabits of data per second, and it uses complementary code keying (CCK)
modulation to improve speeds.
 802.11g transmits at 2.4 GHz like 802.11b, but it's a lot faster -- it can handle up
to 54 megabits of data per second. 802.11g is faster because it uses the sameOFDM coding
as 802.11a.
 802.11n is the most widely available of the standards and is backward compatible
with a, b and g. It significantly improved speed and range over its predecessors. For instance,
although 802.11g theoretically moves 54 megabits of data per second, it only achieves real-
world speeds of about 24 megabits of data per second because of network congestion. 802.11n,
however, reportedly can achieve speeds as high as 140 megabits per second. 802.11n can
transmit up to four streams of data, each at a maximum of 150 megabits per second, but most
routers only allow for two or three streams.
 802.11ac is the newest standard as of early 2013. It has yet to be widely adopted,
and is still in draft form at the Institute of Electrical and Electronics Engineers
(IEEE), but devices that support it are already on the market. 802.11ac is backward
compatible with 802.11n (and therefore the others, too), with n on the
2.4 GHz band and ac on the 5 GHz band. It is less prone to interference and far faster than its
predecessors, pushing a maximum of 450 megabits per second on a single stream, although
real-world speeds may be lower. Like 802.11n, it allows for transmission on multiple spatial
streams -- up to eight, optionally. It is sometimes called 5G because of its frequency band,
sometimes Gigabit WiFi because of its potential to exceed a gigabit per second on multiple
streams and sometimes Very High Throughput (VHT) for the same reason.
 Other 802.11 standards focus on specific applications of wireless networks, like
wide area networks (WANs) inside vehicles or technology that lets you move from one
wireless network to another seamlessly.
 WiFi radios can transmit on any of three frequency bands. Or, they can
"frequency hop" rapidly between the different bands. Frequency hopping helps
reduce interference and lets multiple devices use the same wireless connection simultaneously.
As long as they all have wireless adapters, several devices can use one router to connect to the
Internet. This connection is convenient, virtually invisible and fairly reliable; however, if the
router fails or if too many people try to use high-bandwidth applications at the same time,
users can experience interference or lose their connections. Although newer, faster standards
like 802.11ac could help with that.
***********
Zigbee :
• ZigBee makes possible completely networked homes where all devices are able to
communicate and be controlled by a single unit.
• It provides network, security and application support services operating on the top of
IEEE.
IEEE 802.15.4 & ZigBee :

• Physical Layer: This layer does modulation and demodulation operations up on


transmitting and receiving signals respectively.

• MAC Layer: This layer is responsible for reliable transmission of data by accessing
different networks with the carrier sense multiple access collision avoidance (CSMA).
This also transmits the beacon frames for synchronizing communication.
• Application Support Sub-Layer: This layer enables the services necessary for Zigbee
device object and application objects to interface with the network layers for data
managing services. This layer is responsible for matching two devices according to their
services and need.

Zigbee Device Types :


There are three different ZigBee device types that operate on the layers in any self-
organizing application network
1. Zigbee Coordinator node
2. Full Function Device (FFD)
3. Reduced Function Device(RFD)
1. Zigbee Coordinator Node:
 It is the root of network tree and a bridge to other network
 Able to store information about the network
 Only one ZCN for a network
 It act as a repositary for other security keys

2.The full Function Device :


• An intermediatory router transmitting data from other devices
• Needs lesser memory than Zigbee coordinator node
• Lesser manufacturing cost
• Can operate on all topologies
• Also act as a coordinator
3.The Reduced Function Device:
• Device capable of talking in the network
• It cannot relay data from other devices
• Less memory
• Cheaper than FFD
• It talks only to the n/w coordinator

Zigbee Operating Modes:


Zigbee two way data is transferred in two modes:
• Beacon mode
• Non-Beacon mode
In a beacon mode, the coordinators and routers continuously monitor active state of
incoming data hence more power is consumed. In this mode, the routers and coordinators do not
sleep because at any time any node can wake up and communicate. However, it requires more
power supply and its overall power consumption is low because most of the devices are in an
inactive state for over long periods in the network.
The Non-beacon mode communication is suitable for applications such as smoke detector
and burglar alarm applications where devices ‘sleep' nearly almost all the time. In this mode
there is no data communication from end devices, then the routers and coordinators enter into
sleep state.
Network Topologies:
• Zigbee supports several network topologies; however, the most commonly used
configurations are
1.Star
2.Mesh
3.Cluster tree topologies.
• Any topology consists of one or more coordinator.

1.Star Topology
In a star topology, the network consists of one coordinator which is responsible for
initiating and managing the devices over the network. All other devices are called end
devices that directly communicate with coordinator. This is used in industries where all the
end point devices are needed to communicate with the central controller, and this topology is
simple and easy to deploy.
2. Mesh Topology ;
In mesh, the Zigbee network is extended with several routers where coordinator is responsible
for staring them. These structures allow any device to communicate with any other adjacent node
for providing redundancy to the data. If any node fails, the information is routed automatically to
other device by these topologies. As the redundancy is the main factor in industries, hence mesh
topology is mostly used.

3.Cluster-tree Network :
• In a cluster-tree network, each cluster consists of a coordinator with leaf nodes, and these
coordinators are connected to parent coordinator which initiates the entire network.

Applications:
• The ZigBee Alliance targets applications Across consumer, commercial, industrial and
government markets worldwide
• Home networking
• Industrial control and management
GSM (Global System for Mobile communications) :
GSM (Global System for Mobile communications or Groupe Speciale Mobile)
communications, initiated by the European Commission, is the second-generation mobile
cellular system aimed at developing a Europe-wide digital cellular system.

Base station controller (BSC): The main function of the BSC is to look over a certain number
of BTSs to ensure proper operation. It takes care of handoff from one BTS to the other,
maintains appropriate power levels of the signal, and administers frequency among BTSs.
Mobile switching center (MSC): The MSC basically performs the switching functions of the
system by controlling calls to and from other telephone and data systems. It also does functions
such as network interfacing and common channel signaling. If the MSC has an interface to the
PSTN, then it is called a gateway MSC. GSM uses two important databases called HLR and
VLR, to keep track of the current location of a MS.
Authentication center (AUC): AUC unit provides authentication and encryption parameters
that verify the user’s identity and ensure the confidentiality of each call. The AUC protects
network operators from different types of frauds and spoofing found in today’s cellular world.
Equipment identity register (EIR): EIR is a database that contains information about the
identity of mobile equipment
Home Location Register (HLR):
 The HLR is a central database that stores subscriber information for users registered to
a particular mobile network operator.
 It contains permanent subscriber data such as the subscriber's service profile, current
location area, supplementary services, and authentication information.
 When a subscriber initiates a call or sends a message, the network consults the HLR to
retrieve necessary subscriber information for call setup or message delivery.
 The HLR also handles subscriber authentication and authorization processes.
Visitor Location Register (VLR):
 The VLR is a temporary database that stores information about subscribers who are
currently located in a particular area served by a Mobile Switching Center (MSC).
 When a mobile subscriber roams into a new location area, the VLR associated with the
serving MSC of that area temporarily stores subscriber information from the HLR.
 The VLR allows the network to quickly access subscriber data without needing to
repeatedly query the HLR for each call or message.
 It plays a key role in call routing by providing the necessary subscriber information to
the MSC for call setup and management.
Frequency Bands and Channels :
GSM has been allocated an operational frequency from 890MHz to 960 MHz.
To reduce possible interference, the MS and the BS use different frequency ranges (i.e., MSs
employ 890MHz to 915MHz and BS operates in 935MHz to 960 MHz).
Frames in GSM :
The GSM system uses the TDMA scheme shown in Figure. With a 4.615 ms– long frame,
divided into eight time slots each of 0.557 ms. Each frame measured in terms of time is 156.25
bits long, of which 8.25 period bits are guard bits for protection.

International mobile subscriber identity (IMSI):


 The IMSI is a unique identifier assigned to each SIM card in the GSM network.
 It consists of a Mobile Country Code (MCC), Mobile Network Code (MNC), and
Mobile Subscriber Identification Number (MSIN).
 The IMSI is used by the network to identify the subscriber and provide services such as
call routing and authentication.
 These values are called the international mobile subscriber identity (IMSI). This
number is usually 15 digits or less.
Subscriber identity module (SIM):
 Every time the MS has to communicate with a BS, it must correctly identify itself.
 A MS does this by storing the phone number (or the number used to contact the MS),
personal identification number for the station, authentication parameters, and so on in
the SIM card.
 The SIM card is the heart of a GSM phone, and the MS is unusable without it
International Mobile Equipment Identity (IMEI):
 The IMEI is a unique identifier assigned to each mobile device (phone or modem) in
the GSM network.
 It is used to identify the device itself rather than the subscriber.
 The IMEI is often used for tracking lost or stolen devices and for network security
purposes.
Mobile Subscriber ISDN Number (MSISDN):
• The MSISDN is the telephone number associated with a mobile subscriber.
• It includes the country code, area code (if applicable), and the subscriber number.
• This is the number used to dial and reach the mobile subscriber over the GSM network.
Temporary Mobile Subscriber Identity (TMSI):
 The TMSI is a temporary identifier assigned to a mobile subscriber during a particular
session or location area update.
 It is used for privacy and security purposes to avoid transmitting the IMSI over the air
interface frequently.
 The TMSI helps in reducing the possibility of eavesdropping or tracking the
subscriber's movements.
Location Area Identity (LAI):
• The LAI is an identifier used to identify a geographical area within the GSM network.
• It consists of a Mobile Country Code (MCC), Mobile Network Code (MNC), and
Location Area Code (LAC).
• The LAI is used for paging and location updating procedures within the network.

GPS (Global Positioning System) :


• The global positioning system is a space based radio navigation system consisting of a
constellation of satellites broadcasting navigation signals and a network of ground
stations and satellite control stations used for monitoring and control.
• GPS system is associated with coordinated universal time or UTC as observed by the
US Naval observatory.
• The accuracy of GPS is based on the clear and fine visibility of the sky, and any
obstructions by means of tree branches or building density may lead to limited the
accuracy in the forest and urban areas.
• GPS satellites transmit signals to provide accurate PVT information to an unlimited
number of users on the earth.
• GPS satellites broadcast a signal that encodes position and time with a high accuracy
derived from the satellites atomic clock time standard.
• The GPS receivers use the time of arrival ranging to generate pseudo range to
determine the users position.
• Currently 31 GPS satellites orbit the earth at an attitude of approximately 11,000 miles
providing users with accurate information on position, velocity and time anywhere in
the world and in all weather conditions.

GPS includes three main segments:


1. The space segment
2. Control segment
3. User Segment
• The GPS space segment includes over 30 satellites in orbit operated and maintained by
the U.S. space force.
• These satellites broadcast radio signals to control and monitoring stations on earth and
directly to users requiring highly precise satellite positioning.
• The U.S space force also overseas the GPS control segment.
• It includes master control and backup control stations , dedicated ground antennas and
several monitor stations located worldwide.
• These stations work to ensure GPS satellites are healthy, orbiting in the correct
locations and have accurate atomic clocks on board.
• These stations are integral to the overall health and accuracy of the GPS constellation.
• The user segment includes everyone relying upon GPS satellites for PNT
measurements.
• From a mobile phone providing directions to autonomous vehicles requiring lane level
positioning accuracy; from a farmer tracking planting and harvesting routes year-over-
year to a UAV mapping a rainforest, many applications use GPS for high precision
positioning and accuracy around the world.
• In GPS-enabled IoT applications, communication protocols play a crucial role in
transmitting location data efficiently and reliably.
• MQTT (Message Queuing Telemetry Transport) stands out for its lightweight nature
and low bandwidth usage, making it ideal for publishing location data from GPS
devices to brokers for distribution to subscribers.
• HTTP/HTTPS protocols offer standard communication between GPS devices and
servers, enabling data transmission via POST requests for processing and storage.
• CoAP (Constrained Application Protocol) caters to resource-constrained environments,
providing a lightweight option for data exchange. WebSocket ensures real-time
communication by establishing persistent connections between GPS devices and
servers.
• LoRaWAN suits long-range communication with low-power devices, while Bluetooth
Low Energy (BLE) facilitates short-range data transmission to nearby devices for
further processing or display, highlighting the diverse options available to meet specific
IoT application requirements.
Advantages:
• Accurate Positioning
• Global Coverage
• Real-Time Tracking
• Improved Efficiency
• Enhanced Safety and Security
• Versatility:
Disadvantages:
• Signal Interference
• Power Consumption
• Indoor Limitations
• Cost
Applications:
• Asset Tracking
• Fleet Management
• Smart Agriculture
• Personal Tracking
• Emergency Response
• Geolocation-based Services

Raspberry Pi :
Raspberry Pi is a small single-board computer (SBC). It is a credit card-sized computer that
can be plugged into a monitor. It acts as a minicomputer by connecting the keyboard, mouse,
and display. Raspberry Pi has an ARM processor and 512MB of RAM. The architecture of
Raspberry Pi is discussed in this article.

Raspberry Pi mainly consists of the following blocks:


Processor: Raspberry Pi uses Broadcom BCM2835 system on chip which is an ARM processor
and Video core Graphics Processing Unit (GPU). It is the heart of the Raspberry Pi which
controls the operations of all the connected devices and handles all the required computations.
HDMI: High Definition Multimedia Interface is used for transmitting video or digital audio data
to a computer monitor or to digital TV. This HDMI port helps Raspberry Pi to connect its signals
to any digital device such as a monitor digital TV or display through an HDMI cable.
GPIO ports: General Purpose Input Output ports are available on Raspberry Pi which allows the
user to interface various I/P devices.
Audio output: An audio connector is available for connecting audio output devices such as
headphones and speakers.
USB ports: This is a common port available for various peripherals such as a mouse, keyboard,
or any other I/P device. With the help of a USB port, the system can be expanded by connecting
more peripherals.
SD card: The SD card slot is available on Raspberry Pi. An SD card with an operating system
installed is required for booting the device.
Ethernet: The ethernet connector allows access to the wired network, it is available only on the
model B of Raspberry Pi.
Power supply: A micro USB power connector is available onto which a 5V power supply can be
connected.
Camera module: Camera Serial Interface (CSI) connects the Broadcom processor to the Pi
camera.
Display: Display Serial Interface (DSI) is used for connecting LCD to Raspberry Pi using 15 15-
pin ribbon cables. DSI provides a high-resolution display interface that is specifically used for
sending video data.
A powerful feature of the Raspberry Pi is the row of GPIO (general-purpose input/output) pins
along the top edge of the board. A 40-pin GPIO header is found on all current Raspberry Pi
boards

Voltages:
Two 5V pins and two 3.3V pins are present on the board, as well as a number of ground pins
(GND), which can not be reconfigured. The remaining pins are all general-purpose 3.3V pins,
meaning outputs are set to 3.3V and inputs are 3.3V-tolerant.

Outputs:
A GPIO pin designated as an output pin can be set to high (3.3V) or low (0V).

Inputs :
A GPIO pin designated as an input pin can be read as high (3.3V) or low (0V). This is made
easier with the use of internal pull-up or pull-down resistors. Pins GPIO2 and GPIO3 have fixed
pull-up resistors, but for other pins this can be configured in software.

Other functions :
As well as simple input and output devices, the GPIO pins can be used with a variety of
alternative functions, some are available on all pins, others on specific pins.
PWM (pulse-width modulation):
Pulse width modulation (PWM) is a modulation technique that generates variable-width
pulses to represent the amplitude of an analog input signal.
 Software PWM available on all pins
 Hardware PWM available on GPIO12, GPIO13, GPIO18, GPIO19
SPI:
A serial peripheral interface (SPI) is an interface commonly used in computers and
embedded systems to facilitate short-distance communication between a microcontroller
and one or more peripheral integrated circuits (ICs). Serial Peripheral Interface (SPI) is a full-
duplex serial protocol for communicating with high-speed peripherals.

 SPI0: MOSI (GPIO10); MISO (GPIO9); SCLK (GPIO11); CE0 (GPIO8), CE1 (GPIO7)
 SPI1: MOSI (GPIO20); MISO (GPIO19); SCLK (GPIO21); CE0 (GPIO18); CE1
(GPIO17); CE2 (GPIO16)

I2C :
I2C stands for Inter-Integrated Circuit. It is a bus interface connection protocol incorporated into
devices for serial communication. I2C stands for Inter-Integrated Circuit. It is a bus interface
connection protocol incorporated into devices for serial communication.
 Data: (GPIO2); Clock (GPIO3)
EEPROM :
Data: (GPIO0); EEPROM Clock (GPIO1)
Serial:
 TX (GPIO14); RX (GPIO15)
GPIO pinout :
A GPIO reference can be accessed on your Raspberry Pi by opening a terminal window and
running the command pinout. This tool is provided by the GPIO Zero Python library, which is
installed by default in Raspberry Pi OS.

Serial interface:
The serial interface on Raspberry Pi has received (Rx) and transmit (Tx) pins for
communication with serial peripherals.

Raspberry Pi has multiple serial ports. The first two are called primary and secondary. By
default, primary appears on GPIO 14 (transmit) and 15 (receive) of the J8. Secondary is used by
bluetooth, on Raspberry Pi that support bluetooth. Each port is driven by a UART. On every
Raspberry Pi there are at least two of them: UART0 and UART1. The assignment of which
UART drives which port depends on the model and its configuration.
***********

Interfacing:
Introduction to UART:
UART (Universal Asynchronous Receiver/Transmitter) is a serial communication
protocol in which data is transferred serially i.e. bit by bit. Asynchronous serial communication
is widely used for byte oriented transmission. In Asynchronous serial communication, a byte of
data is transferred at a time.
UART serial communication protocol uses a defined frame structure for their data bytes. Frame
structure in Asynchronous communication consists:
• START bit: It is a bit with which indicates that serial communication has started and it is
always low.
• Data bits packet: Data bits can be packets of 5 to 9 bits. Normally we use 8-bit data
packet, which is always sent after the START bit.
• STOP bit: This usually is one or two bits in length. It is sent after data bits packet to
indicate the end of frame. Stop bit is always logic high.

Usually, an asynchronous serial communication frame consists of a START bit (1 bit)


followed by a data byte (8 bits) and then a STOP bit (1 bit), which forms a 10-bit frame as shown
in the figure above. The frame can also consist of 2 STOP bits instead of a single bit, and there
can also be a PARITY bit after the STOP bit.
Raspberry Pi UART :
In Respberry Pi pin - GPIO 13 and GPIO 14 used for UART communication
Raspberry Pi has two in-built UART which are as follows:
• PL011 UART
• mini UART
PL011 UART is an ARM based UART. This UART has better throughput than mini UART.
The PL011 is a stable and high performance UART. For better and effective communication use PL011
UART instead of mini UART.

SPI serial peripheral interface:


The SPI serial peripheral interface bus is a serial bus that has three lines for communication
needs. SPI is based on the master-slave principle. That means that there is a master that requests
the slaves to output their data. Independent the slaves cannot communicate with each other. The
master in our case is the Raspberry Pi, the slave can use any component with an SPI interface
(see Figure 1).
The figure clearly shows that there is an additional line per subscriber it is possible to connect
several participants to the same bus. The fourth line is the chip select signal. This allows the
master to select the participant to be communicated with.

 MOSI (Master Out Slave In): Pin 19 of the GPIO connector strip
 MISO (Master In Slave Out): Pin 21 of the GPIO connector strip
 SCLK (Serial Clock): Pin 23 of the GPIO connector strip
 CS / CE (Chip Select or Chip Enable): Pins 24 and 26 or any free one
 The output of the GPIO connector strip
MOSI and MISO:
 The MOSI and MISO lines are the data lines where MOSI is responsible for transmitting
data from the master to the slave and MISO is responsible to transmit data from the slave
to the master.
 When the slave needs to send a response back to the master, the master will first generate
a prearranged number of clock cycles first before the slave transmits data on the MISO
line.
 Compared to asynchronous serial where data is sent in either direction at any amount, the
master knows how much data is being returned and when in SPI.

SCLK:
 SCLK which is the clock signal is generated by the master to the slave to signal it to look
at the data line to read data bits incoming.
 In SPI interfaces, there is only one master who is in charge of generating the clock signal
to one or more slaves.

SS / CSS:
SS/CSS has the same functionality as chip select which is used as an addressing function. This
signal is normally an active-low signal which is then pulled high to disconnect a slave from the
SPI bus.
SPI Data Transmission:
 An SPI communication will typically start with:
 Master sending a clock signal and selecting a slave through the SS line.
 Master will send a logic 0 signal to select a slave as this line is on an active low signal.
 If a waiting period is required (eg. Analog to digital conversion) the master will be
required to wait for a period of time before being able to send the clock signal.
 SPI is a full-duplex interface so both master and slave can send data to each other at the
same time via the MOSI and MISO lines respectively and data are being simultaneously
transmitted between the master and slave. This will be synchronized by the serial clock.
For example, these two operations will happen at the same time:
 Master sends data one bit at a time on the MOSI line = Slave Reads it
 (If a response is needed) Slave returns the data one bit at a time to the master on
the MISO line = Master reads it
 SPI provides you with the flexibility to select the rising or falling edge of the clock to
sample or shift the data.
 For the number of data bits to be transmitted, please do refer to your device datasheet as
every device differs.

SPI Slave Selection:


As mentioned above, the SPI protocol first starts with the Master sending a clock signal and
selecting a slave through the SS line. On the SS line, there are two ways in which the master can
use to select a slave to receive or send data when there are multiple slaves involved. They are:

Through this configuration, each slave will require a separate SS line.


The master will activate a particular slave by making the particular slave SS line low while
keeping the others high.

Inter - Integrated Circuit Bus:


• The name stands for “Inter - Integrated Circuit Bus”
• A Small Area Network connecting ICs and other electronic systems
• Developed by Philips Semiconductors
• I2C can support up to 128 slave Devices
• Today, a variety of devices are available with I2C Interfaces
– Microcontroller, EEPROM, Real-Timer, interface chips, LCD driver, A/D
converter

• I2C bus/interface is used to communicate with the external devices like RTC, MPU6050,
Magnetometer, etc with only 2 lines. We can connect more devices using I2C interface if
their addresses are different.
• To access I2C bus in Raspberry Pi, we should make some extra configuration. Raspberry
Pi has I2C pins which are GPIO 2 and GPIO 3 (Refer Raspberry Pi Pin diagram)

• SDA
– This signal is known as Serial Data. Any data sent from one device to another
goes on this line
• SCL
– This is the Serial Clock signal. It is generated by the master device and controls
when data is sent and when it is read.
I2C Bus operation:
• SDA line Transmits/Receives data bits (MSB is sent first)
• Data in SDA line is stable during clock (SCL) high
• Serial clock is driven by the master
• Acknowledgment bit is driven by the receiver after the end of reception
• If the receiver does not acknowledge, SDA line remains high

• The start bit is followed 7-bit slave address


• Address bit is followed by R/W bit
• If R/W=0, subsequent bytes transmitted on the bus will be written by the controller to the
selected peripheral
• If R/W=1, subsequent bytes will be sent by the selected peripheral and read by the
controller
I2C typical message format:
• For peripheral chip that contains more than one internal register or memory address, the
PIC will typically write a second byte to the chip to set a pointer to the selected internal
register or the consecutive addresses that follow it
I2C Advantages:
• It is faster than asynchronous serial communication
• Number of pins required for communication is less (only 2 pins)
• I2C supports multi master system
• I2C supports up to 128 slave devices
• I2C supports slave acknowledgment

**********

Connecting to the Cloud:


The Internet of Things (IoT) has revolutionized the way we interact with the world,
connecting a vast array of smart devices and enabling seamless communication and data
exchange. As the number of IoT devices continues to grow exponentially, managing and
harnessing the potential of this data becomes a significant challenge.
In this we going to send DHT22 humidity and temperature sensor readings to the cloud using
the Raspberry Pi. We will build a project and demonstrate two different methods for sending
sensor data to the cloud with a Raspberry Pi using the ThingSpeak cloud platform.
ThingSpeak is an IoT platform in the cloud that provides sensor data collection services,
transmission, processing, visualization, and analytics on the cloud by using API keys.
Furthermore, it provides these services in real-time, which means that users can operate their
services for monitoring and control applications in real-time. Potential application areas for
sensor monitoring and control with ThingSpeak include:

Air quality monitoring


Energy monitoring
Smart farming
Traffic monitoring
Weather station
Because of the cost-saving feature and reliability offered by such platforms, a number of big IoT
companies are opting to purchase the services offered by IoT providers such as ThingSpeak.
Instead of building their own IoT platforms, a move to cloud-based infrastructure offers
unparalleled benefits for companies, big or small.

THINGSPEAK AND SENSOR DATA


There are two methods for saving sensor readings in ThingSpeak—either in a public channel or a
private channel. A channel consists of eight fields for data storage, three fields for recording the
geophysical location, and a status field. To access these services, a user needs to be signed in.
Integration with MATLAB guarantees users access to rich visualization and sensor data analytics
tools. The platform accepts raw sensor data and users use equations and algorithms to transform
that data into a usable form. It is advantageous to perform any data processing on the cloud due
to a number of reasons:

Most IoT projects are battery-powered so processing data costs energy


Processing data may slow down the micro-controllers
Increase microcontroller sleep time
CONNECTING THE RASPBERRY PI TO THINGSPEAK
The Raspberry Pi needs an internet connection to connect to ThingSpeak. Here are some of the
ways to do this:
 Wired ethernet connection
 USB WiFi adapter
 ESP266 WiFi module
import sys
import Adafruit_DHT as dht
import urllib2

myAPI = 'IUKV2ZRBQW9MV407Q'
ThingsURL = 'https://api.thingspeak.com/update?api_key=%s' % myAPI

def DHT22_data():
humidity, temperature = dht.read_retry(dht.DHT22, 23)
return humi, temp

humidity, temp = DHT22_data()


if isinstance(humidity, float) and isinstance(temp, float):
humi = '%.2f' % humidity
temp = '%.2f' % temp

coms = urllib2.urlopen(ThingsURL + '&field1=%s&field2=%s' % (temp, humi))


print coms.read()
coms.close()
else:
print 'Error'

Connecting to thingspeak over ethernet :


The first method uses a wired ethernet connection. In this set-up, we use a LAN cable to connect
the Raspberry Pi to the internet. Then, we write a Python script that makes HTTP requests to
access and retrieve data from the internet. There are several libraries that we can use to open the
URLs. In this tutorial, we are going to use the urllib2 library to send the data to ThingSpeak.
Here is an example of sending sensor values to ThingSpeak.
Sending sensor data to thingspeak:
To send the sensor data to our ThingSpeak channel, firstly, we need to obtain the channel’s write
API key. Then we will need the sensor values to write. For this tutorial, we have two sensor
variables—temperature and humidity. So we need to have two fields: field1 and field2. Send this
information in a single URL using the following format:
https://api.thingspeak.com/update?api_key=drminls2dn88g1ez&field1=4&field2=4. The URL
description is shown in the diagram below:

Refer Manual Experiment 9 and 10 for procedure….

You might also like