Page 1 of 1

Socket connection in AP mode not working

Posted: Mon Jul 29, 2019 2:42 pm
by manuel2258
Hey guys,
I'm currently facing a pretty odd network error. Firstly I'm using a Wemos D1 mini with the newest firmware installed. I'm trying to setup a simple network configuration mode over a access point, therefor I currently also I develop an app to communicate with the microcontroller.
The entire code for the microcontroller is written and works perfect when the controller is connected to my wifi. However when trying the same using an access point the controller seams to never receive any communication.

So to make sure that my understanding of networking is right. Beeing in the same network as the controller which is hosted by the controller (access point) and the socket is bound to the address that the socket gives me desolving the '' address, I should be able to simply make request targeting the address of the controller ( and then the socket should receive them, right?

That also what my code does and it basicly the same as other tutorials that I have found.
So here are some code bits. (I'm new here and don't know whether I can use code formation, sorry for that)
I set up my AP using this code:

Code: Select all

    sta_if = network.WLAN(network.STA_IF)
    ap_if = network.WLAN(network.AP_IF)
    mac = ubinascii.hexlify(network.WLAN().config('mac'), ':').decode()
Which works fine. I see the network from my phone and can connect to it.

I set up my socket using this code:

Code: Select all

        address_info = socket.getaddrinfo('', 80)
        print("Hostinfo: {}".format(address_info))
        address = address_info[0][-1]
        self._socket = socket.socket()
And then poll for a incoming connection like that:

Code: Select all

            client, address = self._socket.accept()
            print("New connection from: {}".format(address))
            data = self.receive_all_data(client)
        except OSError:
However I can't register any incoming connection. Said like before that same code works using the STA network mode.

I don't know where to go from here. I can't find anyone online with the same problem. I also have 2 boards which both produce the same error. The even run on different firmware versions, still the same problem.

Does anyone know what I'm doing wrong? Or is it a bug thats bound to the wemos d1 mini?

Thanks for help in advance!
Manuel S.

Re: Socket connection in AP mode not working

Posted: Tue Jul 30, 2019 12:43 am
by jimmo

I was able to see the same thing connecting from my Android phone (Chrome), but interestingly no problem if I joined the ESP8266 AP from my laptop then used `nc` to connect. i.e. using your exact code, binding to, accept a socket, write to it.

Same problem with `nc` on my phone (yay Termux), but then ping in Termux said "packet filtered" from a 10/8 address... wut. My guess is that Android is preferentially using the cellular data rather than WiFi because it knows it has no internet access on the WiFi.

I tried putting the phone into aeroplane mode and only enabling WiFi, and now it works from Chrome.

Re: Socket connection in AP mode not working

Posted: Tue Jul 30, 2019 12:48 am
by jimmo
I looked briefly and don't see an Android option to force it to use the WiFi...although if you're writing your own client then perhaps you can force it to bind to a specific interface?

Re: Socket connection in AP mode not working

Posted: Tue Jul 30, 2019 10:10 am
by manuel2258
Oh wow yeah, that was the problem ... I feel so stupid right now ^^ Simply disabeling the mobile connection forces it to use the non internet AP connection and the microcontroller receives the requests!
It works now, thanks a lot!
Should I somehow mark this thread as solved or something? (I'm new here ...)