コード例 #1
0
        public void Connect(string ssid, string passphrase = null)
        {
            var conf = new WifiConfiguration
            {
                Ssid = $"\"{ssid}\""
            };

            // very important for unprotected networks otherwise connection doesn't go on
            if (passphrase == null)
            {
                conf.AllowedKeyManagement.Set((int)KeyManagementType.None);
            }
            else
            {
                conf.AllowedKeyManagement.Set((int)KeyManagementType.WpaPsk);
                conf.PreSharedKey = $"\"{passphrase}\"";
            }

            var netId = Wifi.AddNetwork(conf);

            currentNetwork = Wifi.ConnectionInfo.NetworkId;
            Wifi.Disconnect();
            var connected = Wifi.EnableNetwork(netId, true);

            if (connected)
            {
                Wifi.Reconnect();
            }
        }