MTech IoT Lab




Class:                         MTech 1st Sem
Stream:                      Computer Science and Engineering
Subject:                      IoT Lab
Subject Code:           18SCNL16 / 18SCSL16


What is IoT?

The Internet of Things is the concept of connecting any device (so long as it has an on/off switch) to the Internet and to other connected devices. The IoT is a giant network of connected things and people – all of which collect and share data about the way they are used and about the environment around them.
That includes an extraordinary number of objects of all shapes and sizes – from smart microwaves, which automatically cook your food for the right length of time, to self driving cars, whose complex sensors detect objects in their path, to wearable fitness devices that measure your heart rate and the number of steps you’ve taken that day, then use that information to suggest exercise plans tailored to you. There are even connected footballs that can track how far and fast they are thrown and record those statistics via an app for future training purposes.

How does it Work?

An IoT system consists of sensors/devices which “talk” to the cloud through some kind of connectivity. Once the data gets to the cloud, software processes it and then might decide to perform an action, such as sending an alert or automatically adjusting the sensors/devices without the need for the user.
But if the user input is needed or if the user simply wants to check in on the system, a user interface allows them to do so. Any adjustments or actions that the user makes are then sent in the opposite direction through the system: from the user interface, to the cloud, and back to the sensors/devices to make some kind of change.



Why do we need to study IoT?

The powerful IoT platforms can pinpoint exactly what information is useful and what can safely be ignored. This information can be used to detect patterns, make recommendations, and detect possible problems before they occur.
According to latest research, the number of IoT devices globally is believed to have reached 10 billion in 2018. Note that this is higher than the number of mobile devices in use in the world. With 5G on the horizon and an uptick in IoT adoption, companies’ plans to invest in IoT solutions seem to be accelerating.
The global IoT market is projected to nearly double in size between 2014 and 2017, passing the $1 trillion mark. By 2019, the global IoT market is forecast to be valued at more than $1.7 trillion. Consumer electronics is the largest component of the global IoT market.

Prerequisite for IoT Lab
  •     Brief understanding of IoT and its potential
  •     Arduino or Raspberry Pi or any other interactive electronic objects with sensors 
  •     In this lab we will be working with ESP8266 board
  •     Arduino IDE 
  •     Installation Guide: https://randomnerdtutorials.com/how-to-install-esp8266-board-arduino-ide/
  •    Programming language C/C++
  •    Enormous imagination and zeal to explore the horizons

ESP 8266 module

ESP8266 is a Wi-Fi module produced by Espressif. It can be used with most of the development board and micro-controller like Arduino. It is a popular module having a good price/performance ratio. ESP8266 contains a built-in 32-bit low-power CPU, ROM and RAM. It is a complete and self-contained Wi-Fi network solution that can carry software applications as a stand-alone device or connected with a microcontroller (MCU). The module has built-in AT Command firmware to be used with any MCU via COM port.



NodeMCU is an eLua based firmware for the ESP8266 WiFi SOC from Espressif. The firmware is based on the Espressif NON-OS SDK and uses a file system based on spiffs.

(Firmware is a software program or set of instructions programmed on a hardware device. It provides the necessary instructions for how the device communicates with the other computer hardware.

Firmware is typically stored in the flash ROM of a hardware device. While ROM is "read-only memory," flash ROM can be erased and rewritten because it is actually a type of flash memory.)

SPIFFS : SPI Flash file Systems

SPI: Serial Peripheral Interface (SPI) is an interface bus commonly used to send data between microcontrollers and small peripherals such as shift registers, sensors, and SD cards. It uses separate clock and data lines, along with a select line to choose the device you wish to talk to.

Interface: In computing, an interface is a shared boundary across which two or more separate components of a computer system exchange information. The exchange can be between software, computer hardware, peripheral devices, humans, and combinations of these.[1] Some computer hardware devices, such as a touchscreen, can both send and receive data through the interface, while others such as a mouse or microphone may only provide an interface to send data to a given system.

A peripheral or peripheral device is "an input or output device used to put information into and get information out of the computer".

Baud Rate: 


