Dear Sir,
I follwed exactly the same procedure / steps given in the tutorial. But I am getting the following errer.
exec(open(‘./main.py’).read(),globals())
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “<string>”, line 9, in <module>
NameError: name ‘socket’ is not defined
>>> r$
Did you upload both the boot.py and main.py files?
You’re probably getting that error because you haven’t uploaded the boot.py file.
Regards,
Sara
Dear Madam, I Followed the same procedure. I have uploaded both main.py and booty.py files. But the resualt is as below –
Ready to download this file,please wait!
……
download ok
exec(open(‘main.py’).read(),globals())
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “<string>”, line 9, in <module>
OSError: [Errno 98] EADDRINUSE
>>> {d
Codesentered are as below –
Main.py
Start your code here
# Complete project details at https://RandomNerdTutorials.com def web_page(): html = """<html><head><meta name="viewport" content="width=device-width, initial-scale=1"></head> <body><h1>Hello, World!</h1></body></html>""" return html s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('', 80)) s.listen(5) while True: conn, addr = s.accept() print('Got a connection from %s' % str(addr)) request = conn.recv(1024) print('Content = %s' % str(request)) response = web_page() conn.send('HTTP/1.1 200 OK\n') conn.send('Content-Type: text/html\n') conn.send('Connection: close\n\n') conn.sendall(response) conn.close()
---------------------------
booty.py
Start your code here
# Complete project details at https://RandomNerdTutorials.com #import socket import sys try: import usocket as socket except: import socket import network import esp esp.osdebug(None) import gc gc.collect() ssid = 'xxxxxxx' password = 'xxxxxx' help' station = network.WLAN(network.STA_IF) station.active(True) station.connect(ssid, password) while station.isconnected() == False: pass print('Connection successful') print(station.ifconfig())
>>
>>>
Ready to download this file,please wait!
….
download ok
exec(open(‘boot.py’).read(),globals())
Connection successful
(‘192.168.1.104’, ‘255.255.255.0’, ‘192.168.1.1’, ‘192.168.1.1’)
>>>
Finaly I am succesful in getting IP Address. But it is not displaying web page in browser