# IoT Final Note
## CH1- Introduction to IoT
### Block Diagram of IoT Device
* consisted of interfaces for connections to other devices --> **wired/ wireless**

### Protocols
* From bottom to top

* Link layer: 802.3(ethernet)、802.11(wifi)......
* network/Internet Layer: IPv4, IPv6......
* Transport Layer: TCP、UDP
* Application Layer: HTTP、WebSocket、MQTT......
### **Models**
#### Request-Response communicatin model
* client: sends requests to server
* server: respose to the requests
* how to response?
* fetches data...?
* retrieved resource representations
* prepare response
* send back

#### Publish-Subscribe communication model
* publisher: **source of data**
- send data to the topics managed by **broker**
- Not aware of consumers
* Consumer: subscribe to topics
* After broker received data from publisher--> send data to all the **subscribed consumers**

#### Push-Pull communication model
* data producer: push data to queue
* Not aware of consumers
* consumers: pull the data from the queue
* Queues: help decoupling the messages
* Queues: Buffer in situation --> mismatched pull/ push rate

#### Exclusive Pair communication model
* bidirectional, fully duplex (雙向)
* **persistent connection** --> communication remains open till client sends close request

### **API**
#### REST-based Communication APIs
* REST: Representational State Transfer
* design web services and web APIs
* focus on a system’s resources
* how resource states are addressed and transferred
* model: request-response communication model

#### WebSocket-based Communication APIs
* bidirectional, full duplex communication
* model: exclusive pair communication model

### IoT Components
* Device
* Resource: software components **on the IoT device**
* function:
a. accessing, processing, and storing sensor information
b. controlling actuators
c. enable network access for the device
* Controller Service: native service
* runs on the device
* interacts with the web services
* function:
* sends data: device ---> web service
* receives commands <---(via: web services)--- application
* Database: local/ cloud
* Web Service: link between the **IoT device**, **application**, **database**, **analysis components**
* Implemented methods:
* HTTP and REST principles (**REST service**)
* WebSocket protocol (**WebSocket service**)
* Analysis Component
* Application:
* interface for users to control and monitor
* view the system status
* view the processed data
### IoT Level
#### Level 1
* single node/device
* sensing/ actuation
* stores data
* analysis
* hosts application
* lowcost, low-complexity solutions

#### Level 2
* single node
* sensing/ actuation
* local analysis
<font color = red>
* Data/ application
* cloud
</font>
* big data involved, analysis not computationally intensive

#### Level 3
* single node
* sensing/ actuation
* Data/ application/ <font color=red>analysis
</font>
* cloud
* big data involved, analysis <font color=red>computationally intensive</font>

#### Level 4
* <font color = red>multiple</font> node
* sensing/ actuation
* local analysis
* <font color = red>local/ cloudbased observer nodes</font>
* subscribe to/ receive information
* Data/ application
* cloud
* multiple nodes required, big data involved, computationally intensive analysis

#### Level 5
* <font color = red>multiple end nodes and one coordinator node</font>
* end node: sensing/ actuation
* <font color = red>coordinator node: collects data from end, sends to the cloud</font>
* Data/ application/ analysis
* cloud
* solutions based on <font color = red>wireless sensor networks</font>, big data involved, computationally intensive analysis

#### Level 6
* multiple independent end nodes
<font color = red>
* sensing/ actuation
* send data to the cloud
</font>
* Data/ application/ analysis
* cloud
<font color = red>
* centralized controller
* aware of the status of all the end nodes
* sends control commands to the nodes
</font>

### Comparision between Levels

## CH3- IoT vs. M2M
### M2M Intro.
* Machine-to-Machine
* networking of machines (devices)
* remote monitoring, control, data exchange
* Machine:
* embedded hardware modules
* sensing, actuation and communication
* Communication:
* protocols:
* ZigBee
* Bluetooh
* ModBus
* M-Bus
* Wirless M-Bus
* Power Line Communication (PLC)
* 6LoWPAN
* IEEE 802.15.4
* ......
* network: **wire/ wireless networks(IP)**
* M2M area networks: proprietary or non-IP based communication protocols
* Unable to communicate with nodes in an external network ---> use **gateways**

