Esempio n. 1
0
        public static void Main()
        {
            Debug.WriteLine("Welcome to WiFI Soft AP world!");

            GpioPin setupButton = GpioController.GetDefault().OpenPin(SETUP_PIN);

            setupButton.SetDriveMode(GpioPinDriveMode.InputPullUp);

            // If Wireless station is not enabled then start Soft AP to allow Wireless configuration
            // or Button pressed
            if (!Wireless80211.IsEnabled() || (setupButton.Read() == GpioPinValue.Low))
            {
                Wireless80211.Disable();

                if (WirelessAP.Setup() == false)
                {
                    // Reboot device to Activate Access Point on restart
                    Debug.WriteLine($"Setup Soft AP, Rebooting device");
                    Power.RebootDevice();
                }

                Debug.WriteLine($"Running Soft AP, waiting for client to connect");
                Debug.WriteLine($"Soft AP IP address :{WirelessAP.GetIP()}");

                // Link up Network event to show Stations connecting/disconnecting to Access point.
                NetworkChange.NetworkAPStationChanged += NetworkChange_NetworkAPStationChanged;;
            }
            else
            {
                Debug.WriteLine($"Running in normal mode, connecting to Access point");
                string IpAdr = Wireless80211.WaitIP();
                Debug.WriteLine($"Connected as {IpAdr}");
            }


            // Just wait for now
            // Here you would have the reset of your program using the client WiFI link
            Thread.Sleep(Timeout.Infinite);
        }
Esempio n. 2
0
        public static void Main()
        {
            Debug.WriteLine("Welcome to WiFI Soft AP world!");

            var     gpioController = new GpioController();
            GpioPin setupButton    = gpioController.OpenPin(SETUP_PIN, PinMode.InputPullUp);

            // If Wireless station is not enabled then start Soft AP to allow Wireless configuration
            // or Button pressed
            if (!Wireless80211.IsEnabled() || (setupButton.Read() == PinValue.High))
            {
                Wireless80211.Disable();
                if (WirelessAP.Setup() == false)
                {
                    // Reboot device to Activate Access Point on restart
                    Debug.WriteLine($"Setup Soft AP, Rebooting device");
                    Power.RebootDevice();
                }

                Debug.WriteLine($"Running Soft AP, waiting for client to connect");
                Debug.WriteLine($"Soft AP IP address :{WirelessAP.GetIP()}");

                // Link up Network event to show Stations connecting/disconnecting to Access point.
                //NetworkChange.NetworkAPStationChanged += NetworkChange_NetworkAPStationChanged;
                // Now that the normal Wifi is deactivated, that we have setup a static IP
                // We can start the Web server
                server.Start();
            }
            else
            {
                Debug.WriteLine($"Running in normal mode, connecting to Access point");
                var conf = Wireless80211.GetConfiguration();

                bool success;

                // For devices like STM32, the password can't be read
                if (string.IsNullOrEmpty(conf.Password))
                {
                    // In this case, we will let the automatic connection happen
                    success = WiFiNetworkHelper.Reconnect(requiresDateTime: true, token: new CancellationTokenSource(60000).Token);
                }
                else
                {
                    // If we have access to the password, we will force the reconnection
                    // This is mainly for ESP32 which will connect normaly like that.
                    success = WiFiNetworkHelper.ConnectDhcp(conf.Ssid, conf.Password, requiresDateTime: true, token: new CancellationTokenSource(60000).Token);
                }

                if (success)
                {
                    Debug.WriteLine($"Connection is {success}");
                    Debug.WriteLine($"We have a valid date: {DateTime.UtcNow}");
                }
                else
                {
                    Debug.WriteLine($"Something wrong happened, can't connect at all");
                }
            }


            // Just wait for now
            // Here you would have the reset of your program using the client WiFI link
            Thread.Sleep(Timeout.Infinite);
        }