nanoFramework.Windows.Devices.Wifi 1.3.4-preview.30

Suggested Alternatives

nanoFramework.System.Device.WiFi

This is a prerelease version of nanoFramework.Windows.Devices.Wifi.
There is a newer prerelease version of this package available.
See the version list below for details.
Install-Package nanoFramework.Windows.Devices.Wifi -Version 1.3.4-preview.30
dotnet add package nanoFramework.Windows.Devices.Wifi --version 1.3.4-preview.30
<PackageReference Include="nanoFramework.Windows.Devices.Wifi" Version="1.3.4-preview.30" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nanoFramework.Windows.Devices.Wifi --version 1.3.4-preview.30
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: nanoFramework.Windows.Devices.Wifi, 1.3.4-preview.30"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install nanoFramework.Windows.Devices.Wifi as a Cake Addin
#addin nuget:?package=nanoFramework.Windows.Devices.Wifi&version=1.3.4-preview.30&prerelease

// Install nanoFramework.Windows.Devices.Wifi as a Cake Tool
#tool nuget:?package=nanoFramework.Windows.Devices.Wifi&version=1.3.4-preview.30&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Quality Gate Status Reliability Rating License NuGet #yourfirstpr Discord

nanoFramework logo


Welcome to the .NET nanoFramework Windows.Devices.WiFi Library repository and NetworkHelper

This repository contains nanoFramework Windows.Devices.Wifi and NetworkHelper.

Build status

Component Build Status NuGet Package
Windows.Devices.WiFi Build Status NuGet
Windows.Devices.WiFi (preview) Build Status NuGet

NetworkHelper usage

The NetworkHelper is mainly dedicated to help you connect automatically to WiFi networks. That said, it can be used as well to check if you have a valid IP address and a valid date on any interface including on ethernet.

Preferred usage

The following code will allow you to connect automatically, wait for a valid IP address and a valid date with specific credentials:

const string Ssid = "YourSSID";
const string Password = "YourWifiPassword";
// Give 60 seconds to the wifi join to happen
CancellationTokenSource cs = new(60000);
var success = NetworkHelper.ConnectWifiDhcp(Ssid, Password, setDateTime: true, token: cs.Token);
if (!success)
{
    // Something went wrong, you can get details with the ConnectionError property:
    Debug.WriteLine($"Can't connect to the network, error: {NetworkHelper.ConnectionError.Error}");
    if (NetworkHelper.ConnectionError.Exception != null)
    {
        Debug.WriteLine($"ex: { NetworkHelper.ConnectionError.Exception}");
    }
}
// Otherwise, you are connected and have a valid IP and date

Note that this function will store the network credentials on the device.

Using stored credentials

You can as well connect to a network with pre stored credentials on the device depending on the type of device you have. Please check for proper support with your device.

if (!NetworkHelper.IsConfigurationStored())
{
    Debug.WriteLine("No configuration stored in the device");
}
else
{
    // The wifi credentials are already stored on the device
    // Give 60 seconds to the wifi join to happen
    CancellationTokenSource cs = new(60000);
    var success = NetworkHelper.ReconnectWifi(setDateTime: true, token: cs.Token);
    if (!success)
    {
        // Something went wrong, you can get details with the ConnectionError property:
        Debug.WriteLine($"Can't connect to the network, error: {NetworkHelper.ConnectionError.Error}");
        if (NetworkHelper.ConnectionError.Exception != null)
        {
            Debug.WriteLine($"ex: { NetworkHelper.ConnectionError.Exception}");
        }
    }
    // Otherwise, you are connected and have a valid IP and date
}

Scan and join

You can force to scan the network and then join the network. This case can be useful in specific conditions. Be aware, that you may have to use this method with one of the previous method depending the support of rescanning while you are already connected.

