Return-Path: <ovmsdev-bounces@lists.teslaclub.hk>
Received: from network-box.com ([unix socket])
	 by nbmailhq5 (Cyrus v2.3.16-Fedora-RPM-2.3.16-6_5.nb5.0.2) with LMTPA;
	 Thu, 09 Nov 2017 13:38:21 +0800
X-Sieve: CMU Sieve 2.3
Received: from nbmailscanhq5.network-box.com (unknown [10.12.18.182])
	by network-box.com (Postfix) with ESMTP id 22FB32100016
	for <mark.johnson@network-box.com>; Thu,  9 Nov 2017 13:38:21 +0800 (HKT)
Received: from nbmailhk1.network-box.com (localhost [127.0.0.1])
	by nbmailscanhq5.network-box.com (Postfix) with ESMTP id B1E2DA0FB8
	for <mark.johnson@network-box.com>; Thu,  9 Nov 2017 13:38:18 +0800 (HKT)
Received: from unknown (EHLO nbmailhk1.network-box.com) (10.8.18.9)
  by 127.0.0.1 (Network Box) with SMTP id
 '30837ec8-c510-11e7-b87e-7e2b5a688fa9'; 09 Nov 2017 05:38:21 -0000
X-Scanned-By-nbmailscanhq5: eMail scan performed by network-box
X-Scanned-By-nbmailscanhq5: Network Box scan job
 30e12d02-c510-11e7-b87e-7e2b5a688fa9
X-Scanned-By-nbmailscanhq5: Network Box message id
 30837ec8-c510-11e7-b87e-7e2b5a688fa9
Received: from nbmailscanhq5.network-box.com (unknown [10.12.18.182])
	by nbmailhk1.network-box.com (Postfix) with ESMTP id 0A2BE78036
	for <mark@webb-johnson.net>; Thu,  9 Nov 2017 13:38:18 +0800 (HKT)
Received: from markhk2.network-box.com (localhost [127.0.0.1])
	by nbmailscanhq5.network-box.com (Postfix) with ESMTP id E6A76A0FBB;
	Thu,  9 Nov 2017 13:38:15 +0800 (HKT)
Received: from unknown (EHLO markhk2.network-box.com) (10.12.18.80)
  by 127.0.0.1 (Network Box) with SMTP id
 '2e24887a-c510-11e7-87af-7e2b5a688fa9'; 09 Nov 2017 05:38:17 -0000
X-Scanned-By-nbmailscanhq5: eMail scan performed by network-box
X-Scanned-By-nbmailscanhq5: Network Box scan job
 2f41d3ca-c510-11e7-87af-7e2b5a688fa9
X-Scanned-By-nbmailscanhq5: Network Box message id
 2e24887a-c510-11e7-87af-7e2b5a688fa9
Received: from [127.0.0.1] (markhk2 [127.0.0.1])
	by markhk2.network-box.com (Postfix) with ESMTP id 278E380054;
	Thu,  9 Nov 2017 13:38:14 +0800 (HKT)
X-Original-To: OvmsDev@lists.teslaclub.hk
Delivered-To: OvmsDev@lists.teslaclub.hk
Received: from nbmailscanhq5.network-box.com (unknown [10.12.18.182])
	by markhk2.network-box.com (Postfix) with ESMTP id 638E680052
	for <OvmsDev@lists.teslaclub.hk>; Thu,  9 Nov 2017 13:38:12 +0800 (HKT)
Received: from [10.8.2.100] (localhost [127.0.0.1])
	by nbmailscanhq5.network-box.com (Postfix) with ESMTP id 328FDA0FBB
	for <OvmsDev@lists.teslaclub.hk>; Thu,  9 Nov 2017 13:38:10 +0800 (HKT)
Received: from unknown (EHLO [10.8.2.100]) (10.8.2.100)
	by 127.0.0.1 (Network Box) with SMTP id
	'2b783f0e-c510-11e7-98d9-7e2b5a688fa9'; 09 Nov 2017 05:38:12 -0000
X-NetworkBox-Signature-Group-NBHQ: 0501; GROUP; NBHQ; nbmailscanhq5;
	5f807f87e3ee1abc656824757c2e72b78c10b3a3d4e7fe436f9d8a276ab99468
X-Scanned-By-nbmailscanhq5: eMail scan performed by network-box
X-Scanned-By-nbmailscanhq5: Network Box scan job
	2bbfa2e0-c510-11e7-98d9-7e2b5a688fa9
X-Scanned-By-nbmailscanhq5: Network Box message id
	2b783f0e-c510-11e7-98d9-7e2b5a688fa9
From: Mark Webb-Johnson <mark@webb-johnson.net>
Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\))
Message-Id: <62F68336-EAD0-4A31-840D-87F86F40D593@webb-johnson.net>
Date: Thu, 9 Nov 2017 13:38:09 +0800
To: OVMS Developers <OvmsDev@lists.teslaclub.hk>
X-Mailer: Apple Mail (2.3273)
Subject: [Ovmsdev] A promiscous wifi client
X-BeenThere: ovmsdev@lists.teslaclub.hk
X-Mailman-Version: 2.1.11
Precedence: list
Reply-To: OVMS Developers <ovmsdev@lists.teslaclub.hk>
List-Id: OVMS Developers <ovmsdev.lists.teslaclub.hk>
List-Unsubscribe: <http://lists.teslaclub.hk/mailman/options/ovmsdev>,
	<mailto:ovmsdev-request@lists.teslaclub.hk?subject=unsubscribe>
