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

MicroPythonWebinar - IOT

This document provides an overview of using Micropython for Internet of Things applications on ESP32 devices. It defines IoT as interconnected devices that generate and exchange data. It discusses what constitutes a "thing" in IoT and how things can produce and transmit data using sensors, microcontrollers and Python. It also covers HTTP communications, sockets, web servers and demonstrations of IoT applications using the ESP32.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
160 views

MicroPythonWebinar - IOT

This document provides an overview of using Micropython for Internet of Things applications on ESP32 devices. It defines IoT as interconnected devices that generate and exchange data. It discusses what constitutes a "thing" in IoT and how things can produce and transmit data using sensors, microcontrollers and Python. It also covers HTTP communications, sockets, web servers and demonstrations of IoT applications using the ESP32.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Internet of Things

Using
Micropython
Outline:
• What is IOT
• The “thing” in IOT
• HTTP Communications
• Sockets
• Webservers
• HTTP in ESP32
• Demos:IOT applications in ESP32
RECAP from Session 1 and 2

What is Micropython?
What are sensors?
What is Micropython?

Micropython is:
• A complete reimplementation of Python
• Designed to be efficient with resources
• Compact enough to fit and run within 256k of code space
and 16k of RAM
• Allows faster iterations
• Optimises developer time
• Worry more about the solution, less about the
implementation
ESP2 modules:
Sound,temperature
, pressure,light, Sensors
vibration,humidity,
position
Lets Start
WebServers
The Internet

192.168.10.3
64.233. 160.0

192.168.10.4

60.233. 160.1
Clients

192.168.10.10
The Internet of Things WebServers
192.168.10.15
192.168.10.10

Things as
Clients
64.233. 160.0

192.168.10.3

60.233. 160.1

192.168.10.4
Internet of Things
The Internet of things is a
system of interrelated computing
devices, mechanical and
digital machines provided
with unique identifiers and
the ability to transfer data over a
network without requiring human-
to-human or human-to-computer
interaction. Wikipedia
How does data move in the Internet
WebServers

HTTP Packets

HTTP Packets
Clients
HTTP Packets
Why IOT

The essence of the IOT is simply interconnected devices


that generate and exchange data from observations,
facts, and other data making it available to anyone.

IOT solutions are designed to make our knowledge of


the world around us more timely and relevant by
making it possible to get data about anything from
anywhere at any time
What is IOT and What its Not
• If a device is connected to the Internet, does that make it an IOT solution?
• the answer is not unless there is some benefit from doing so
• For example, if you connected your toaster to the Internet, what could be
the benefit of doing so?
• would be pointless (or at least extremely eccentric) to get a text on your
phone from your toaster stating that your toast is ready. So, in this case,
the answer is no.
• if there is no use for the data, whether it is something that is viewed in
realtime or is stored for later processing, then simply connecting it to the
Internet does not make it an IOT solution.
• There must be some gain in the use of the device
IOT driver of Smart Cities
Internet Refridgerator.is it beneficial?

VS
Glocuse monitoring system.is it beneficial?
Fleet Management System
Diagnostic System
The Thing in IOT
• Must be similar to a computer
• Must have Computing Power
• Must be able produce data
• Must be able to sense its
environment
• Must have a certain level of
Robustness and Autonomy
How Can Things Produce and transmit data

WebServers

HTTP Packets

Sensors+Microcontroller+Python Clients

Car as WebServers
What is a Webserver

• A web server is a computer that runs websites


• It's a computer program that distributes web pages as they are
requisitioned.
• The basic objective of the web server is to store, process and deliver web
pages to the users.
• This intercommunication is done using Hypertext Transfer Protocol (HTTP).
• Most IOT things are webservers
• Thus we will make a webserver based on esp32 using micropython
Sockets
• A socket is one endpoint of a two-way communication link between
two programs running on the network. A socket is bound to a port
number so that the HTTP can can identify the application that data is
destined to be sent to.
• An endpoint is a combination of an IP address and a port number.
Every TCP connection can be uniquely identified by its two endpoints.
That way you can have multiple connections between your host and
the server.
• Clients and Webservers communicate Via sockets
• Sockets=IP dress+Port Number
HTTP session:Client server Communications
On the client-side: The client knows the hostname of the machine on which the server is running and the port
number on which the server is listening. To make a connection request, the client tries to rendezvous with the
server on the server's machine and port. The client also needs to identify itself to the server so it binds to a
local port number that it will use during this connection. This is usually assigned by the system.