The baud rate specifies how fast data is sent over a serial line. It's usually expressed in units of bits-per-second (bps). If you invert the baud rate, you can find out just how long it takes to transmit a single bit. This value determines how long the transmitter holds a serial line high/low or at what period the receiving device samples its line.
Baud rates can be just about any value within reason. The only requirement is that both devices operate at the same rate. One of the more common baud rates, especially for simple stuff where speed isn't critical, is 9600 bps. Other "standard" baud are 1200, 2400, 4800, 19200, 38400, 57600, and 115200. The higher a baud rate goes, the faster data is sent/received, but there are limits to how fast data can be transferred. You usually won't see speeds exceeding 115200 - that's fast for most microcontrollers. Get too high, and you'll begin to see errors on the receiving end, as clocks and sampling periods just can't keep up.

Baud rates are like the languages of serial communication. If two devices aren't speaking at the same speed, data can be either misinterpreted, or completely missed. If all the receiving device sees on its receive line is garbage, check to make sure the baud rates match up.

Experiment No 1: Transmit a String Using UART

What is UART?

UART stands for Universal Asynchronous Receiver/Transmitter. It’s not a communication protocol like SPI and I2C, but a physical circuit in a microcontroller, or a stand-alone IC. A UART’s main purpose is to transmit and receive serial data.

In UART communication, two UARTs communicate directly with each other. The transmitting UART converts parallel data from a controlling device like a CPU into serial form, transmits it in serial to the receiving UART, which then converts the serial data back into parallel data for the receiving device. Only two wires are needed to transmit data between two UARTs. Data flows from the Tx pin of the transmitting UART to the Rx pin of the receiving UART:



In this experiment we will learn to transfer the data to controller (ESP 8266) through UART communication i.e the entered data will be transferred from the host and converted to HEX, DECIMAL and CHARACTER. We can see the output in Serial Monitor at the specified COM port. The below source code will also be able to control the Builtin LED through the input we provide for better understanding of the experiment. 

Source Code


/* SerialMonitor_SEND_RCVE<br> - WHAT IT DOES:
- Receives characters from Serial Monitor
- Displays received character as Decimal, Hexadecimal and Character
- Controls LED from Keyboard
- SEE the comments after "//" on each line below
/*-----( Import needed libraries )-----*/
/*-----( Declare Constants and Pin Numbers )-----*/
/*-----( Declare objects )-----*/
/*-----( Declare Variables )-----*/
int ByteReceived;
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
Serial.println("--- Start Serial Monitor SEND_RECV ---");
Serial.println(" Type in Box above, . ");
Serial.println("(Decimal)(Hex)(Character)");
Serial.println();
}
//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
while (Serial.available() > 0)
{
ByteReceived = Serial.read();
Serial.print(ByteReceived);
Serial.print(" ");
Serial.print(ByteReceived, HEX);
Serial.print(" ");
Serial.print(char(ByteReceived));
if(ByteReceived == '1') // Single Quote! This is a character.
{
digitalWrite(LED_BUILTIN, LOW);
Serial.print(" LED ON ");
}
if(ByteReceived == '0')
{
digitalWrite(LED_BUILTIN,HIGH);
Serial.print(" LED OFF");
}
Serial.println(); // End the line
}
// END Serial Available
}
//--(end main loop )---
/*-----( Declare User-written Functions )-----*/
/*********( THE END )***********/
view raw SerialUart hosted with ❤ by GitHub


Experiment 2: Point-to-Point communication of two Motes over the radio frequency.

In telecommunications, a point-to-point connection refers to a communication connection between two communication endpoints or nodes. An example is a telephone call, in which one telephone is connected with one other, and what is said by one caller can only be heard by the other. Think of a wire that directly connects two systems. The systems use that wire exclusively to communicate. The opposite of point-to-point communications is broadcasting, where one system transmits to many.

In this experiment we will be able to establish a communication between the host and a controller (ESP8266).  We will utilize the Wi Fi module of the controller and will be able to fetch the static IP address of the Wi-Fi module of ESP 8266.

Source Code


#include <ESP8266WiFi.h> //Required header
// Replace these with your WiFi network settings
const char* hotspot = "hotspot_name"; //replace this with your WiFi network name
const char* password = "password"; //replace this with your WiFi network password
void setup()
{
delay(1000);
Serial.begin(115200); //set the Baud rate to 115200
WiFi.begin(hotspot, password); //command ro begins the Wi-Fi connection to ESP8266 board
Serial.println();
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) //If connection is not yet established
{
delay(500); //wait in loop till the connection gets established
Serial.print(".");
}
Serial.println("success!"); //Once the connection is established following lines of code will be executed
Serial.print("IP Address is: ");
Serial.println(WiFi.localIP()); //Get the IP address of the device
}
void loop()
{
}
Experiment 3: Multi-point to single point communication of Motes over the radio frequency.LAN (Subnetting).

