I use this codesnippet at the end of my AP/STA Template.
Further Connecting WLAN (ssid, pwd) is successfully done.
Code: Select all
# Connecting to WLAN, reading sensors, making webpage are done
1 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
2 s.bind(('', 80))
3 s.listen(1) #only one client
4 while True:
5 try:
6 print('waiting for client request')
7 conn, addr = s.accept()
8 print('Got a connection from %s' % str(addr)) #old Syntax
9 #print('Got a connection from {}'.format((addr))) #new Syntax
10 request = conn.recv(1024)
11 print('Content = %s' % str(request)) #old Syntax
12 #print('Content = {}' .format(str(request))) #new Syntax
13 response = web_page() #storing html-data from web_page():
14 conn.send('HTTP/1.1 200 OK\n')
15 conn.send('Content-Type: text/html\n')
16 conn.send('Connection: close\n\n')
17 conn.sendall(response) #send html to client
18 conn.close()
19 print('Connection closed', '\n')
20 except OSError as e:
21 conn.close()
Printing in 8/9 works with ESP32 and ESP8266 (uPyCraft)
Printing in 11/12 works only with ESP32 but it does not work with ESP8266!
I get only a C and nothing else. C from Content:
Why?
The received datavolume is less than 1024 Bytes and looks like this.
Code: Select all
Content = b'GET / HTTP/1.1\r\nHOST: 192.168.4.1\r\nUpgrade- ... \r\nConnection: keep-alive\r\n\r\n'
Only printing in 19 does not appear!
This is the seccond Problem with using ESP8266 vs ESP32 (1st: BME280.py is not executed)
regards