If everything goes well, the server accepts the connection. Upon acceptance, the server gets a new socket bound to the
same local port and also has its remote endpoint set to the address and port of the client. It needs a new socket so that it
can continue to listen to the original socket for connection requests while tending to the needs of the connected client.
Client server Communications
webserver webserver

Socket
64.233. 160.0
DEMO:ESP32 as an IOT webserver
DEMO:ESP32 as an IOT webserver

GPIO_server.py Index.htm
Networking Interface in ESP32
• Wireless connectivity:
• Wi-Fi: 802.11 b/g/n/e/i
(802.11n @ 2.4 GHz up to
150 Mbit/s)
• Can act as a Station or
Access Point
• IEEE 802.11 standard
security features all
supported, including WFA,
WPA/WPA2 and WAPI

ESP32 Functional Block diagram


ESP32 as a network Client
def connectWifi(ssid,passwd):
wlan=network.WLAN(network.STA_IF) #create a wlan object
wlan.active(True) #activate the network interface
wlan.disconnect() #Disconnect the last connected
WiFi
wlan.connect(ssid,passwd) #connect wifi
while not wlan.isconnected():
pass
ip= wlan.ifconfig()[0]
ESP32 as a Webserver serving HTML
ip=wifi.connectWifi(SSID,PASSWORD)
s = socket.socket()
s.bind((ip,80))
s.listen(5)

print('listening on', ip)

while True:
cl, addr = s.accept()
print('client connected from', addr)
request = cl.recv(1024)
cl.send('HTTP/1.0 200 OK\r\nContent-type:
text/html\r\n\r\n')
with open('html2.txt', 'r') as html: cl.sendall(html.read())
cl.close()
HTML2.txt
<HTML>
<HEAD>
<TITLE>Your Title Here</TITLE>
</HEAD>
<BODY BGCOLOR="FFFFFF">
<CENTER><IMG SRC="clouds.jpg" ALIGN="BOTTOM">
</CENTER>
<HR>
<a href="http://somegreatsite.com">Link Name</a>
is a link to another nifty site
<H1>This is a Header</H1>
<H2>This is a Medium Header</H2>
Send me mail at <a href="mailto:[email protected]">
[email protected]</a>.
<P> This is a new paragraph!
<P> <B>This is a new paragraph!</B>
<BR> <B><I>This is a new sentence without a paragraph break, in bold
italics.</I></B>
<HR>
</BODY>
</HTML>
DEMOS
Webinar on Micropython Series
Series Titles:
1. Introduction to Micropython
2. Sensor integration in Micropython
3. Internet of things Using Micropython
4. Intermediate Python and the micropython Runtime Environment
5. Object Oriented programming in Micropython
6. Event Based programming in Micropython
7. Finite State Machines in Micropython
8. Getting to know the ESP32 deeper
9. Developing Robust and Autonomous software in Embedded devices using Micropython
10. Python Data Analysis using Desktop Python and Micropython
11. Power and Energy Optimization in Micropython Devices
12. Wireless sensor networks in Micropython
13. MQTT in Micropython
14. Sockets and networking in Micropython
15. ESPNow technology in Micropython
16. LORA in micropython
17. Machine Vision in Micropython
18. Intro to Embedded Machine Learning in Micropython
19. Intermediate Embedded Machine learning in Micropython
20. Artificial neural networks in Micropython
21. Intro to Autonomous AI Robotics using Micropython
For Your ESP32 and sensor needs
www.e-gizmo.com
Thank you

For more info


www.facebook/micropython.ph
www.micropython.org
www.esp32.net
https://randomnerdtutorials.com/getting-started-with-esp32/
https://randomnerdtutorials.com/getting-started-micropython-esp32-
esp8266/
https://micropython-workshop.readthedocs.io
https://randomnerdtutorials.com/micropython-esp32-esp8266-dht11-
dht22-web-server/
www.e-gizmo.com

You might also like