A communication that is accomplished via a distinct type of one-to-many connection, providing multiple paths from a single location to multiple locations is termed as Point to Multipoint (PMP)

The point-to-multipoint topology consists of a central base station that supports several subscriber stations. These offer network access from a single location to multiple locations, permitting them to use the same network resources between them. The bridge located at the central location is known as the base station bridge or root bridge. All data that passes between the wireless bridge clients should initially go via the root bridge.
In this experiment we will be able to establish a communication between the host and a controller (ESP8266).  We will utilize the Wi Fi module of the controller and will be able to fetch the static IP address of the Wi-Fi module of ESP 8266. A HTTP page is made available via the IP address provided by ESP8266 by which more than one nodes(smart devices) can communicate to the host and change the state of the LED


Source Code


#include <ESP8266WiFi.h> //Define the WiFi header
const char* ssid = "user_name";//type your ssid -
// | -> Wi Fi Setup Parameters
const char* password = "password";//type your password -
WiFiServer server(80); //Initialize WiFi Server
void setup()
{
Serial.begin(115200); //Set Baud rate
delay(10);
pinMode(LED_BUILTIN, OUTPUT); //Initialize LED
digitalWrite(LED_BUILTIN, LOW); //Initial state of LED is ON
/*---------------------------------------------- Connect to WiFi network--------------------------------------------------------------------*/
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password); //Command to connect the device to Wi Fi
while (WiFi.status() != WL_CONNECTED) //Wait in loop until the device is connected to WiFi network
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
/*-----------------------------------------------Start the server----------------------------------------------------------------------------*/
server.begin();
Serial.println("Server started");
/*--------------------------------------------- Print the Local IP address------------------------------------------------------------------------*/
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop()
{
int value = LOW; //Assign a variable to hold the state of LED
/*----------------------------------------------Check if a client has connected-----------------------------------------------------------------*/
WiFiClient client = server.available();
if (!client)
{
return;
}
Serial.println("new client"); // Message to display when client is connected
while(!client.available())
{
delay(1);
}
String request = client.readStringUntil('\r'); //Read the data sent by client into a string variable
Serial.println(request);
client.flush();
/*--------------------------------------Creating a Client Interacting page (HTML) in localhost---------------------------------------------------------*/
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("LED pin is now: ");
client.println("<br><br>");
client.println("Click <a href=\"/LED=ON\">here</a> turn the LED on pin 2 ON<br>");
client.println("Click <a href=\"/LED=OFF\">here</a> turn the LED on pin 2 OFF<br>");
client.println("</html>");
/*-------------------------------------END of creating a Client Interacting page (HTML) in localhost------------------------------------------------------*/
/*-------------------------------------Client Request to turn ON the LED----------------------------------------------------------------------------------*/
if (request.indexOf("/LED=ON") != -1) //Request will be in the form of |GET|/LED=ON|
{ //INDEX: 0 1
digitalWrite(LED_BUILTIN, LOW);
value = HIGH; //Set the variable 'value' to HIGH
}
/*-----------------------------------Client Request to turn OFF the LED----------------------------------------------------------------------------------*/
if (request.indexOf("/LED=OFF") != -1) //Request received will be in the form of |GET|/LED=OFF|
{ //INDEX: 0 1
digitalWrite(LED_BUILTIN, HIGH);
value = LOW; //Set the variable 'value' to LOW
}
if(value == HIGH)
{
client.print("On");
} else {
client.print("Off");
}
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}

Comments

  1. Set aside my effort to peruse all the remarks, however I truly delighted in the article. It's consistently pleasant when you can not exclusively be educated, yet in addition, engaged!
    360DigiTMG iot classes

    ReplyDelete
  2. Through this post, I realize that your great information in playing with all the pieces was exceptionally useful. I advise this is the primary spot where I discover issues I've been scanning for. You have a smart yet alluring method of composing.
    https://360digitmg.com/course/certification-program-in-iot

    ReplyDelete
  3. This post is very simple to read and appreciate without leaving any details out. Great work!
    data science courses in chennai

    ReplyDelete
  4. Really Nice Information It's Very Helpful All courses Checkout Here.
    Data Science Course Online

    ReplyDelete

Post a Comment

Popular posts from this blog

IoT Lab on Saturday, 07/12/2019 at 9:00AM