nanoFramework.System.Device.Wifi 1.4.0.14

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package nanoFramework.System.Device.Wifi --version 1.4.0.14                
NuGet\Install-Package nanoFramework.System.Device.Wifi -Version 1.4.0.14                
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.System.Device.Wifi" Version="1.4.0.14" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nanoFramework.System.Device.Wifi --version 1.4.0.14                
#r "nuget: nanoFramework.System.Device.Wifi, 1.4.0.14"                
#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.System.Device.Wifi as a Cake Addin
#addin nuget:?package=nanoFramework.System.Device.Wifi&version=1.4.0.14

// Install nanoFramework.System.Device.Wifi as a Cake Tool
#tool nuget:?package=nanoFramework.System.Device.Wifi&version=1.4.0.14                

Quality Gate Status Reliability Rating License NuGet #yourfirstpr Discord

nanoFramework logo


Document Language: English | 简体中文

Welcome to the .NET nanoFramework System.Device.Wifi Library repository

This repository contains the nanoFramework System.Device.Wifi class library.

Build status

Component Build Status NuGet Package
System.Device.Wifi Build Status NuGet

WifiNetworkHelper usage

The WifiNetworkHelper class 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 = WifiNetworkHelper.ConnectDhcp(Ssid, Password, requiresDateTime: 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: {WifiNetworkHelper.Status}");
    if (WifiNetworkHelper.HelperException != null)
    {
        Debug.WriteLine($"ex: {WifiNetworkHelper.HelperException}");
    }
}
// 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 (!WifiNetworkHelper.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 = WifiNetworkHelper.Reconnect(requiresDateTime: 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: {WifiNetworkHelper.Status}");
        if (WifiNetworkHelper.HelperException != null)
        {
            Debug.WriteLine($"ex: {WifiNetworkHelper.HelperException}");
        }
    }
    // 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 = WifiNetworkHelper.ScanAndConnectDhcp(Ssid, Password, requiresDateTime: 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: {WifiNetworkHelper.Status}");
    if (WifiNetworkHelper.HelperException != null)
    {
        Debug.WriteLine($"ex: {WifiNetworkHelper.HelperException}");
    }
}
// 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 = WifiNetworkHelper.ConnectFixAddress(Ssid, Password, new IPConfiguration("192.168.1.7", "255.255.255.0", "192.168.1.1"), requiresDateTime: true, token: cs.Token);

Checking valid IP address and date

The WifiNetworkHelper 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

WifiNetworkHelper usage

The WifiNetworkHelper 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 = WifiNetworkHelper.ConnectDhcp(Ssid, Password, requiresDateTime: 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: {WifiNetworkHelper.Status}");
    if (WifiNetworkHelper.HelperException != null)
    {
        Debug.WriteLine($"ex: {WifiNetworkHelper.HelperException}");
    }
}
// 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 = WifiNetworkHelper.Reconnect(requiresDateTime: 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: {WifiNetworkHelper.Status}");
    if (WifiNetworkHelper.HelperException != null)
    {
        Debug.WriteLine($"ex: {WifiNetworkHelper.HelperException}");
    }
}
// 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 = WifiNetworkHelper.ScanAndConnectDhcp(Ssid, Password, requiresDateTime: 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: {WifiNetworkHelper.Status}");
    if (WifiNetworkHelper.HelperException != null)
    {
        Debug.WriteLine($"ex: {WifiNetworkHelper.HelperException}");
    }
}
// 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 = WifiNetworkHelper.ConnectFixAddress(Ssid, Password, new IPConfiguration("192.168.1.7", "255.255.255.0", "192.168.1.1"), requiresDateTime: true, token: cs.Token);

Checking valid IP address and date

The WifiNetworkHelper 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 (5)

Showing the top 5 NuGet packages that depend on nanoFramework.System.Device.Wifi:

Package Downloads
MakoIoT.Device.Services.ConfigurationManager

