nanoFramework.Windows.Devices.Wifi 1.3.4-preview.39 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved

.NET Framework
Suggested Alternatives

nanoFramework.System.Device.Wifi

This is a prerelease version of nanoFramework.Windows.Devices.Wifi.
Install-Package nanoFramework.Windows.Devices.Wifi -Version 1.3.4-preview.39
dotnet add package nanoFramework.Windows.Devices.Wifi --version 1.3.4-preview.39
<PackageReference Include="nanoFramework.Windows.Devices.Wifi" Version="1.3.4-preview.39" />
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.39
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.39"
#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.39&prerelease

// Install nanoFramework.Windows.Devices.Wifi as a Cake Tool
#tool nuget:?package=nanoFramework.Windows.Devices.Wifi&version=1.3.4-preview.39&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


Document Language: English | 简体中文

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 Versions
.NET Framework net
Compatible target framework(s)
Additional computed target framework(s)
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.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 (1)

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

Repository Stars
dotnet/samples
Sample code referenced by the .NET documentation
Version Downloads Last updated
1.3.4-preview.39 452 12/28/2021
1.3.4-preview.30 531 12/2/2021
1.3.4-preview.26 173 12/2/2021
1.3.4-preview.24 179 12/2/2021
1.3.4-preview.19 559 11/12/2021
1.3.4-preview.12 243 10/22/2021
1.3.4-preview.6 295 10/17/2021
1.3.3 1,701 9/16/2021
1.3.3-preview.9 180 9/16/2021
1.3.2 1,209 7/15/2021
1.3.2-preview.77 191 7/15/2021
1.3.2-preview.75 209 7/14/2021
1.3.2-preview.66 637 6/20/2021
1.3.2-preview.64 254 6/19/2021
1.3.2-preview.60 190 6/19/2021
1.3.2-preview.58 196 6/18/2021
1.3.2-preview.56 226 6/16/2021
1.3.2-preview.54 190 6/16/2021
1.3.2-preview.50 257 6/7/2021
1.3.2-preview.48 226 6/7/2021
1.3.2-preview.46 567 6/6/2021
1.3.2-preview.44 597 6/6/2021
1.3.2-preview.42 270 6/5/2021
1.3.2-preview.40 275 6/5/2021
1.3.2-preview.38 205 6/4/2021
1.3.2-preview.36 212 5/19/2021
1.3.2-preview.35 201 5/19/2021
1.3.2-preview.34 196 5/13/2021
1.3.2-preview.33 203 5/11/2021
1.3.2-preview.29 246 4/8/2021
1.3.2-preview.26 308 3/21/2021
1.3.2-preview.24 228 3/2/2021
1.3.2-preview.21 587 1/6/2021
1.3.2-preview.19 243 12/29/2020
1.3.2-preview.17 201 12/28/2020
1.3.2-preview.14 269 12/7/2020
1.3.2-preview.11 384 10/20/2020
1.3.2-preview.9 279 9/30/2020
1.3.2-preview.7 268 9/30/2020
1.3.2-preview.5 298 9/27/2020
1.3.2-preview.1 297 9/24/2020
1.3.1-preview.6 335 7/2/2020
1.3.1-preview.4 277 7/1/2020
1.3.1-preview.2 300 6/16/2020
1.3.0 725 6/16/2020
1.3.0-preview.5 282 6/16/2020
1.2.0 433 6/12/2020
1.2.0-preview.24 285 6/12/2020
1.2.0-preview.22 311 6/11/2020
1.2.0-preview.20 298 5/29/2020
1.2.0-preview.19 313 5/8/2020
1.2.0-preview.18 291 5/8/2020
1.2.0-preview.17 292 4/27/2020
1.2.0-preview.16 316 4/16/2020
1.2.0-preview.15 267 4/14/2020
1.2.0-preview.14 328 3/15/2020
1.2.0-preview.12 276 3/10/2020
1.2.0-preview.11 305 3/9/2020
1.2.0-preview.9 373 11/18/2019
1.2.0-preview.8 284 11/14/2019
1.2.0-preview.7 284 11/7/2019
1.2.0-preview.6 293 11/5/2019
1.2.0-preview.5 291 11/4/2019
1.2.0-preview.4 295 10/23/2019
1.2.0-preview.3 286 10/18/2019
1.1.0 648 10/30/2019
1.1.0-preview.3 291 10/17/2019
1.0.7 490 10/15/2019
1.0.7-preview.26 301 10/15/2019
1.0.7-preview.25 310 10/15/2019
1.0.7-preview.24 287 9/30/2019
1.0.7-preview.17 348 7/18/2019
1.0.7-preview.14 382 6/23/2019
1.0.7-preview.9 327 6/20/2019
1.0.7-preview.6 361 6/12/2019
1.0.7-preview.2 318 6/12/2019
1.0.6-preview-009 544 4/24/2019
1.0.6-preview-008 691 4/23/2019
1.0.6-preview-002 475 4/7/2019
1.0.6-preview-001 472 4/7/2019
1.0.4 866 1/22/2019
1.0.4-preview-007 477 4/3/2019
1.0.4-preview-005 483 3/11/2019
1.0.4-preview-003 488 3/10/2019
1.0.4-preview-001 481 3/7/2019
1.0.3-preview-007 471 3/7/2019
1.0.2 677 12/15/2018
1.0.2-preview-017 588 12/5/2018
1.0.2-preview-011 570 11/20/2018
1.0.2-preview-007 583 11/8/2018
1.0.2-preview-004 563 11/8/2018
1.0.0 742 10/17/2018
1.0.0-preview022 604 10/9/2018
1.0.0-preview015 607 9/18/2018
1.0.0-preview009 634 9/6/2018