An empty HOST string should work. Are you still getting an error or does it just hang?
Your code looks OK as far as making a connection goes. I'm not so sure about the HTML you are generating but if you try connecting to your devices IP address via a browser you should at least see a connection if you run the code from the REPL.
I'd reiterate that it's worth building things up slowly. Forget about images until you can serve a simple, text only, web page.
For what it's worth here is my minimal webserver code:
Code: Select all
import network
from socket import socket
from net_config import SSID, PSWD
station = network.WLAN(network.STA_IF)
station.active(True)
while True:
try:
station.connect(SSID,PSWD)
except:
pass
if station.isconnected():
break
print('Connection successful')
print(station.ifconfig())
s = socket()
s.bind(('', 80))
s.listen(5)
while True:
conn, addr = s.accept()
print('Got a connection from' + str(addr))
request = conn.recv(1024)
conn.send('HTTP/1.1 200 OK\n')
conn.send('Content-Type: text/html\n')
conn.send('Connection: close\n\n')
conn.sendall('Hello New World')
conn.close()
And the output from the program when connecting via a browser to the IP address:
Code: Select all
Connection successful
('192.168.1.187', '255.255.255.0', '192.168.1.1', '192.168.1.1')
Got a connection from('192.168.1.131', 39494)