public static void Main() { var cont = GpioController.GetDefault(); //FEZ //var reset = cont.OpenPin(FEZ.GpioPin.WiFiReset); //var irq = cont.OpenPin(FEZ.GpioPin.WiFiInterrupt); //var scont = SpiController.FromName(FEZ.SpiBus.WiFi); //var spi = scont.GetDevice(SPWF04SxInterface.GetConnectionSettings(SpiChipSelectType.Gpio, FEZ.GpioPin.WiFiChipSelect)); //led1 = cont.OpenPin(FEZ.GpioPin.Led1); //btn1 = cont.OpenPin(FEZ.GpioPin.Btn1); //UC5550 var reset = cont.OpenPin(UC5550.GpioPin.PG12); var irq = cont.OpenPin(UC5550.GpioPin.PB11); var scont = SpiController.FromName(UC5550.SpiBus.Spi5); var spi = scont.GetDevice(SPWF04SxInterface.GetConnectionSettings(SpiChipSelectType.Gpio, UC5550.GpioPin.PB10)); led1 = cont.OpenPin(UC5550.GpioPin.PD3); btn1 = cont.OpenPin(UC5550.GpioPin.PB2); led1.SetDriveMode(GpioPinDriveMode.Output); 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; Run(); }
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"); } }
static void Main() { TouchSensor touch = new TouchSensor(FEZ.GpioPin.D7); LightSensor light = new LightSensor(FEZ.AdcChannel.A3); ServoMotor servo = new ServoMotor(FEZ.PwmPin.Controller4.Id, FEZ.PwmPin.Controller4.D5); Buzzer buzz = new Buzzer(FEZ.GpioPin.D4); LcdRgbBacklight lcd = new LcdRgbBacklight(); host = "192.168.1.152"; port = 80; var buffer = new byte[512]; var cont = GpioController.GetDefault(); var reset = cont.OpenPin(FEZ.GpioPin.WiFiReset); var irq = cont.OpenPin(FEZ.GpioPin.WiFiInterrupt); var spi = SpiDevice.FromId(FEZ.SpiBus.WiFi, SPWF04SxInterface.GetConnectionSettings(FEZ.GpioPin.WiFiChipSelect)); connected = false; socketOpened = false; garageLed = cont.OpenPin(FEZ.GpioPin.D2); servo.SetPosition(180); garageLed.SetDriveMode(GpioPinDriveMode.Output); 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(); //wifi.JoinNetwork("GHI", "ghi555wifi."); lcd.Clear(); lcd.SetBacklightRGB(100, 100, 100); lcd.Write("Time:"); while (!connected) { ListenWind(); Thread.Sleep(200); } StringBuilder builder = new StringBuilder(); while (connected) { if (!socketOpened) { id = wifi.OpenSocket(host, port, SPWF04SxConnectionyType.Tcp, SPWF04SxConnectionSecurityType.None); socketOpened = true; } var hour = DateTime.UtcNow.Hour; var minute = DateTime.UtcNow.Minute; var second = DateTime.UtcNow.Second; lcd.SetCursor(7, 1); lcd.Write($"{hour}:{minute}:{second}"); if (touch.IsTouched()) { wifi.WriteSocket(id, Encoding.UTF8.GetBytes("Someone wants to open the garage")); } if (light.ReadLightLevel() > 60 && isDoorOpened == true) { //Debug.WriteLine(light.ReadLightLevel().ToString()); wifi.WriteSocket(id, Encoding.UTF8.GetBytes("Car in the garage")); while (light.ReadLightLevel() > 60) { Thread.Sleep(50); } wifi.WriteSocket(id, Encoding.UTF8.GetBytes("You can close the garage")); } if (wifi.QuerySocket(id) is var avail && avail > 0) { wifi.ReadSocket(id, buffer, 0, Math.Min(avail, buffer.Length)); for (var k = 0; k < buffer.Length; k++) { if (buffer[k] != 0) { char result = (char)buffer[k]; builder.Append(result); buffer[k] = 0; } } Debug.WriteLine(builder.ToString()); } string command = builder.ToString(); builder.Clear(); switch (command) { case "open": buzz.Beep(); servo.SetPosition(0); garageLed.Write(GpioPinValue.High); isDoorOpened = true; break; case "close": buzz.Beep(); servo.SetPosition(180); garageLed.Write(GpioPinValue.Low); break; default: break; } Thread.Sleep(100); } }
static void Main() { var buffer = new byte[512]; DIRA = GpioController.GetDefault().OpenPin(FEZ.GpioPin.D2); DIRA.SetDriveMode(GpioPinDriveMode.Output); DIRB = GpioController.GetDefault().OpenPin(FEZ.GpioPin.D4); DIRB.SetDriveMode(GpioPinDriveMode.Output); var cont = GpioController.GetDefault(); var reset = cont.OpenPin(FEZ.GpioPin.WiFiReset); var irq = cont.OpenPin(FEZ.GpioPin.WiFiInterrupt); var spi = SpiDevice.FromId(FEZ.SpiBus.WiFi, SPWF04SxInterface.GetConnectionSettings(FEZ.GpioPin.WiFiChipSelect)); led1 = cont.OpenPin(FEZ.GpioPin.Led1); btn1 = cont.OpenPin(FEZ.GpioPin.Btn1); led1.SetDriveMode(GpioPinDriveMode.Output); btn1.SetDriveMode(GpioPinDriveMode.InputPullUp); wifi = new SPWF04SxInterface(spi, irq, reset); wifi.TurnOn(); //wifi.JoinNetwork("GHI", "ghi555wifi."); Debug.WriteLine("WaitForButton"); WaitForButton(); var speed = 90; var id = wifi.OpenSocket("192.168.1.152", 80, SPWF04SxConnectionyType.Tcp, SPWF04SxConnectionSecurityType.None); StringBuilder builder = new StringBuilder(); while (true) { if (wifi.QuerySocket(id) is var avail && avail > 0) { wifi.ReadSocket(id, buffer, 0, Math.Min(avail, buffer.Length)); for (var k = 0; k < buffer.Length; k++) { if (buffer[k] != 0) { char result = (char)buffer[k]; builder.Append(result); buffer[k] = 0; } } Debug.WriteLine(builder.ToString()); } string command = builder.ToString(); builder.Clear(); switch (command) { case "forvard": SetMotorDuty(Servo.A, speed, Direction.Forvard); SetMotorDuty(Servo.B, speed, Direction.Forvard); break; case "backward": SetMotorDuty(Servo.A, speed, Direction.Back); SetMotorDuty(Servo.B, speed, Direction.Back); break; case "left": SetMotorDuty(Servo.A, speed, Direction.Forvard); StopMotor(Servo.B); Thread.Sleep(500); break; case "right": SetMotorDuty(Servo.B, speed, Direction.Forvard); StopMotor(Servo.A); Thread.Sleep(500); break; case "stop": StopMotor(Servo.B); StopMotor(Servo.A); Thread.Sleep(500); break; default: break; } Thread.Sleep(100); } }