1. Explaining the importance of platform based development
2. Understanding The importance of NodeMCU and demonstrate its interfacing with various devices and sensors.
Size: 4.14 MB
Language: en
Added: May 30, 2020
Slides: 49 pages
Slide Content
Presented By Amarjeetsingh Thakur NODEMCU 1
Introduction to IoT Introduction to ESP8266 What is N odeMCU What you can do with it ? NodeMCU development board Pin Description ESP8266 Block diagram Connecting different devices with ESP8266 Introduction to things board IoT platform 2
3
4
We will now have connectivity for anything. From any time, any place connectivity for anyone !!! 5
Various Names, One Concept For over a decade after the introduction of the term Internet-of-Things, different organizations and working groups have been providing various definitions. M2M (Machine to Machine) “Internet of Everything” (Cisco Systems) “World Size Web” (Bruce Schneier) “Skynet” (Terminator movie) Cloud of Things Web of Things 6
7
What is NodeMCU ? The NodeMCU (Node MicroController Unit) is an open source software and hardware development environment that is built around a very inexpensive System-on-a-Chip ( SoC ) called the ESP8266. An Arduino -like device Main component: ESP8266 With programmable pins And built-in wifi Power via USB Low cost 8
What you can do with it ? Program it via C or LUA Access it via wifi (ex. HTTP ) Connect pins to any device ( in or out) 9
Main Component 10
Pin Description 11
Figure : ESP8266EX Block Diagram 12
13
14
The Arduino software consists of a development environment (IDE) and the core libraries. The IDE is written in Java and based on the processing environment. The core libraries are written in C and C++ and compiled using avr -gcc compiler. 15
16
Program Structure Setup( ) { // A function that runs once at the start of a program and is used to set // pinMode or initialize serial communication } loop( ) { // This function includes the code to be executed continuously – reading inputs, //triggering outputs, etc. // This function is the core of all Arduino programs and does the bulk of the //work. } 17
BREAD BOARD 18
19
20
Activity 1.1 Type : Team of 2 Duration : 20 Minutes Single LED blink program using web . Anode of LED Cathode of LED 21
pinMode ( ledPin , OUTPUT); digitalWrite ( ledPin , LOW); // Connect to WiFi network Serial.println (); Serial.println (); WiFi.mode (WIFI_AP); /* You can remove the password parameter if you want the AP to be open. */ Serial.print ("Connecting to "); Serial.println ( ssid ); 23
// Print the IP address Serial.print ("Use this URL to connect: "); Serial.print ("http://"); Serial.print ( WiFi.localIP ()); Serial.println ("/"); } 25
void loop() { // Check if a client has connected WiFiClient client = server.available (); if (!client) { return; } // Wait until the client sends some data Serial.println ("new client"); while (! client.available ()) { delay(1); } 26
// Read the first line of the request String request = client.readStringUntil ('\r'); Serial.println (request); client.flush (); // Match the request int value = LOW; if ( request.indexOf ("/LED=ON") != -1) { digitalWrite ( ledPin , HIGH); value = HIGH; } if ( request.indexOf ("/LED=OFF") != -1) { digitalWrite ( ledPin , LOW); value = LOW; } 27
// Return the response 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: "); if (value == HIGH) { client.print ("On"); } else { client.print ("Off"); } client.println ("< br >< br >"); client.println ("<a href =\"/LED=ON\"\"><button>Turn On </button></a>"); client.println ("<a href =\"/LED=OFF\"\"><button>Turn Off </button></a>< br />"); client.println ("</html>"); 28
// Connect to WiFi network Serial.println (); Serial.println (); WiFi.mode (WIFI_AP); /* You can remove the password parameter if you want the AP to be open. */ Serial.print ("Connecting to "); Serial.println ( ssid ); WiFi.begin ( ssid , password); while ( WiFi.status () != WL_CONNECTED) { delay(500); Serial.print ("."); } Serial.println (""); Serial.println (" WiFi connected"); // Start the server server.begin (); Serial.println ("Server started"); 33
// Print the IP address Serial.print ("Use this URL to connect: "); Serial.print ("http://"); Serial.print ( WiFi.localIP ()); Serial.println ("/"); } void loop() { // Check if a client has connected WiFiClient client = server.available (); 34
if (!client) { return; } // Wait until the client sends some data Serial.println ("new client"); while (! client.available ()) { delay(1); } // Read the first line of the request String request = client.readStringUntil ('\r'); Serial.println (request); client.flush (); 35
// Match the request int value = LOW; if ( request.indexOf ("/LED=ON") != -1) { digitalWrite ( ledPin , HIGH); value = HIGH; } if ( request.indexOf ("/LED=OFF") != -1) { digitalWrite ( ledPin , LOW); value = LOW; } if ( request.indexOf ("/LED1=ON") != -1) { digitalWrite (ledPin1, HIGH); value = HIGH; } if ( request.indexOf ("/LED1=OFF") != -1) { digitalWrite (ledPin1, LOW); value = LOW; } 36
// Return the response 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: "); if (value == HIGH) { client.print ("On"); } else { client.print ("Off"); } 37
Serial communication What is serial communication ? 39
The word serial means "one after the other." What is Baud rate ? Number of symbols transferred per sec 40
Serial Display Functions Serial.begin ( baud_rate ) //baud rate(characters per sec) between computer and board is typically 9600 although you can work with other speeds by changing settings of COM Port Serial.print (value), //value could be any data and even string Serial.println (value) //print in new line 41
Eg. Print INDIA on serial monitor void setup( ) { Serial.begin (9600); // 9600 is default baud rate of serial com port of a computer } void loop( ) { Serial.println (“INDIA”); // Send the value “INDIA” } 42
Serial Monitor 43
Activity 1.3 Type : Team of 2 Duration : 20 Minutes Wi-Fi Network Scanning by NodeMCU 44
#include <ESP8266WiFi.h> void setup() { Serial.begin (115200); // Set WiFi to station mode WiFi.mode (WIFI_STA); WiFi.disconnect (); delay(100); Serial.println ("Setup done"); } void loop() { Serial.println ("scan start"); int n = WiFi.scanNetworks (); // WiFi.scanNetworks will return the number of networksfound Serial.println ("scan done"); 45
if (n == 0) Serial.println ("no networks found"); else { Serial.print (n); Serial.println (" networks found"); for ( int i = 0; i < n; ++i) { // Print SSID and RSSI for each network found Serial.print (i + 1); Serial.print (": "); Serial.print ( WiFi.SSID (i)); Serial.print (" ("); Serial.print ( WiFi.RSSI (i)); Serial.print (")"); Serial.println (( WiFi.encryptionType (i) == ENC_TYPE_NONE) ? " " : "*"); delay(10); } 46
} Serial.println (""); delay(5000); } 47
Learning Outcomes At the end of the workshop the student should be able to Explain the importance of platform based development Understand The importance of NodeMCU and demonstrate its interfacing with various devices and sensors. 48
For more information contact: [email protected] linkedin.com/in/amarjeetsingh-thakur-54915955 49