Unit 4-1
Unit 4-1
& Applications
CE0622
▪ Network Layer: The network layer is a transmission layer that transfers the
information from physical objects or sensors to the processing system over
secure lines using a communication system. (IoT Gateway)
○ Advanced gateways which mainly opens up connection between Sensor networks and Internet also
performs many basic gateway functionalities like malware protection, and filtering also sometimes
decision making based on inputted data and data management services, etc.
IoT Architecture
▪ Middleware Layer: The middleware layer obtains data from the network
layer, links the system to the cloud and database, and performs data processing
and storage.
Arduino platform
Input Voltage
7-12V 32 KB (ATmega328P) of which
(recommended) Flash Memory
0.5 KB used by bootloader
Input Voltage (limit) 6-20V
SRAM 2 KB (ATmega328P)
14 (of which 6 provide PWM
Digital I/O Pins
output) EEPROM 1 KB (ATmega328P)
▪ Download from:
http://arduino.cc/en/Main/Software
Concept: Input v/s Output 12
Input Output
Inputs is a signal / information going in Output is signal going out from the
to the board board
Examples: Examples:
Analog Digital
Analog signals are signals that can Microcontroller is digital device can
have full range, have values ON or OFF
Example: Example:
Code comparison
#define __SFR_OFFSET 0x20
#include "avr/io.h"
.global start
.global forever const int LED_Pin = 8;
#define F_CPU 16000000UL
start: #include <avr/io.h> void setup()
LDI R16, 0x01 ; Setting 1st bit of PORTB as output
STS DDRB, R16 #include <util/delay.h> {
LDI R17, 0x00
STS PORTB, R17 ; Writing 0 to PORTB int main(void)
pinMode(LED_Pin, OUTPUT);
LDI R16, 0x00
STS TCCR1A, R16 ; Setting all bits of TCCR1A as 0
{ }
RET DDRB |= (1<<DDB1);
while (1)
forever: { void loop()
LDI R16, 0xC2
STS TCNT1H, R16 ; Writing 0xC2 into TCNT1H (8-bit)
PORTB |= (1<<PORTB1); {
_delay_ms(1000);
LDI R16, 0xF7
STS TCNT1L, R16 ; Writing 0xF7 into TCNT1H (8-bit) PORTB &= ~ (1<<PORTB1);
digitalWrite(LED_Pin, LOW);
LDI R16, 0x05 _delay_ms(1000); delay(1000);
STS TCCR1B, R16 ; Writing 0x05 into TCCR1B
L:LDS R0, TIFR1 ; Load the value of TIFR1 into R0
}
} digitalWrite(LED_Pin, HIGH);
SBRS R0, 0 ; Skip the next statement if overflow has occured.
RJMP L ; Loop until overflow occurs. delay(1000);
LDI R16, 0x00
STS TCCR1B, R16 ; Stop the Timer/Counter1
}
LDI R16, 0x01
STS TIFR1, R16 ; Clear the overflow flag by writing 1 to it
COM R17 ; Complement R17 register
STS PORTB, R17 ; Toggle the LED output
RET
void setup() 15
▪ Reads the value from the specified analog pin. Arduino boards contain
a multichannel, 10-bit analog to digital converter.
▪ Syntax:
▪ analogRead(pin)
▪ Parameters
▪ pin: the name of the analog input pin to read from
▪ Returns
▪ The analog reading on the pin (int). Although it is limited to the resolution of
the analog to digital converter
analogRead() 23
delay() 24
▪ Pauses the program for the amount of time (in milliseconds) specified
as parameter. (There are 1000 milliseconds in a second.)
▪ Syntax:
▪ delay(ms)
▪ Parameters
▪ ms: the number of milliseconds to pause (unsigned long)
▪ Returns
▪ Nothing
delay() 25
Other delay functions 26
▪ Sets the data rate in bits per second (baud) for serial data
transmission. For communicating with the computer, use one of these
rates: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800,
38400, 57600, or 115200.
▪ Syntax:
▪ Serial.begin(speed , config)
▪ Parameters
▪ speed: in bits per second (baud) - long
config: sets data, parity, and stop bits
▪ Returns
▪ Nothing
Serial.begin() 28
Serial.read() 29
▪ Writes binary data to the serial port. This data is sent as a byte or
series of bytes; to send the characters representing the digits of a
number use the print() function instead.
▪ Syntax:
▪ Serial.write(val)
▪ Parameters
▪ None
▪ Returns
▪ the first byte of incoming serial data available (or -1 if no data is available)
Serial.write() 32
Serial.print() and prinln() 33
▪ ISR:
▪ It is a function that is called when an external interrupt is done.
▪ You can also use operators like == and != to check if string equals
to or not equals to
▪ Returns: true (1) or false (0)
▪ Returns: Integer
remove()
▪ myString.remove(index): Remove charaters of a String from index to
end
▪ Returns: Nothing
ESP8266 - Node MCU
Low Cost Alternative for IoT
ESPRESSIF Modules
▪ ESP8266 WiFi Module is a self contained SOC with integrated
TCP/IP protocol stack.
▪ ESP8266 is capable of either hosting an application or offloading all
WiFi networking functions from another application processor.
▪ ESP8266 comes packed with a powerful controller; no external
controller interfacing is required.
▪ ESPRESSIF provides various version of ESP modules of which
ESP12 module is very popular.
▪ Low cost chip with small PCB area and power efficiency.
Key Features of ESP8266
▪ CPU
▪ Tensilica L106 32-bit MCU
▪ Clock: 80MHz (max. 160MHz)
▪ 4MB Flash Memory
▪ 96KB data RAM; available to user less than 45KB
▪ RTOS Enabled (Supports FreeRTOS)
▪ WiFi
▪ Supports 802.11b/g/n protocol
▪ Access Point or Station
▪ WEP
▪ GPIO, UART, ADC, I2C, SPI, PWM
Different version of ESP8266
Advantages of ESP8266
▪ Integrated TCP/IP protocol stack
▪ Integrated low power 32-bit CPU could be used as application processor
▪ Wake up and transmit packets in < 2ms
▪ Standby power consumption of < 1.0mW
▪ Operates at a low voltage range: 1.8 to 3.6 V
▪ Supports three different power save modes:
1. Modem sleep: WiFi modem is shut off; CPU works; Maintains WiFi connection
without data transmission
2. Light sleep: Suspended CPU; WiFi modem turned off
3. Deep sleep: Does not maintain WiFi connection; long time lags between data
transmission
NodeMCU Pin Diagram
Software Development Using Arduino IDE
▪ As soon as the pulses are transmitted, the ECHO pin goes HIGH,
and stays HIGH till all the reflected pulses are received. The module
times out after 38ms, if all the reflected pulses are not received in this
duration.
Timing Diagram
Wi-Fi Modes
▪ Devices that connect to Wi-Fi network are called stations (STA).
Connection to Wi-Fi is provided by an access point (AP), which acts
as a hub for one or more stations.
Node MCU as an access point
▪ ESP8266 module can operate as a station, so we can connect it to
the Wi-Fi network. It can also operate as a soft access point (softAP),
to establish its own Wi-Fi network.
▪ Therefore we can connect other stations to such ESP module.
ESP8266 is also able to operate both in station and soft access point
mode.
Node MCU as an access point
▪ Password Protected Network
▪ WiFi.softAP(ssid, password); //With Password
▪ Open Network
▪ WiFi.softAP(ssid); //No password
Node MCU as an access point
Connecting NodeMCU to Access Point
▪ The Wi-Fi network is identified with the SSID and Password. Network
may be protected with a password.
▪ Connect to Password Protected Network
▪ WiFi.begin(ssid, password); //With Password
▪ Connect to Open Network
▪ WiFi.begin(ssid); //No password
Connecting NodeMCU to Access Point
Connecting NodeMCU to Access Point
Wi-Fi Network Scan
▪ ESP8266 NodeMCU Wi-Fi Scanner allows you to easily locate visible
wireless networks and its corresponding information.
▪ This way you can refer to all functions in the module using the shorter
name "GPIO".
▪ RPi.GPIO supports referring to GPIO pins using either the physical pin
numbers on the GPIO connector or using the BCM channel names from
the Broadcom SOC that the pins are connected to.
GPIO.setmode(GPIO.BOARD) GPIO.setmode(GPIO.BCM)
● GPIO BOARD– This type of pin ● GPIO BCM– The BCM option
numbering refers to the number refers to the pin by “Broadcom
of the pin in the plug. SOC Channel. They signify the
Broadcom SOC channel
● The advantage of this type of designation.
numbering is, it will not change
even though the version of board ● The BCM channel changes as the
changes. version number changes.
GPIO.setup()
▪ GPIO.setup(channel, GPIO.IN)
▪ GPIO.setup(channel, GPIO.OUT)
▪ GPIO.input(channel)
▪ Where channel is the channel number as used in setup. It will return a
value of 0, or False (all are equivalent) if it is low and 1, or True if it was at
a high level.
▪ GPIO.output(channel, state)
▪ where channel is the channel number and state is the desired output level:
GPIO.LOW for a low value or GPIO.HIGH for a high level.
▪ GPIO.cleanup()
▪ When you are done with the library, it is good practice to free up any
resources used and return all channels back to the safe default of being
inputs.
Example
import RPi.GPIO as GPIO
import time
led = 18
switch = 31
GPIO.setmode(GPIO.BOARD)
GPIO.setup(led, GPIO.OUT)
GPIO.setup(switch, GPIO.IN)
for i in range(10):
GPIO.output(led, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(led, GPIO.LOW)
time.sleep(0.2)
print('Switch status = ', GPIO.input(switch))
GPIO.cleanup()
WHAT IS CLOUD COMPUTING?
● On-demand network access (Using the Internet for communication and transport provides
hardware, software and networking services) Provisioned by the Service Provider
BASIC CLOUD CHARACTERISTICS
▪ Cloud are transparent to users and applications, they can be built in multiple
ways branded products, proprietary open source, hardware or software, or just
off-the-shelf PCs.
▪ In general, they are built on clusters of PC servers and off-the-shelf
components plus Open Source software combined with in-house applications
and/or system software.
▪ Clients can:
▪ Put their data on the platform instead of on their own desktop PCs and/or on
their own servers.
▪ They can put their applications on the cloud and use the servers within the
cloud to do processing and data manipulations etc.
Convergence Approaches of IoT and Cloud
Cloud-centric IoT
● Bring IoT data in the cloud
● Processing and computing the data and deploy management tools in cloud
● This approach this good if service are provided among objects located in multiple
location
CLOUD-CENTRIC IOT PLATFORM
IOT-CENTRIC CLOUD COMPUTING