Wifi questions

Hello,

Where can I find documention about the Wifi interface ?
I have a Wifi7 Click board, it looks like I can connect to my network, but I don’t know how to list available access points, for example.

Or perhaps there is a method to access “internal functions” of the module or should they be hand-coded ?

Regards,
Christophe

It is missing from docs. @Joel_Riley are you adding it today?

Will add to docs, but it looks like there might be a problem with the Scan() method – we’re looking into it.

This should help get you started. These methods are part of the static Winc15x0Interface class.

string[] ssidList = Winc15x0Interface.Scan() returns a list of found SSIDs, but we are looking into possible bug in this command.

int signalStrength = Winc15x0Interface.GetRssi() returns relative signal strength.

byte[] macAddress = Winc15x0Interface.GetMacAddress() returns the MAC address.

Sorry for the delay, the docs should be up soon along with instructions for updating the WiFi firmware.

1 Like

Thank you !

I will have a deeper look into it, then.

And call those before network.Enable()

We found an issue if call them after network.Enable().

Scan works, although it seems to miss some networks. I will have to dig into this to be 100% sure.

Also, there are other informations in the scan data returned by the module, like signal strength, channel, encryption and so on…
Could it be possible that the scan() method returns a struct/class with this information instead of simply a strings array ?

Choosing an AP using its signal strength or encryption method is useful.

today after 4 month of wait received from Mikroe Wifi 7 Click

and i tested sample from tutorial as is :

https://docs.ghielectronics.com/software/tinyclr/tutorials/wifi.html

but i’ve got strange results for this piece of code (part of DNS or i’m wrong)

       wifiSettings.Address = new IPAddress(new byte[] { 192, 168, 2, 122 });
        wifiSettings.SubnetMask = new IPAddress(new byte[] { 255, 255, 255, 0 });
        wifiSettings.GatewayAddress = new IPAddress(new byte[] { 192, 168, 2, 1 });
        wifiSettings.DnsAddresses = new IPAddress[] { new IPAddress(new byte[]
        { 8, 8, 8, 8 }), new IPAddress(new byte[] { 8, 8, 8, 4 }) };

            
        wifiSettings.MacAddress = new byte[] { 0x00, 0x4, 0x00, 0x00, 0x00, 0x00 };
        wifiSettings.IsDhcpEnabled = true;
        wifiSettings.IsDynamicDnsEnabled = true;
        wifiSettings.TlsEntropy = new byte[] { 0, 1, 2, 3 };

so whene i tried to retreive with code

      var ipProperties = sender.GetIPProperties();
        var address = ipProperties.Address.GetAddressBytes();
        var gateway = ipProperties.GatewayAddress.GetAddressBytes();
        var subnetmask = ipProperties.SubnetMask.GetAddressBytes();
            var dns1 = ipProperties.DnsAddresses[0].GetAddressBytes();
            var dns2 = ipProperties.DnsAddresses[1].GetAddressBytes();

            Debug.WriteLine("DNS Len"+ipProperties.DnsAddresses.Length.ToString());

            Debug.WriteLine("IP: " + address[0] + "." + address[1] + "." + address[2] + "." + address[3]);
            Debug.WriteLine("Gateway: " + gateway[0] + "." + gateway[1] + "." + gateway[2] + "." + gateway[3]);
            Debug.WriteLine("SubnetMsk: " + subnetmask[0] + "." + subnetmask[1] + "." + subnetmask[2] + "." + subnetmask[3]);
            Debug.WriteLine("DNS 1: " + dns1[0] + "." + dns1[1] + "." + dns1[2] + "." + dns1[3]);
            Debug.WriteLine("DNS 2: " + dns2[0] + "." + dns2[1] + "." + dns2[2] + "." + dns2[3]);

i’ve got wrong result - DNS1 - same as gateway ??

IP: 192.168.2.109
Gateway: 192.168.2.1
SubnetMsk: 255.255.255.0
DNS 1: 192.168.2.1
DNS 2: 8.8.8.8

did DNS should be
DNS 1:8.8.8.8
DNS 2:8.8.8.4

Are you sure of your AP/Router settings ?

Using your code, I get correct results on my side :