Configuration mode manager for MAKO-IoT

MakoIoT.Device.Services.WiFi.AP

WiFi Access Point library for MAKO-IoT

MakoIoT.Device.Services.ConfigurationApi

REST API for configuration with MAKO-IoT

MakoIoT.Device.Services.WiFi

WiFi connectivity library for MAKO-IoT

MakoIoT.Device.Platform.LocalConfig

MAKO-IoT Platform local configuration library. On-device web server, WiFi AP

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on nanoFramework.System.Device.Wifi:

Repository Stars
nanoframework/Samples
🍬 Code samples from the nanoFramework team used in testing, proof of concepts and other explorational endeavours
nanoframework/nanoFramework.IoT.Device
📦 This repo includes .NET nanoFramework implementations for various sensors, chips, displays, hats and drivers
nanoframework/nanoFramework.M5Stack
:package: Board support package for M5Stack, M5StickC and M5StickCPlus for .NET nanoFramework
Version Downloads Last updated
1.5.91 6,550 7/29/2024
1.5.85 3,234 5/13/2024
1.5.83 126 5/13/2024
1.5.81 1,600 4/8/2024
1.5.79 822 4/3/2024
1.5.76 2,598 1/29/2024
1.5.74 800 1/26/2024
1.5.71 6,986 11/10/2023
1.5.67 482 11/9/2023
1.5.65 1,797 10/16/2023
1.5.54 7,654 2/16/2023
1.5.51 1,844 12/28/2022
1.5.49 764 12/28/2022
1.5.46 731 12/27/2022
1.5.37 2,205 10/26/2022
1.5.35 795 10/26/2022
1.5.33 837 10/25/2022
1.5.31 804 10/24/2022
1.5.29 869 10/23/2022
1.5.27 1,124 10/10/2022
1.5.25 826 10/8/2022
1.5.22 957 9/22/2022
1.5.20 1,264 9/21/2022
1.5.18 812 9/21/2022
1.5.13 1,009 9/15/2022
1.5.8 1,802 8/4/2022
1.5.6 831 8/4/2022
1.5.4 787 8/3/2022
1.5.2 879 8/3/2022
1.4.0.24 858 8/3/2022
1.4.0.22 1,620 6/13/2022
1.4.0.20 919 6/8/2022
1.4.0.16 1,089 5/26/2022
1.4.0.14 942 5/18/2022
1.4.0.12 1,628 5/4/2022
1.4.0.10 882 5/4/2022
1.4.0 1,676 3/29/2022
1.4.0-preview.59 171 3/28/2022
1.4.0-preview.57 136 3/28/2022
1.4.0-preview.55 143 3/28/2022
1.4.0-preview.53 134 3/28/2022
1.4.0-preview.51 140 3/28/2022
1.4.0-preview.48 271 3/17/2022
1.4.0-preview.46 192 3/16/2022
1.4.0-preview.44 161 3/14/2022
1.4.0-preview.42 145 3/14/2022
1.4.0-preview.40 148 3/14/2022
1.4.0-preview.36 523 2/17/2022
1.4.0-preview.34 265 2/8/2022
1.4.0-preview.32 245 2/4/2022
1.4.0-preview.30 154 2/4/2022
1.4.0-preview.28 158 2/4/2022
1.4.0-preview.26 218 1/28/2022
1.4.0-preview.24 185 1/28/2022
1.4.0-preview.21 187 1/21/2022
1.4.0-preview.19 150 1/21/2022
1.4.0-preview.17 151 1/21/2022
1.4.0-preview.15 152 1/21/2022
1.4.0-preview.13 150 1/21/2022
1.4.0-preview.11 255 1/12/2022
1.4.0-preview.6 207 1/5/2022
1.4.0-preview.1 377 1/4/2022
1.3.4-preview.44 216 1/4/2022
1.3.4-preview.43 176 1/4/2022