### Difference
|Comparison|IoT|M2M|
|-|-|-|
|Emphasis|software|hardware with embedded modules|
|Data Collection & Analysis|cloud (public, private or hybrid)|point solutions& on-premises storage infrastructure|
|Applications|collected in the cloud& accessed by cloud applications|collected in point solutions& accessed by on-premises applications|

### SDN
* Software-Defined Networking
* separates control plane from data plane
* maintain a unified view of the network
* make configuration, management, provisioning simpler
* use simple packet forwarding hardware

* Components
* Centralized Network Controller
* Programmable Open APIs
* **Northbound interface**: interface between the SDN application and control layers
* Standard Communication Interface<font color=red> (OpenFlow)</font>
* **Southbound interface**: interface between the control and infrastructure layers
### NFV
* Network Function Virtualization
* leverages <font color=blue>virtualization</font> to consolidate the heterogeneous network devices
* **complementary to SDN** ---> infra. to run
* Elements:
* **VNF** (Virtualized Network Function):
* software implementation of a network function
* **NFVI** (NFV Infrastructure):
* virtualize compute, network and storage resources
* Management and Orchestration:
* Use case: virtualize Home Gateway
* private IP addresses to the devices in the home
* connects to network services: VoIP, IPTV

## CH4- IoT System Management with NETCONF-YANG
### SNMP (Simple Network Management Protocol)
- protocol allowing monitoring and configuring network devices
- components:
- NMS (Network Management Station)
- Managed Device
- MIB (Management Information Base)
- SNMP Agent

- stateless& the SNMP request contains all the info. ---> **application needs to be intelligent**
- connectionless protocol (UDP) ---> **unreliable**
- MIBs lack writable objects ---> device configuration is impossible
- difficulty retrieving current configuration
- lack strong security features
### NETCONF (Network Configuration Protocol)
- session-based network management protocol
- retrieving state/ configuration data
- manipulating configuration data

- SSH transport protocol
- transport layer ---> end-to-end connectivity, reliable delivery
- XML-encoded Remote Procedure Calls (PRCs) ---> framing request and response messages
- RPC layer ---> mechanism for encoding of RPC calls and notifications
- Content Layer ---> configuration and state data (XML-encoded)
- **```YANG```** ---> data modeling language
### YANG
- usage: model configuration and state data
- contains:
- definitions of configuration data
- state data
- RPC calls that can be issued
- format of the notifications
- defines the data between the NETCONF client and server
- hierarchical tree structure

## CH5- IoT Design Methodology

## CH8- IoT Physical Servers & Cloud Offerings
### WAMP (Web Application Messaging Protocol)
- sub-protocol of Websocket
- publish-subscribe model
- Publisher: publishes events to topic maintained by the Broker
- Subscriber: subscribes to topics, receives the events
- remote procedure call (RPC)
- Caller: issues calls to the remote procedures
- Callee: executes the procedures which calls are issued by the caller and returns the results back to the caller
- Router: perform generic call and event routing
- PS-mode: Broker: routes messages published to a topic to all subscribers
- RPC-mode: Dealer: routes RPC calls from the Caller to the Callee and routes results from Callee to Caller

## CH10- Data Analytics for IoT
### Hadoop Ecosystem
- open source framework for distributed batch processing of big data
## Lab1
### OS Installation
- Download Raspbian
- Flash .img file into SD card
- **SSH**
- add new raw file ```ssh``` into the ```boot``` disk
- ssh command ```ssh pi@raspberrypi.local```
- default password: raspberry
- VNC
- ```raspi-config```
- Adjust ```VNC```, ```Resolution```
- Reboot
- Trouble shoot
- reinstall: delete ```known_hosts``` file or line related to ```raspberrypi.local```
## Lab2
### Request
- pip install request
- ```response = request.get(url, params={‘key’ : ‘data’}, headers={‘key’ :‘data’}```
- HTTP status code:
- Informational responses (100–199)
- Successful responses (200–299)
- Redirects (300–399)
- Client errors (400–499)
- Server errors (500–599)
- response.json(): get the message in ```json``` format