Skip to content

Commit

Permalink
Improve Improv-wifi (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellerbach authored Jan 3, 2024
1 parent a6bdb7f commit de60c82
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
19 changes: 16 additions & 3 deletions samples/Bluetooth/ImprovWifi/Improv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Device.Wifi;
using nanoFramework.Networking;
using nanoFramework.Device.Bluetooth.Advertisement;
using System.Threading;

namespace ImprovWifi
{
Expand Down Expand Up @@ -524,11 +525,23 @@ public bool ConnectWiFi(string ssid, string password)
WifiAdapter wa = WifiAdapter.FindAllAdapters()[0];
wa.Disconnect();

System.Threading.CancellationTokenSource cs = new(30000);
CancellationTokenSource cs = new(30000);
Console.WriteLine("ConnectDHCP");
bool success = WifiNetworkHelper.ConnectDhcp(ssid, password, requiresDateTime: true, token: cs.Token);
WifiNetworkHelper.Disconnect();
bool success;

success = WifiNetworkHelper.ConnectDhcp(ssid, password, WifiReconnectionKind.Automatic, true, token: cs.Token);

if (!success)
{
wa.Disconnect();
// Network helper only allow 1 configuration, we've most likely try to connect before, let's make it manual
var res = wa.Connect(ssid, WifiReconnectionKind.Automatic, password);
// If we still arenot connected, it means, it's not good!
success = res.ConnectionStatus == WifiConnectionStatus.Success;
}

Console.WriteLine($"ConnectDHCP exit {success}");
cs.Cancel();
return success;
}

Expand Down
33 changes: 11 additions & 22 deletions samples/Bluetooth/ImprovWifi/ImprovWifi.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,49 +27,38 @@
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib, Version=1.15.6.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<Reference Include="mscorlib">
<HintPath>packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nanoFramework.Device.Bluetooth, Version=1.1.60.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<Reference Include="nanoFramework.Device.Bluetooth">
<HintPath>packages\nanoFramework.Device.Bluetooth.1.1.60\lib\nanoFramework.Device.Bluetooth.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nanoFramework.Runtime.Events, Version=1.11.15.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<Reference Include="nanoFramework.Runtime.Events">
<HintPath>packages\nanoFramework.Runtime.Events.1.11.15\lib\nanoFramework.Runtime.Events.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nanoFramework.Runtime.Native, Version=1.6.12.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<Reference Include="nanoFramework.Runtime.Native">
<HintPath>packages\nanoFramework.Runtime.Native.1.6.12\lib\nanoFramework.Runtime.Native.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nanoFramework.System.Collections, Version=1.5.31.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<Reference Include="nanoFramework.System.Collections">
<HintPath>packages\nanoFramework.System.Collections.1.5.31\lib\nanoFramework.System.Collections.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nanoFramework.System.Text, Version=1.2.54.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<Reference Include="nanoFramework.System.Text">
<HintPath>packages\nanoFramework.System.Text.1.2.54\lib\nanoFramework.System.Text.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Device.Wifi, Version=1.5.71.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<Reference Include="System.Device.Wifi">
<HintPath>packages\nanoFramework.System.Device.Wifi.1.5.71\lib\System.Device.Wifi.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.IO.Streams, Version=1.1.52.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<Reference Include="System.IO.Streams">
<HintPath>packages\nanoFramework.System.IO.Streams.1.1.52\lib\System.IO.Streams.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net, Version=1.10.64.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<Reference Include="System.Net">
<HintPath>packages\nanoFramework.System.Net.1.10.64\lib\System.Net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http, Version=1.5.113.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<Reference Include="System.Net.Http">
<HintPath>packages\nanoFramework.System.Net.Http.1.5.113\lib\System.Net.Http.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading, Version=1.1.32.63105, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<Reference Include="System.Threading">
<HintPath>packages\nanoFramework.System.Threading.1.1.32\lib\System.Threading.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
Expand Down
2 changes: 1 addition & 1 deletion samples/Bluetooth/ImprovWifi/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 🌶️🌶️🌶️ - Improv Wifi provisioning

This sample shows the use of the `Improv` class to provision the Wifi credentials for an ESP32 device via Bluetooth LE.
This sample shows the use of the `Improv` class to provision the Wifi credentials for an ESP32 device via Bluetooth LE. To setup your device, go to the page [<https://www.improv-wifi.com/>](https://www.improv-wifi.com/).

The device will advertise with the name `Improv sample` and support the `Improv Service` allowing the Wifi Credentials to be setup directly from the Improv test page or any other web page.

Expand Down

0 comments on commit de60c82

Please sign in to comment.