http server problem
Posted: Wed Aug 03, 2016 10:54 am
Hi, I am trying to offer a web page from esp (nodeMCU) so the user can introduce ssid and password for future connection. If the client url is http:/192.168.4.1/ssid/pass data should be taken from this. If url is just http://192.168.4.1 it should send the form to client.
I can read the url or send the form . But I can´t do both, only the one i do first.
Any help will be thanked. Here is my code:
[code]def levantarAp():
print("levantar AP")
ap = network.WLAN(network.AP_IF) # create access-point interface
ap.config(essid='APILINK_SETUP') # set the ESSID of the access point
ap.config(authmode=0) # sin contraseña
ap.active(True)
print(ap.status())
#esperar conexion
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
print(addr)
print(ap.ifconfig())
s = socket.socket()
s.setblocking(True)
s.bind(addr)
s.listen(1)
seguir=True
while(seguir):
print('listening ', addr)
cl, addr = s.accept() #ESPERAR
print('client connected from', addr)
cl_file = cl.makefile('rwb', 0)# nos e que hace pero hace falta
try:
print("leer linea")
l=str(cl.readline())
print(l)
# http://192.168.4.1/ssid/pass/
# recibe: 'GET /ssid/pass/ HTTP/1.1\r\n'
l=l[l.index('/')+1 : l.index('/ HTTP')]
print(l)
ssid=l[:l.index('/')]
pas=l[l.index('/')+1:]
print(ssid)
print(pas)
seguir=False
except:
print("errorcito al leer")
#mandar la pag
try:
print("enviar pagina")
html=pagConfiguracion()
print(html)
cl.send(html)
cl.close()
seguir=False
i=0
except:
print("error al enviar")
#hasta que NO se cierra el socket la pag no se envia
print("OK !!")[/code]
I can read the url or send the form . But I can´t do both, only the one i do first.
Any help will be thanked. Here is my code:
[code]def levantarAp():
print("levantar AP")
ap = network.WLAN(network.AP_IF) # create access-point interface
ap.config(essid='APILINK_SETUP') # set the ESSID of the access point
ap.config(authmode=0) # sin contraseña
ap.active(True)
print(ap.status())
#esperar conexion
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
print(addr)
print(ap.ifconfig())
s = socket.socket()
s.setblocking(True)
s.bind(addr)
s.listen(1)
seguir=True
while(seguir):
print('listening ', addr)
cl, addr = s.accept() #ESPERAR
print('client connected from', addr)
cl_file = cl.makefile('rwb', 0)# nos e que hace pero hace falta
try:
print("leer linea")
l=str(cl.readline())
print(l)
# http://192.168.4.1/ssid/pass/
# recibe: 'GET /ssid/pass/ HTTP/1.1\r\n'
l=l[l.index('/')+1 : l.index('/ HTTP')]
print(l)
ssid=l[:l.index('/')]
pas=l[l.index('/')+1:]
print(ssid)
print(pas)
seguir=False
except:
print("errorcito al leer")
#mandar la pag
try:
print("enviar pagina")
html=pagConfiguracion()
print(html)
cl.send(html)
cl.close()
seguir=False
i=0
except:
print("error al enviar")
#hasta que NO se cierra el socket la pag no se envia
print("OK !!")[/code]