List-Archive: <http://lists.teslaclub.hk/pipermail/ovmsdev>
List-Post: <mailto:ovmsdev@lists.teslaclub.hk>
List-Help: <mailto:ovmsdev-request@lists.teslaclub.hk?subject=help>
List-Subscribe: <http://lists.teslaclub.hk/mailman/listinfo/ovmsdev>,
	<mailto:ovmsdev-request@lists.teslaclub.hk?subject=subscribe>
Content-Type: multipart/mixed; boundary="===============7099450398505908811=="
Sender: ovmsdev-bounces@lists.teslaclub.hk
Errors-To: ovmsdev-bounces@lists.teslaclub.hk


--===============7099450398505908811==
Content-Type: multipart/alternative;
 boundary="Apple-Mail=_EB356935-B191-4E71-AD4C-AB72DBBE5637"


--Apple-Mail=_EB356935-B191-4E71-AD4C-AB72DBBE5637
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8


I=E2=80=99ve 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=E2=80=99ve 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=E2=80=99ve committed today supports this variant:

config set wifi.ssid <SSID1> <password>
config set wifi.ssid <SSID2> <password>
=E2=80=A6 etc
wifi mode client

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

I=E2=80=99ve got no idea how phones, laptops, etc, actually implement =
it, and can=E2=80=99t find much information on the ESP32 resources or =
forums. There is certainly no magic =E2=80=98here is a list of SSIDs - =
connect to whichever comes close=E2=80=99 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=E2=80=99t 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=E2=80=99s 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 =E2=80=98wi=
fi scan=E2=80=99.


--Apple-Mail=_EB356935-B191-4E71-AD4C-AB72DBBE5637
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html =
charset=3Dutf-8"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" =
class=3D""><div class=3D""><br class=3D""></div><div class=3D"">I=E2=80=99=
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).</div><div class=3D""><br class=3D""></div><div class=3D"">Up =
until now, we=E2=80=99ve supported the wifi client mode as =
follows:</div><div class=3D""><br class=3D""></div><div class=3D""><ul =
class=3D"MailOutline"><li class=3D"">config set wifi.ssid &lt;SSID&gt; =
&lt;password&gt;</li><li class=3D"">wifi mode client =
&lt;SSID&gt;</li></ul></div><div class=3D""><br class=3D""></div><div =
class=3D"">That seems to work well, and reconnection now seems pretty =
robust.</div><div class=3D""><br class=3D""></div><div class=3D"">What =
I=E2=80=99ve committed today supports this variant:</div><div =
class=3D""><br class=3D""></div><div class=3D""><ul =
class=3D"MailOutline"><li class=3D"">config set wifi.ssid &lt;SSID1&gt; =
&lt;password&gt;</li><li class=3D"">config set wifi.ssid &lt;SSID2&gt; =
&lt;password&gt;</li><li class=3D"">=E2=80=A6 etc</li><li class=3D"">wifi =
mode client</li></ul></div><div class=3D""><br class=3D""></div><div =
class=3D"">The module should then connect to either SSID1 or SSID2, =
whichever comes into range.</div><div class=3D""><br class=3D""></div><div=
 class=3D"">I=E2=80=99ve got no idea how phones, laptops, etc, actually =
implement it, and can=E2=80=99t find much information on the ESP32 =
resources or forums. There is certainly no magic =E2=80=98here is a list =
of SSIDs - connect to whichever comes close=E2=80=99 function in the =
wifi libraries. So, I ended up implementing the following =
logic:</div><div class=3D""><br class=3D""></div><div class=3D""><ul =
class=3D"MailOutline"><li class=3D"">Bring up the wifi as a client, in =
station mode.</li><li class=3D"">Every 30 seconds or so, do a wifi scan =
of available SSIDs.</li><li class=3D"">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.</li><li =
class=3D"">If we don=E2=80=99t 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.</li></ul></div><div =
class=3D""><br class=3D""></div><div class=3D"">It=E2=80=99s 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.</div><div class=3D""><br =
class=3D""></div><div class=3D"">Regards, Mark.</div><div class=3D""><br =
class=3D""></div><div class=3D"">P.S. Also found (and cleaned up) a big =
stonking memory leak in =E2=80=98wifi scan=E2=80=99.</div><div =
class=3D""><br class=3D""></div></body></html>=

--Apple-Mail=_EB356935-B191-4E71-AD4C-AB72DBBE5637--

--===============7099450398505908811==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
OvmsDev mailing list
OvmsDev@lists.teslaclub.hk
http://lists.teslaclub.hk/mailman/listinfo/ovmsdev

--===============7099450398505908811==--
