Problem binding socket for captive portal

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
Post Reply
KMcLoud
Posts: 7
Joined: Sun Oct 30, 2016 1:06 pm

Problem binding socket for captive portal

Post by KMcLoud » Sun Nov 06, 2016 2:37 pm

I've got a WiPy serving html over http just fine on port 80 in AP mode.

However, I'm also trying to set up a captive portal so that any dns request within the WiPy's broadcasted network is redirected to the configuration page.

When I go to bind the socket to port 53, the execution just hangs forever. I simplified the code down to:

Code: Select all

import socket
import network

ap = network.WLAN()
ap.init(network.WLAN.AP, ssid='dns test')

def start():        
    udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    udps.setblocking(False)
    udps.settimeout(10)#seconds
    print('just before bind')
    udps.bind(('',53))
    print('just after bind')
when you call start() from the repl, you get:

Code: Select all

>>> start()
just before bind
...the repl never returns

The bind call on port 80 for my http setup works just fine and returns quickly.

Any idea what I'm doing wrong here?

Lysenko
Posts: 62
Joined: Wed Aug 17, 2016 1:21 pm

Re: Problem binding socket for captive portal

Post by Lysenko » Sun Nov 06, 2016 4:13 pm

I've never used a WiPy, but:

setblocking(False) is the same thing as settimeout(0) so all you're doing there is making two consecutive to socket.setsockopt, the first setting SO_NONBLOCKING and the second setting SO_RCVTIMEO which implies a blocking socket.

Given that blocking mode and timeouts don't usually mix with UDP sockets in the first place, maybe that confuses things.

Try commenting out the timeout and blocking lines and see if that makes any difference (they aren't appropriate even if they are not the immediate problem).

Post Reply