[Ovmsdev] A promiscous wifi client

Mark Webb-Johnson mark at webb-johnson.net
Thu Nov 9 13:38:09 HKT 2017

I’ve committed a change to the esp32wifi component, to try to support a promiscuous mode for the wifi client. This should make it work the way it does on cellphones, computers, and pretty much all equipment. Rather than specifying a specific wifi AP to connect to, it just connects to whichever it can (based on where it has connected to in the past).

Up until now, we’ve supported the wifi client mode as follows:

config set wifi.ssid <SSID> <password>
wifi mode client <SSID>

That seems to work well, and reconnection now seems pretty robust.

What I’ve committed today supports this variant:

config set wifi.ssid <SSID1> <password>
config set wifi.ssid <SSID2> <password>
… etc
wifi mode client

The module should then connect to either SSID1 or SSID2, whichever comes into range.

I’ve got no idea how phones, laptops, etc, actually implement it, and can’t find much information on the ESP32 resources or forums. There is certainly no magic ‘here is a list of SSIDs - connect to whichever comes close’ function in the wifi libraries. So, I ended up implementing the following logic:

Bring up the wifi as a client, in station mode.
Every 30 seconds or so, do a wifi scan of available SSIDs.
If we find a SSID within range, that has a matching name in config wifi.ssid, we try to actively connect to it. For this, we pick the first SSID we find that matches.
If we don’t manage to connect (get disconnected), or there is no SSID in range that matches anything in config wifi.ssid, wait for 30 seconds, then go back and scan again.

It’s not elegant, but seems to work. Change is isolated in esp32wifi.{h,cpp}, which is pretty small and manageable at the moment. Please give it a go, and let me know how it works out for you.

Regards, Mark.

P.S. Also found (and cleaned up) a big stonking memory leak in ‘wifi scan’.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20171109/83af9a2d/attachment.htm>

More information about the OvmsDev mailing list