DNS Len2
IP: 192.168.0.19
Gateway: 192.168.0.254
SubnetMsk: 255.255.255.0
DNS 1: 9.9.9.9
DNS 2: 8.8.8.8

Edit: perhaps it’s not a fault, your router could act as a DNS server as well.

2 Likes

Thanks a lot you for fast answer you are right ,
it was come from router

# Set a static IP address (Otherwise defined from DHCP)
wifiSettings.Address = new IPAddress(new byte[] { 192, 168, 2, 122 });
# Your networks subnet Mask (Only needed if you plan to use a static IP. Otherwise defined from DHCP)
wifiSettings.SubnetMask = new IPAddress(new byte[] { 255, 255, 255, 0 });
# Your networks Gateway to internet (Only needed if you plan to use a static IP. Otherwise defined from DHCP)
wifiSettings.GatewayAddress = new IPAddress(new byte[] { 192, 168, 2, 1 });
# Your networks DNS servers (Only need to change if you wish to not use DHCP DNS info)
wifiSettings.DnsAddresses = new IPAddress[] { new IPAddress(new byte[]
{ 8, 8, 8, 8 }), new IPAddress(new byte[] { 8, 8, 8, 4 }) };

#Warning: if you use this you may get exceptions thrown. Best to comment out.
wifiSettings.MacAddress = new byte[] { 0x00, 0x4, 0x00, 0x00, 0x00, 0x00 };
# This enabled DHCP. Set to False if you wish to set a static IP from "wifiSettings.Address"
wifiSettings.IsDhcpEnabled = true;
# This pulls your DNS info from your DHCP router. Set to false if you wish to use defined DNS entries from wifiSettings.DnsAddresses.
wifiSettings.IsDynamicDnsEnabled = true;

1 Like

Yeb, wifi has own mac address, no need define again.
But SCore doesn’t mind if you do that, how did you get exception?

I have the Fez Duino.
Thinking you have to set the MAC address.
If you make the mistake of changing the mac address to the existing MAC on the wifi module it will throw an exception on networkconroller.Enable();

namespace WebButtons
{
    public class Wifi
    {
        ~Wifi()
        {
            
        }
        public void LoadWifi()
        {
            var enablePin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PA8);
            enablePin.SetDriveMode(GpioPinDriveMode.Output);
            enablePin.Write(GpioPinValue.High);

            SpiNetworkCommunicationInterfaceSettings netInterfaceSettings =
                new SpiNetworkCommunicationInterfaceSettings();

            var cs = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PD15);

            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 = "CIA",
                Password = "Langley",
            };

            wifiSettings.Address = new IPAddress(new byte[] { 192, 168, 55, 220 });
            wifiSettings.SubnetMask = new IPAddress(new byte[] { 255, 255, 254, 0 });
            wifiSettings.GatewayAddress = new IPAddress(new byte[] { 192, 168, 55, 1 });
            wifiSettings.DnsAddresses = new IPAddress[] { new IPAddress(new byte[]
        { 192, 168, 55, 22 }) };

            //wifiSettings.MacAddress = new byte[] { 0xFB, 0xF0, 0x05, 0x75, 0x75, 0xFD };
            wifiSettings.IsDhcpEnabled = false;
            wifiSettings.IsDynamicDnsEnabled = false;
            wifiSettings.TlsEntropy = new byte[] { 0, 1, 2, 3 };

            networkController.SetInterfaceSettings(wifiSettings);
            networkController.SetCommunicationInterfaceSettings(netInterfaceSettings);
            networkController.SetAsDefaultController();

            networkController.NetworkAddressChanged += NetworkController_NetworkAddressChanged;

            networkController.NetworkLinkConnectedChanged +=
                NetworkController_NetworkLinkConnectedChanged;
      
            try
            {
                networkController.Enable();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
            // Network is ready to used
            Thread.Sleep(Timeout.Infinite);
        }

        private static void NetworkController_NetworkLinkConnectedChanged
            (NetworkController sender, NetworkLinkConnectedChangedEventArgs e)
        {
            // Raise event connect/disconnect
        }

        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]);
        }
        // public static SelectServiceWindow SelectServicePage { get; set; }
       
    }

}