const string Ssid = "YourSSID";
const string Password = "YourWifiPassword";
// Give 60 seconds to the wifi join to happen
CancellationTokenSource cs = new(60000);
var success = NetworkHelper.ScanAndConnectWifiDhcp(Ssid, Password, setDateTime: true, token: cs.Token);
if (!success)
{
    // Something went wrong, you can get details with the ConnectionError property:
    Debug.WriteLine($"Can't connect to the network, error: {NetworkHelper.ConnectionError.Error}");
    if (NetworkHelper.ConnectionError.Exception != null)
    {
        Debug.WriteLine($"ex: { NetworkHelper.ConnectionError.Exception}");
    }
}
// Otherwise, you are connected and have a valid IP and date

Note that this function will store the network credentials on the device.

Joining with a static IP address

You join a WiFi network with a static IP address:

const string Ssid = "YourSSID";
const string Password = "YourWifiPassword";
// Give 60 seconds to the wifi join to happen
CancellationTokenSource cs = new(60000);
var success = NetworkHelper.ConnectWifiFixAddress(Ssid, Password, new IPConfiguration("192.168.1.7", "255.255.255.0", "192.168.1.1"), setDateTime: true, token: cs.Token);

Checking valid IP address and date

The NetworkHelper offers couple of functions to check validity of your IP address, the DateTime and helping setting them up:

var success = IsValidDateTime();
// if success is true, you have a valid DateTime
success = IsValidIpAddress(NetworkInterfaceType.Wireless80211);
// if success is true, you have a valid IP address on the Wireless adapter
// Be aware that a local address like 127.0.0.1 is considered as a valid address for ethernet

You can as well wait for a valid IP address and date time:

// Give 60 seconds to check if we have a valid IP and a valid DateTime
CancellationTokenSource cs = new(60000);
var success = WaitForValidIPAndDate(true, NetworkInterfaceType.Ethernet, cs.Token);
// if success is true then you are connected

NetworkHelper usage

The NetworkHelper is mainly dedicated to help you connect automatically to WiFi networks. That said, it can be used as well to check if you have a valid IP address and a valid date on any interface including on ethernet.

Preferred usage

The following code will allow you to connect automatically, wait for a valid IP address and a valid date with specific credentials:

const string Ssid = "YourSSID";
const string Password = "YourWifiPassword";
// Give 60 seconds to the wifi join to happen
CancellationTokenSource cs = new(60000);
var success = NetworkHelper.ConnectWifiDhcp(Ssid, Password, setDateTime: true, token: cs.Token);
if (!success)
{
    // Something went wrong, you can get details with the ConnectionError property:
    Debug.WriteLine($"Can't connect to the network, error: {NetworkHelper.ConnectionError.Error}");
    if (NetworkHelper.ConnectionError.Exception != null)
    {
        Debug.WriteLine($"ex: { NetworkHelper.ConnectionError.Exception}");
    }
}
// Otherwise, you are connected and have a valid IP and date

Note that this function will store the network credentials on the device.

Using stored credentials

You can as well connect to a network with pre stored credentials on the device depending on the type of device you have. Please check for proper support with your device.

// The wifi credentials are already stored on the device
 // Give 60 seconds to the wifi join to happen
CancellationTokenSource cs = new(60000);
var success = NetworkHelper.ReconnectWifi(setDateTime: true, token: cs.Token);
if (!success)
{
    // Something went wrong, you can get details with the ConnectionError property:
    Debug.WriteLine($"Can't connect to the network, error: {NetworkHelper.ConnectionError.Error}");
    if (NetworkHelper.ConnectionError.Exception != null)
    {
        Debug.WriteLine($"ex: { NetworkHelper.ConnectionError.Exception}");
    }
}
// Otherwise, you are connected and have a valid IP and date

Scan and join

You can force to scan the network and then join the network. This case can be useful in specific conditions. Be aware, that you may have to use this method with one of the previous method depending the support of rescanning while you are already connected.

