ahalim
1
I am looking at this sample code from the tutorial page:
https://docs.ghielectronics.com/software/tinyclr/tutorials/wifi.html
The comment says this code is for fez portal.
Would it work for fezduino? Are there any changes I need to make for it to work?
thanks
Not much changes needed, just the pins. This should also work with the bit and feather.
class Program
{
static void Main()
{
var enablePin = GpioController.GetDefault().OpenPin(GHIElectronics.TinyCLR.Pins.SC20100.GpioPin.PA8);
enablePin.SetDriveMode(GpioPinDriveMode.Output);
enablePin.Write(GpioPinValue.High);
var cs = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PD15);
SpiNetworkCommunicationInterfaceSettings netInterfaceSettings = new SpiNetworkCommunicationInterfaceSettings();
var settings = new SpiConnectionSettings()
{
ChipSelectLine = cs,
ClockFrequency = 4000000,
Mode = SpiMode.Mode0,
ChipSelectType = SpiChipSelectType.Gpio,
ChipSelectHoldTime = TimeSpan.FromTicks(10),
ChipSelectSetupTime = TimeSpan.FromTicks(10)
};
netInterfaceSettings.SpiApiName = SC20100.SpiBus.Spi3;
netInterfaceSettings.GpioApiName = SC20100.GpioPin.Id;
netInterfaceSettings.SpiSettings = settings;
netInterfaceSettings.InterruptPin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PB12);
netInterfaceSettings.InterruptEdge = GpioPinEdge.FallingEdge;
netInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp;
netInterfaceSettings.ResetPin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PB13);
netInterfaceSettings.ResetActiveState = GpioPinValue.Low;
var networkController = NetworkController.FromName("GHIElectronics.TinyCLR.NativeApis.ATWINC15xx.NetworkController");
WiFiNetworkInterfaceSettings wifiSettings = new WiFiNetworkInterfaceSettings()
{
Ssid = "ssid",
Password = "password",
};
// wifiSettings.Address = new IPAddress(new byte[] { 192, 168, 1, 122 });
// wifiSettings.SubnetMask = new IPAddress(new byte[] { 255, 255, 255, 0 });
// wifiSettings.GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 });
// wifiSettings.DnsAddresses = new IPAddress[] { new IPAddress(new byte[]
//{ 75, 75, 75, 75 }), new IPAddress(new byte[] { 75, 75, 75, 76 }) };
wifiSettings.IsDhcpEnabled = true;
wifiSettings.IsDynamicDnsEnabled = true;
wifiSettings.TlsEntropy = new byte[] { 0, 1, 2, 3 };
networkController.SetInterfaceSettings(wifiSettings);
networkController.SetCommunicationInterfaceSettings(netInterfaceSettings);
networkController.SetAsDefaultController();
networkController.NetworkAddressChanged += (NetworkController sender, NetworkAddressChangedEventArgs e) =>
{
var ipProperties = sender.GetIPProperties();
var address = ipProperties.Address.GetAddressBytes();
Debug.WriteLine("IP: " + address[0] + "." + address[1] + "." + address[2] +
"." + address[3]);
};
networkController.NetworkLinkConnectedChanged += NetworkController_NetworkLinkConnectedChanged;
networkController.Enable();
// Network is ready to used
Thread.Sleep(Timeout.Infinite);
}
private static void NetworkController_NetworkLinkConnectedChanged(NetworkController sender, NetworkLinkConnectedChangedEventArgs e)
{
}
private static void NetworkController_NetworkAddressChanged(NetworkController sender, NetworkAddressChangedEventArgs e)
{
var ipProperties = sender.GetIPProperties();
var address = ipProperties.Address.GetAddressBytes();
Debug.WriteLine("IP: " + address[0] + "." + address[1] + "." + address[2] +
"." + address[3]);
}
3 Likes
ahalim
3
Great. Thanks! I will give it a try.