nanoFramework.NetWorkHelper 1.3.4-preview.34

Prefix Reserved
Additional Details

NetworkHelpers are now available in nanoFramework.System.Net and nanoFramework.System.Device.WiFi

This is a prerelease version of nanoFramework.NetWorkHelper.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package nanoFramework.NetWorkHelper --version 1.3.4-preview.34
                    
NuGet\Install-Package nanoFramework.NetWorkHelper -Version 1.3.4-preview.34
                    
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.NetWorkHelper" Version="1.3.4-preview.34" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.NetWorkHelper" Version="1.3.4-preview.34" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.NetWorkHelper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add nanoFramework.NetWorkHelper --version 1.3.4-preview.34
                    
#r "nuget: nanoFramework.NetWorkHelper, 1.3.4-preview.34"
                    
#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.
#addin nuget:?package=nanoFramework.NetWorkHelper&version=1.3.4-preview.34&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=nanoFramework.NetWorkHelper&version=1.3.4-preview.34&prerelease
                    
Install as a Cake Tool

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.4-preview.40 693 12/29/2021 1.3.4-preview.40 is deprecated because it is no longer maintained.
1.3.4-preview.36 346 12/16/2021 1.3.4-preview.36 is deprecated because it is no longer maintained.
1.3.4-preview.34 458 12/3/2021 1.3.4-preview.34 is deprecated because it is no longer maintained.
1.3.4-preview.32 276 12/3/2021 1.3.4-preview.32 is deprecated because it is no longer maintained.
1.3.4-preview.30 283 12/2/2021 1.3.4-preview.30 is deprecated because it is no longer maintained.
1.3.4-preview.28 277 12/2/2021 1.3.4-preview.28 is deprecated because it is no longer maintained.
1.3.4-preview.26 276 12/2/2021 1.3.4-preview.26 is deprecated because it is no longer maintained.
1.3.4-preview.21 696 11/13/2021 1.3.4-preview.21 is deprecated because it is no longer maintained.
1.3.4-preview.14 328 10/23/2021 1.3.4-preview.14 is deprecated because it is no longer maintained.
1.3.4-preview.12 279 10/22/2021 1.3.4-preview.12 is deprecated because it is no longer maintained.
1.3.4-preview.10 313 10/18/2021 1.3.4-preview.10 is deprecated because it is no longer maintained.
1.3.4-preview.8 330 10/18/2021 1.3.4-preview.8 is deprecated because it is no longer maintained.
1.3.4-preview.6 349 10/17/2021 1.3.4-preview.6 is deprecated because it is no longer maintained.
1.3.4-preview.3 960 9/16/2021 1.3.4-preview.3 is deprecated because it is no longer maintained.
1.3.3 1,724 9/16/2021 1.3.3 is deprecated because it is no longer maintained.
1.3.3-preview.5 1,111 7/17/2021 1.3.3-preview.5 is deprecated because it is no longer maintained.
1.3.3-preview.3 308 7/16/2021 1.3.3-preview.3 is deprecated because it is no longer maintained.
1.3.2 448 7/15/2021 1.3.2 is deprecated because it is no longer maintained.
1.3.2-preview.77 296 7/15/2021 1.3.2-preview.77 is deprecated because it is no longer maintained.
1.3.2-preview.75 317 7/14/2021 1.3.2-preview.75 is deprecated because it is no longer maintained.
1.3.2-preview.71 735 7/1/2021 1.3.2-preview.71 is deprecated because it is no longer maintained.
1.3.2-preview.68 306 6/21/2021 1.3.2-preview.68 is deprecated because it is no longer maintained.
1.3.2-preview.66 330 6/20/2021 1.3.2-preview.66 is deprecated because it is no longer maintained.
1.3.2-preview.60 293 6/19/2021 1.3.2-preview.60 is deprecated because it is no longer maintained.
1.3.2-preview.58 301 6/18/2021 1.3.2-preview.58 is deprecated because it is no longer maintained.
1.3.2-preview.56 334 6/16/2021 1.3.2-preview.56 is deprecated because it is no longer maintained.
1.3.2-preview.54 292 6/16/2021 1.3.2-preview.54 is deprecated because it is no longer maintained.
1.3.2-preview.50 341 6/7/2021 1.3.2-preview.50 is deprecated because it is no longer maintained.
1.3.2-preview.48 660 6/7/2021 1.3.2-preview.48 is deprecated because it is no longer maintained.
1.3.2-preview.46 349 6/6/2021 1.3.2-preview.46 is deprecated because it is no longer maintained.
1.3.2-preview.44 706 6/6/2021 1.3.2-preview.44 is deprecated because it is no longer maintained.
1.3.2-preview.42 360 6/5/2021 1.3.2-preview.42 is deprecated because it is no longer maintained.