const string Ssid = "YourSSID";
const string Password = "YourWifiPassword";
// Give 60 seconds to the wifi join to happen
CancellationTokenSource cs = new(60000);
var success = NetworkHelper.ScanAndConnectWifiDhcp(Ssid, Password, setDateTime: true, token: cs.Token);
if (!success)
{
    // Something went wrong, you can get details with the ConnectionError property:
    Debug.WriteLine($"Can't connect to the network, error: {NetworkHelper.ConnectionError.Error}");
    if (NetworkHelper.ConnectionError.Exception != null)
    {
        Debug.WriteLine($"ex: { NetworkHelper.ConnectionError.Exception}");
    }
}
// Otherwise, you are connected and have a valid IP and date

Note that this function will store the network credentials on the device.

Joining with a static IP address

You join a WiFi network with a static IP address:

const string Ssid = "YourSSID";
const string Password = "YourWifiPassword";
// Give 60 seconds to the wifi join to happen
CancellationTokenSource cs = new(60000);
var success = NetworkHelper.ConnectWifiFixAddress(Ssid, Password, new IPConfiguration("192.168.1.7", "255.255.255.0", "192.168.1.1"), setDateTime: true, token: cs.Token);

Checking valid IP address and date

The NetworkHelper offers couple of functions to check validity of your IP address, the DateTime and helping setting them up:

var success = IsValidDateTime();
// if success is true, you have a valid DateTime
success = IsValidIpAddress(NetworkInterfaceType.Wireless80211);
// if success is true, you have a valid IP address on the Wireless adapter
// Be aware that a local address like 127.0.0.1 is considered as a valid address for ethernet

You can as well wait for a valid IP address and date time:

// Give 60 seconds to check if we have a valid IP and a valid DateTime
CancellationTokenSource cs = new(60000);
var success = WaitForValidIPAndDate(true, NetworkInterfaceType.Ethernet, cs.Token);
// if success is true then you are connected

Feedback and documentation

For documentation, providing feedback, issues and finding out how to contribute please refer to the Home repo.

Join our Discord community here.

Credits

The list of contributors to this project can be found at CONTRIBUTORS.

License

The nanoFramework Class Libraries are licensed under the MIT license.

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behaviour in our community. For more information see the .NET Foundation Code of Conduct.

.NET Foundation

This project is supported by the .NET Foundation.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on nanoFramework.Windows.Devices.Wifi:

Package Downloads
nanoFramework.NetWorkHelper

This package includes the NetWorkHelper assembly for .NET nanoFramework C# projects.

ArdNet.Nano.Client

ArdNet Client implementation for NanoFramework. Built for the ESP32, but should work for any wifi-enabled microcontroller running NanoFramework

ArdNet.Nano

ArdNet implementation for NanoFramework. Built for the ESP32, but should work for any wifi-enabled microcontroller running NanoFramework

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on nanoFramework.Windows.Devices.Wifi:

Repository Stars
dotnet/samples
Sample code referenced by the .NET documentation
nanoframework/Samples
🍬 Code samples from the nanoFramework team used in testing, proof of concepts and other explorational endeavours
Version Downloads Last updated
1.3.4-preview.39 128 12/28/2021
1.3.4-preview.30 368 12/2/2021
1.3.4-preview.26 62 12/2/2021
1.3.4-preview.24 61 12/2/2021
1.3.4-preview.19 342 11/12/2021
1.3.4-preview.12 129 10/22/2021
1.3.4-preview.6 175 10/17/2021
1.3.3 1,169 9/16/2021
1.3.3-preview.9 69 9/16/2021
1.3.2 994 7/15/2021
1.3.2-preview.77 77 7/15/2021
1.3.2-preview.75 97 7/14/2021
1.3.2-preview.66 524 6/20/2021
1.3.2-preview.64 140 6/19/2021
1.3.2-preview.60 80 6/19/2021
1.3.2-preview.58 86 6/18/2021
1.3.2-preview.56 113 6/16/2021
1.3.2-preview.54 76 6/16/2021
1.3.2-preview.50 146 6/7/2021
1.3.2-preview.48 110 6/7/2021
1.3.2-preview.46 455 6/6/2021
1.3.2-preview.44 483 6/6/2021
1.3.2-preview.42 158 6/5/2021
1.3.2-preview.40 161 6/5/2021
1.3.2-preview.38 95 6/4/2021
1.3.2-preview.36 100 5/19/2021
1.3.2-preview.35 94 5/19/2021
1.3.2-preview.34 88 5/13/2021
1.3.2-preview.33 98 5/11/2021
1.3.2-preview.29 142 4/8/2021
1.3.2-preview.26 202 3/21/2021
1.3.2-preview.24 120 3/2/2021
1.3.2-preview.21 480 1/6/2021
1.3.2-preview.19 127 12/29/2020
1.3.2-preview.17 92 12/28/2020
1.3.2-preview.14 151 12/7/2020
1.3.2-preview.11 272 10/20/2020
1.3.2-preview.9 167 9/30/2020
1.3.2-preview.7 155 9/30/2020
1.3.2-preview.5 181 9/27/2020
1.3.2-preview.1 185 9/24/2020
1.3.1-preview.6 226 7/2/2020
1.3.1-preview.4 166 7/1/2020
1.3.1-preview.2 189 6/16/2020
1.3.0 571 6/16/2020
1.3.0-preview.5 171 6/16/2020
1.2.0 293 6/12/2020
1.2.0-preview.24 175 6/12/2020
1.2.0-preview.22 201 6/11/2020
1.2.0-preview.20 183 5/29/2020
1.2.0-preview.19 198 5/8/2020
1.2.0-preview.18 180 5/8/2020
1.2.0-preview.17 179 4/27/2020
1.2.0-preview.16 201 4/16/2020
1.2.0-preview.15 156 4/14/2020
1.2.0-preview.14 222 3/15/2020
1.2.0-preview.12 164 3/10/2020
1.2.0-preview.11 194 3/9/2020
1.2.0-preview.9 257 11/18/2019
1.2.0-preview.8 168 11/14/2019
1.2.0-preview.7 173 11/7/2019
1.2.0-preview.6 180 11/5/2019
1.2.0-preview.5 179 11/4/2019
1.2.0-preview.4 180 10/23/2019
1.2.0-preview.3 179 10/18/2019
1.1.0 498 10/30/2019
1.1.0-preview.3 180 10/17/2019
1.0.7 341 10/15/2019
1.0.7-preview.26 185 10/15/2019
1.0.7-preview.25 198 10/15/2019
1.0.7-preview.24 181 9/30/2019
1.0.7-preview.17 238 7/18/2019
1.0.7-preview.14 265 6/23/2019
1.0.7-preview.9 201 6/20/2019
1.0.7-preview.6 234 6/12/2019
1.0.7-preview.2 198 6/12/2019
1.0.6-preview-009 416 4/24/2019
1.0.6-preview-008 563 4/23/2019
1.0.6-preview-002 356 4/7/2019
1.0.6-preview-001 348 4/7/2019
1.0.4 703 1/22/2019
1.0.4-preview-007 353 4/3/2019
1.0.4-preview-005 357 3/11/2019
1.0.4-preview-003 365 3/10/2019
1.0.4-preview-001 358 3/7/2019
1.0.3-preview-007 358 3/7/2019
1.0.2 525 12/15/2018
1.0.2-preview-017 460 12/5/2018
1.0.2-preview-011 445 11/20/2018
1.0.2-preview-007 461 11/8/2018
1.0.2-preview-004 443 11/8/2018
1.0.0 587 10/17/2018
1.0.0-preview022 474 10/9/2018
1.0.0-preview015 483 9/18/2018
1.0.0-preview009 503 9/6/2018