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

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
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.
dotnet add package nanoFramework.Windows.Devices.Wifi --version 1.3.4-preview.30
NuGet\Install-Package nanoFramework.Windows.Devices.Wifi -Version 1.3.4-preview.30
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<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
#r "nuget: nanoFramework.Windows.Devices.Wifi, 1.3.4-preview.30"
#r directive can be used in F# Interactive and Polyglot Notebooks. 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

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.

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

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

Package Downloads
nanoFramework.NetWorkHelper The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

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

ArdNet.Nano

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

ArdNet.Nano.Client

ArdNet Client 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 806 12/28/2021
1.3.4-preview.30 652 12/2/2021
1.3.4-preview.26 289 12/2/2021
1.3.4-preview.24 291 12/2/2021
1.3.4-preview.19 673 11/12/2021
1.3.4-preview.12 358 10/22/2021
1.3.4-preview.6 408 10/17/2021
1.3.3 2,831 9/16/2021
1.3.3-preview.9 294 9/16/2021
1.3.2 2,404 7/15/2021
1.3.2-preview.77 313 7/15/2021
1.3.2-preview.75 323 7/14/2021
1.3.2-preview.66 756 6/20/2021
1.3.2-preview.64 366 6/19/2021
1.3.2-preview.60 303 6/19/2021
1.3.2-preview.58 315 6/18/2021
1.3.2-preview.56 337 6/16/2021
1.3.2-preview.54 297 6/16/2021
1.3.2-preview.50 364 6/7/2021
1.3.2-preview.48 342 6/7/2021
1.3.2-preview.46 678 6/6/2021
1.3.2-preview.44 705 6/6/2021
1.3.2-preview.42 380 6/5/2021
1.3.2-preview.40 386 6/5/2021
1.3.2-preview.38 321 6/4/2021
1.3.2-preview.36 333 5/19/2021
1.3.2-preview.35 311 5/19/2021
1.3.2-preview.34 312 5/13/2021
1.3.2-preview.33 317 5/11/2021
1.3.2-preview.29 357 4/8/2021
1.3.2-preview.26 416 3/21/2021
1.3.2-preview.24 335 3/2/2021
1.3.2-preview.21 691 1/6/2021
1.3.2-preview.19 350 12/29/2020
1.3.2-preview.17 309 12/28/2020
1.3.2-preview.14 387 12/7/2020
1.3.2-preview.11 491 10/20/2020
1.3.2-preview.9 381 9/30/2020
1.3.2-preview.7 375 9/30/2020
1.3.2-preview.5 399 9/27/2020
1.3.2-preview.1 402 9/24/2020
1.3.1-preview.6 447 7/2/2020
1.3.1-preview.4 389 7/1/2020
1.3.1-preview.2 410 6/16/2020
1.3.0 1,613 6/16/2020
1.3.0-preview.5 389 6/16/2020
1.2.0 1,281 6/12/2020
1.2.0-preview.24 392 6/12/2020
1.2.0-preview.22 422 6/11/2020
1.2.0-preview.20 407 5/29/2020
1.2.0-preview.19 420 5/8/2020
1.2.0-preview.18 400 5/8/2020
1.2.0-preview.17 400 4/27/2020
1.2.0-preview.16 424 4/16/2020
1.2.0-preview.15 374 4/14/2020
1.2.0-preview.14 435 3/15/2020
1.2.0-preview.12 383 3/10/2020
1.2.0-preview.11 413 3/9/2020
1.2.0-preview.9 479 11/18/2019
1.2.0-preview.8 388 11/14/2019
1.2.0-preview.7 390 11/7/2019
1.2.0-preview.6 398 11/5/2019
1.2.0-preview.5 395 11/4/2019
1.2.0-preview.4 401 10/23/2019
1.2.0-preview.3 393 10/18/2019
1.1.0 1,535 10/30/2019
1.1.0-preview.3 402 10/17/2019
1.0.7 1,356 10/15/2019
1.0.7-preview.26 404 10/15/2019
1.0.7-preview.25 417 10/15/2019
1.0.7-preview.24 390 9/30/2019
1.0.7-preview.17 448 7/18/2019
1.0.7-preview.14 492 6/23/2019
1.0.7-preview.9 449 6/20/2019
1.0.7-preview.6 484 6/12/2019
1.0.7-preview.2 437 6/12/2019
1.0.6-preview-009 1,120 4/24/2019
1.0.6-preview-008 1,219 4/23/2019
1.0.6-preview-002 980 4/7/2019
1.0.6-preview-001 1,056 4/7/2019
1.0.4 1,789 1/22/2019
1.0.4-preview-007 1,038 4/3/2019
1.0.4-preview-005 992 3/11/2019
1.0.4-preview-003 1,050 3/10/2019
1.0.4-preview-001 1,098 3/7/2019
1.0.3-preview-007 1,055 3/7/2019
1.0.2 1,562 12/15/2018
1.0.2-preview-017 1,139 12/5/2018
1.0.2-preview-011 1,149 11/20/2018
1.0.2-preview-007 1,131 11/8/2018
1.0.2-preview-004 1,119 11/8/2018
1.0.0 1,588 10/17/2018
1.0.0-preview022 1,130 10/9/2018
1.0.0-preview015 1,127 9/18/2018
1.0.0-preview009 1,128 9/6/2018