1. What I Want To Do
I want to build a webserver on ESP32-WROOM-32(ESP32-DevKitc_V4) with MicroPython(v1.16 on 2021-06-23: latest firmware available). My Goal is building a webserver on ESP32 and collecting the data of sensors connected to ESP32 periodically.
2. Environment
- Windows10 (64bit)
MicroPython firmware v1.16 on 2021-06-23
Editor: Thonny Editor v3.3.11
ESP32 DevKitc v4
ampy v1.1.0
Firstly I wrote a code according to this article : https://randomnerdtutorials.com/esp32-e ... eb-server/(Article Title: RandomNerdTutorial: ESP32/ESP8266 MicroPython Web Server) – Control Outputs. My code is as follows:
Code: Select all
import network
import usys
try:
import usocket as socket
except:
import socket
def connect(SSID,PASS):
AP = network.WLAN(network.AP_IF)
if AP.isconnected():
print("Already connected.")
return AP
else:
AP.active(True)
AP.connect(SSID,PASS)
while not AP.isconnected():
print(".",end="")
utime.sleep(0.5)
if AP.isconnected():
print("Network connection is established.")
return AP
else:
print("Connection failed.")
return False
wifi = connect("myssid","mypass")
if not wifi:
usys.exit(0)
html_strings = """
<!DOCTYPE html>
<html lang='ja'>
<head>
<meta charset='utf-8'>
<title>SERVER TEST</title>
</head>
<body>
<h1>SERVER TEST</h1>
</body>
</html>
"""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
addr = socket.getaddrinfo(("",80))[0][-1]
s.bind(addr)
s.listen(1)
print("Linstening on ", addr)
while True:
conn,addr = s.accept()
print("connected from : ",addr)
request = conn.recv(1024)
respose = html_strings
conn.send("HTTP/1.0 200 OK\r\n")
conn.send("Content-type: text/html\r\n")
conn.send("\r\n")
conn.send(response)
conn.close()
Code: Select all
> ampy --port COM4 put main.py
Code: Select all
MicroPython v1.16 on 2021-06-23; ESP32 module with ESP32
Type "help()" for more information.
Code: Select all
Traceback(most recent call last)
File "main.py", line 48, in <module>
TypeError: function mising 1 required positional arguments
Code: Select all
addr = socket.getaddrinfo(("",80))
Code: Select all
addr = socket.getaddrinfo(("0,0,0,0",80))
Thank you for your cooperation.