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]
http server problem
Re: http server problem
Hi!
I'm new and not very expert...
Im' trying to create a simple webserver that start as AP (default ip 192.168.4.1) and ask to insert ssid and pass of a present wifi network.
I saw your question and no response, you have any news from other source?
I found a simple webserver asking ssid and password for a arduino environnement and I'm looking something similar in micropython..
http://iot-playground.com/blog/2-uncate ... 1-improved
I'm new and not very expert...
Im' trying to create a simple webserver that start as AP (default ip 192.168.4.1) and ask to insert ssid and pass of a present wifi network.
I saw your question and no response, you have any news from other source?
I found a simple webserver asking ssid and password for a arduino environnement and I'm looking something similar in micropython..
http://iot-playground.com/blog/2-uncate ... 1-improved
Re: http server problem
You're trying to implement HTTP which isn't completely trivial. I strongly suggest you use somebody else's implementation.
Jon
Jon
Re: http server problem
Here are a few examples you can checkout:
https://www.davidgouveia.net/2016/07/co ... n-esp8266/
https://github.com/micropython/micropyt ... es/network
For what you're trying to accomplish you shouldn't need anything too complicated. You'll want to parse the path like the first link does and return some static HTML content with a form if the path is just /, and then a button on the form can POST to a different path that will indicate you should parse the body for the SSID and Password.
https://www.davidgouveia.net/2016/07/co ... n-esp8266/
https://github.com/micropython/micropyt ... es/network
For what you're trying to accomplish you shouldn't need anything too complicated. You'll want to parse the path like the first link does and return some static HTML content with a form if the path is just /, and then a button on the form can POST to a different path that will indicate you should parse the body for the SSID and Password.
Re: http server problem
See https://github.com/bmsleight/shedcode/b ... nisetup.py Although http://docs.micropython.org/en/latest/e ... ot-process says I should not change inisetup.py
Further details - https://www.barwap.com/projects/microbu ... crobutton/ but this is still a work in progress. (Need add some error checking for bad urls. Simple webserver only accepts a 4096 bytes, so we do some hacks using javascript.
Line 126 of my inisetup.py could be changer to config_names = ["ssid", "passwd", "D"] and only two parameters will be asked. To see it in action:- https://www.barwap.com/projects/microbutton/record.gif
Hope this helps,
Brendan
Further details - https://www.barwap.com/projects/microbu ... crobutton/ but this is still a work in progress. (Need add some error checking for bad urls. Simple webserver only accepts a 4096 bytes, so we do some hacks using javascript.
Line 126 of my inisetup.py could be changer to config_names = ["ssid", "passwd", "D"] and only two parameters will be asked. To see it in action:- https://www.barwap.com/projects/microbutton/record.gif
Hope this helps,
Brendan
Re: http server problem
Here is an example solution: https://github.com/manningt/setwifi
This implementation assumes the module will be 'frozen' in flash, so the size is not critical. It can be used for initial deployment of a device, or it can be called if the WiFi network needs to be changed at a later time.
This implementation assumes the module will be 'frozen' in flash, so the size is not critical. It can be used for initial deployment of a device, or it can be called if the WiFi network needs to be changed at a later time.