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

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.26                
NuGet\Install-Package nanoFramework.Windows.Devices.Wifi -Version 1.3.4-preview.26                
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.26" />                
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.26                
#r "nuget: nanoFramework.Windows.Devices.Wifi, 1.3.4-preview.26"                
#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.26&prerelease

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

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 866 12/28/2021 1.3.4-preview.39 is deprecated because it is no longer maintained.
1.3.4-preview.30 675 12/2/2021 1.3.4-preview.30 is deprecated because it is no longer maintained.
1.3.4-preview.26 306 12/2/2021 1.3.4-preview.26 is deprecated because it is no longer maintained.
1.3.4-preview.24 307 12/2/2021 1.3.4-preview.24 is deprecated because it is no longer maintained.
1.3.4-preview.19 689 11/12/2021 1.3.4-preview.19 is deprecated because it is no longer maintained.
1.3.4-preview.12 380 10/22/2021 1.3.4-preview.12 is deprecated because it is no longer maintained.
1.3.4-preview.6 426 10/17/2021 1.3.4-preview.6 is deprecated because it is no longer maintained.
1.3.3 3,136 9/16/2021 1.3.3 is deprecated because it is no longer maintained.
1.3.3-preview.9 316 9/16/2021 1.3.3-preview.9 is deprecated because it is no longer maintained.
1.3.2 2,699 7/15/2021 1.3.2 is deprecated because it is no longer maintained.
1.3.2-preview.77 337 7/15/2021 1.3.2-preview.77 is deprecated because it is no longer maintained.
1.3.2-preview.75 343 7/14/2021 1.3.2-preview.75 is deprecated because it is no longer maintained.
1.3.2-preview.66 773 6/20/2021 1.3.2-preview.66 is deprecated because it is no longer maintained.
1.3.2-preview.64 384 6/19/2021 1.3.2-preview.64 is deprecated because it is no longer maintained.
1.3.2-preview.60 321 6/19/2021 1.3.2-preview.60 is deprecated because it is no longer maintained.
1.3.2-preview.58 333 6/18/2021 1.3.2-preview.58 is deprecated because it is no longer maintained.
1.3.2-preview.56 359 6/16/2021 1.3.2-preview.56 is deprecated because it is no longer maintained.
1.3.2-preview.54 317 6/16/2021 1.3.2-preview.54 is deprecated because it is no longer maintained.
1.3.2-preview.50 387 6/7/2021 1.3.2-preview.50 is deprecated because it is no longer maintained.
1.3.2-preview.48 361 6/7/2021 1.3.2-preview.48 is deprecated because it is no longer maintained.
1.3.2-preview.46 703 6/6/2021 1.3.2-preview.46 is deprecated because it is no longer maintained.
1.3.2-preview.44 729 6/6/2021 1.3.2-preview.44 is deprecated because it is no longer maintained.
1.3.2-preview.42 402 6/5/2021 1.3.2-preview.42 is deprecated because it is no longer maintained.
1.3.2-preview.40 409 6/5/2021 1.3.2-preview.40 is deprecated because it is no longer maintained.
1.3.2-preview.38 342 6/4/2021 1.3.2-preview.38 is deprecated because it is no longer maintained.
1.3.2-preview.36 356 5/19/2021 1.3.2-preview.36 is deprecated because it is no longer maintained.
1.3.2-preview.35 335 5/19/2021 1.3.2-preview.35 is deprecated because it is no longer maintained.
1.3.2-preview.34 329 5/13/2021 1.3.2-preview.34 is deprecated because it is no longer maintained.
1.3.2-preview.33 334 5/11/2021 1.3.2-preview.33 is deprecated because it is no longer maintained.
1.3.2-preview.29 381 4/8/2021 1.3.2-preview.29 is deprecated because it is no longer maintained.
1.3.2-preview.26 441 3/21/2021 1.3.2-preview.26 is deprecated because it is no longer maintained.
1.3.2-preview.24 360 3/2/2021 1.3.2-preview.24 is deprecated because it is no longer maintained.
1.3.2-preview.21 708 1/6/2021 1.3.2-preview.21 is deprecated because it is no longer maintained.
1.3.2-preview.19 372 12/29/2020 1.3.2-preview.19 is deprecated because it is no longer maintained.
1.3.2-preview.17 327 12/28/2020 1.3.2-preview.17 is deprecated because it is no longer maintained.
1.3.2-preview.14 405 12/7/2020 1.3.2-preview.14 is deprecated because it is no longer maintained.
1.3.2-preview.11 516 10/20/2020 1.3.2-preview.11 is deprecated because it is no longer maintained.
1.3.2-preview.9 399 9/30/2020 1.3.2-preview.9 is deprecated because it is no longer maintained.
1.3.2-preview.7 394 9/30/2020 1.3.2-preview.7 is deprecated because it is no longer maintained.
1.3.2-preview.5 418 9/27/2020 1.3.2-preview.5 is deprecated because it is no longer maintained.
1.3.2-preview.1 427 9/24/2020 1.3.2-preview.1 is deprecated because it is no longer maintained.
1.3.1-preview.6 467 7/2/2020 1.3.1-preview.6 is deprecated because it is no longer maintained.
1.3.1-preview.4 408 7/1/2020 1.3.1-preview.4 is deprecated because it is no longer maintained.
1.3.1-preview.2 436 6/16/2020 1.3.1-preview.2 is deprecated because it is no longer maintained.
1.3.0 1,697 6/16/2020 1.3.0 is deprecated because it is no longer maintained.
1.3.0-preview.5 415 6/16/2020 1.3.0-preview.5 is deprecated because it is no longer maintained.
1.2.0 1,375 6/12/2020 1.2.0 is deprecated because it is no longer maintained.
1.2.0-preview.24 413 6/12/2020 1.2.0-preview.24 is deprecated because it is no longer maintained.
1.2.0-preview.22 448 6/11/2020 1.2.0-preview.22 is deprecated because it is no longer maintained.
1.2.0-preview.20 425 5/29/2020 1.2.0-preview.20 is deprecated because it is no longer maintained.
1.2.0-preview.19 439 5/8/2020 1.2.0-preview.19 is deprecated because it is no longer maintained.
1.2.0-preview.18 426 5/8/2020 1.2.0-preview.18 is deprecated because it is no longer maintained.
1.2.0-preview.17 425 4/27/2020 1.2.0-preview.17 is deprecated because it is no longer maintained.
1.2.0-preview.16 449 4/16/2020 1.2.0-preview.16 is deprecated because it is no longer maintained.
1.2.0-preview.15 392 4/14/2020 1.2.0-preview.15 is deprecated because it is no longer maintained.
1.2.0-preview.14 460 3/15/2020 1.2.0-preview.14 is deprecated because it is no longer maintained.
1.2.0-preview.12 408 3/10/2020 1.2.0-preview.12 is deprecated because it is no longer maintained.
1.2.0-preview.11 431 3/9/2020 1.2.0-preview.11 is deprecated because it is no longer maintained.
1.2.0-preview.9 503 11/18/2019 1.2.0-preview.9 is deprecated because it is no longer maintained.
1.2.0-preview.8 407 11/14/2019 1.2.0-preview.8 is deprecated because it is no longer maintained.
1.2.0-preview.7 409 11/7/2019 1.2.0-preview.7 is deprecated because it is no longer maintained.
1.2.0-preview.6 423 11/5/2019 1.2.0-preview.6 is deprecated because it is no longer maintained.
1.2.0-preview.5 415 11/4/2019 1.2.0-preview.5 is deprecated because it is no longer maintained.
1.2.0-preview.4 420 10/23/2019 1.2.0-preview.4 is deprecated because it is no longer maintained.
1.2.0-preview.3 412 10/18/2019 1.2.0-preview.3 is deprecated because it is no longer maintained.
1.1.0 1,616 10/30/2019 1.1.0 is deprecated because it is no longer maintained.
1.1.0-preview.3 422 10/17/2019 1.1.0-preview.3 is deprecated because it is no longer maintained.
1.0.7 1,437 10/15/2019 1.0.7 is deprecated because it is no longer maintained.
1.0.7-preview.26 424 10/15/2019 1.0.7-preview.26 is deprecated because it is no longer maintained.
1.0.7-preview.25 436 10/15/2019 1.0.7-preview.25 is deprecated because it is no longer maintained.
1.0.7-preview.24 412 9/30/2019 1.0.7-preview.24 is deprecated because it is no longer maintained.
1.0.7-preview.17 470 7/18/2019 1.0.7-preview.17 is deprecated because it is no longer maintained.
1.0.7-preview.14 515 6/23/2019 1.0.7-preview.14 is deprecated because it is no longer maintained.
1.0.7-preview.9 471 6/20/2019 1.0.7-preview.9 is deprecated because it is no longer maintained.
1.0.7-preview.6 507 6/12/2019 1.0.7-preview.6 is deprecated because it is no longer maintained.
1.0.7-preview.2 459 6/12/2019 1.0.7-preview.2 is deprecated because it is no longer maintained.
1.0.6-preview-009 1,190 4/24/2019 1.0.6-preview-009 is deprecated because it is no longer maintained.
1.0.6-preview-008 1,289 4/23/2019 1.0.6-preview-008 is deprecated because it is no longer maintained.
1.0.6-preview-002 1,054 4/7/2019 1.0.6-preview-002 is deprecated because it is no longer maintained.
1.0.6-preview-001 1,121 4/7/2019 1.0.6-preview-001 is deprecated because it is no longer maintained.
1.0.4 1,871 1/22/2019 1.0.4 is deprecated because it is no longer maintained.
1.0.4-preview-007 1,102 4/3/2019 1.0.4-preview-007 is deprecated because it is no longer maintained.
1.0.4-preview-005 1,072 3/11/2019 1.0.4-preview-005 is deprecated because it is no longer maintained.
1.0.4-preview-003 1,120 3/10/2019 1.0.4-preview-003 is deprecated because it is no longer maintained.
1.0.4-preview-001 1,165 3/7/2019 1.0.4-preview-001 is deprecated because it is no longer maintained.
1.0.3-preview-007 1,132 3/7/2019 1.0.3-preview-007 is deprecated because it is no longer maintained.
1.0.2 1,648 12/15/2018 1.0.2 is deprecated because it is no longer maintained.
1.0.2-preview-017 1,216 12/5/2018 1.0.2-preview-017 is deprecated because it is no longer maintained.
1.0.2-preview-011 1,214 11/20/2018 1.0.2-preview-011 is deprecated because it is no longer maintained.
1.0.2-preview-007 1,204 11/8/2018 1.0.2-preview-007 is deprecated because it is no longer maintained.
1.0.2-preview-004 1,194 11/8/2018 1.0.2-preview-004 is deprecated because it is no longer maintained.
1.0.0 1,688 10/17/2018 1.0.0 is deprecated because it is no longer maintained.
1.0.0-preview022 1,191 10/9/2018 1.0.0-preview022 is deprecated because it is no longer maintained.
1.0.0-preview015 1,197 9/18/2018 1.0.0-preview015 is deprecated because it is no longer maintained.
1.0.0-preview009 1,193 9/6/2018 1.0.0-preview009 is deprecated because it is no longer maintained.