Exemplo n.º 1
0
        public static void Main()
        {
            var cont  = GpioController.GetDefault();
            var reset = cont.OpenPin(FEZ.GpioPin.WiFiReset);
            var irq   = cont.OpenPin(FEZ.GpioPin.WiFiInterrupt);
            var mode  = cont.OpenPin(FEZCLR.GpioPin.PA0);
            var scont = SpiController.FromName(FEZ.SpiBus.WiFi);
            var spi   = scont.GetDevice(SPWF04SxInterface.GetConnectionSettings(SpiChipSelectType.Gpio, FEZ.GpioPin.WiFiChipSelect));

            mode.SetDriveMode(GpioPinDriveMode.InputPullDown);

            led1 = cont.OpenPin(FEZ.GpioPin.Led1);
            led1.SetDriveMode(GpioPinDriveMode.Output);

            btn1 = cont.OpenPin(FEZ.GpioPin.Btn1);
            btn1.SetDriveMode(GpioPinDriveMode.InputPullUp);

            wifi = new SPWF04SxInterface(spi, irq, reset);

            wifi.IndicationReceived += (s, e) => Debug.WriteLine($"WIND: {Program.WindToName(e.Indication)} {e.Message}");
            wifi.ErrorReceived      += (s, e) => Debug.WriteLine($"ERROR: {e.Error} {e.Message}");

            wifi.TurnOn();

            NetworkInterface.ActiveNetworkInterface = wifi;

            WaitForButton();
            wifi.JoinNetwork("SSID", "password");

            WaitForButton();
            wifi.ClearTlsServerRootCertificate();
            wifi.SetTlsServerRootCertificate(Resources.GetBytes(Resources.BinaryResources.DigiCertGlobalRootCA));

            while (true)
            {
                WaitForButton();

                //.NET
                TestSocket("www.ghielectronics.com", "/", 443, "ghielectronics.com");

                //WiFi
                //TestHttp("www.ghielectronics.com", "/", 443, SPWF04SxConnectionSecurityType.Tls, true);
                //TestSocket("www.ghielectronics.com", "/", 443, SPWF04SxConnectionType.Tcp, SPWF04SxConnectionSecurityType.Tls, "ghielectronics.com");
            }
        }