http server problem

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
atauri
Posts: 1
Joined: Wed Aug 03, 2016 10:46 am

http server problem

Post by atauri » 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]

chc77
Posts: 1
Joined: Fri Sep 30, 2016 3:35 pm

Re: http server problem

Post by chc77 » Fri Sep 30, 2016 3:41 pm

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

jms
Posts: 108
Joined: Thu May 05, 2016 8:29 pm
Contact:

Re: http server problem

Post by jms » Mon Oct 03, 2016 10:18 am

You're trying to implement HTTP which isn't completely trivial. I strongly suggest you use somebody else's implementation.

Jon

chrisgp
Posts: 41
Joined: Fri Apr 01, 2016 5:29 pm

Re: http server problem

Post by chrisgp » Mon Oct 03, 2016 7:23 pm

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.

bmsleight
Posts: 1
Joined: Wed Oct 05, 2016 9:03 pm

Re: http server problem

Post by bmsleight » Wed Oct 05, 2016 9:11 pm

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

tomm2
Posts: 6
Joined: Thu Mar 23, 2017 4:32 pm

Re: http server problem

Post by tomm2 » Fri May 05, 2017 11:42 am

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.

Post Reply