Skip to main content

WiFi

SITCore products include native support for the Microchip ATWINC1500 family of WiFi modules — pre-certified by FCC, CE, and other regulatory agencies. Communication between SITCore and the WiFi module is over SPI, not AT commands, so the module sees only encrypted data.

info

All TLS and network cryptography runs inside SITCore, not inside the WiFi module. The data going over SPI is already encrypted — the WiFi module simply transmits it.

ATWINC1500 and ATWINC1510 are functionally identical for TinyCLR's purposes; the 1510 just has more memory that isn't used. The tested firmware revision is ATWINC1500-MR210PB — other firmware versions can be used, but you may need to update the firmware first (see WINC1500 utilities below).

NuGet packages:

  • GHIElectronics.TinyCLR.Devices.Network — networking stack
  • GHIElectronics.TinyCLR.Devices.Spi — SPI used to talk to the WiFi module
  • GHIElectronics.TinyCLR.Devices.Gpio — control lines (enable, reset, interrupt)
  • GHIElectronics.TinyCLR.Pins — pin constants
  • GHIElectronics.TinyCLR.Drivers.Microchip.Winc15x0 — driver helpers (scan, RSSI, OTA, multicast); only needed when using those features

Connecting to a network

The example below targets the FEZ Portal with its built-in WINC1500. If you're wiring up a bare module instead, connect SPI (MOSI, MISO, SCK) plus interrupt, reset, and chip-select lines to the SITCore.

tip

If using the MikroE WiFi 7 click board, the module's enable pin must be pulled high.

tip

The MAC address can be overridden through the WiFi settings, but the factory-assigned MAC is usually the right choice.

using System;
using System.Diagnostics;
using System.Threading;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Network;
using GHIElectronics.TinyCLR.Devices.Spi;
using GHIElectronics.TinyCLR.Pins;

var enablePinNumber = FEZBit.GpioPin.WiFiEnable;
var chipSelectPinNumber = FEZBit.GpioPin.WiFiChipselect;
var irqPinNumber = FEZBit.GpioPin.WiFiInterrupt;
var resetPinNumber = FEZBit.GpioPin.WiFiReset;
var spiControllerName = FEZBit.SpiBus.WiFi;
var gpioControllerName = SC20100.GpioPin.Id;

// Power the WiFi module.
var enablePin = GpioController.GetDefault().OpenPin(enablePinNumber);
enablePin.SetDriveMode(GpioPinDriveMode.Output);
enablePin.Write(GpioPinValue.High);

// SPI line settings for talking to the WiFi module.
var chipSelect = GpioController.GetDefault().OpenPin(chipSelectPinNumber);

var spiSettings = new SpiConnectionSettings(){
ChipSelectLine = chipSelect,
ClockFrequency = 4_000_000,
Mode = SpiMode.Mode0,
ChipSelectType = SpiChipSelectType.Gpio,
ChipSelectHoldTime = TimeSpan.FromTicks(10),
ChipSelectSetupTime = TimeSpan.FromTicks(10),
};

// Communication interface settings — SPI plus the IRQ and Reset pins.
var netInterfaceSettings = new SpiNetworkCommunicationInterfaceSettings{
SpiApiName = spiControllerName,
SpiSettings = spiSettings,
GpioApiName = gpioControllerName,

InterruptPin = GpioController.GetDefault().OpenPin(irqPinNumber),
InterruptEdge = GpioPinEdge.FallingEdge,
InterruptDriveMode = GpioPinDriveMode.InputPullUp,

ResetPin = GpioController.GetDefault().OpenPin(resetPinNumber),
ResetActiveState = GpioPinValue.Low,
};

// WiFi credentials and DHCP.
var wifiSettings = new WiFiNetworkInterfaceSettings(){
Ssid = "Your SSID",
Password = "Your Password",
DhcpEnable = true,
DynamicDnsEnable = true,
};

var networkController = NetworkController.FromName(SC20260.NetworkController.ATWinc15x0);

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

networkController.NetworkAddressChanged += NetworkController_NetworkAddressChanged;
networkController.NetworkLinkConnectedChanged += NetworkController_NetworkLinkConnectedChanged;

networkController.Enable();

// Network is ready — keep the main thread alive.
Thread.Sleep(Timeout.Infinite);

void NetworkController_NetworkLinkConnectedChanged(NetworkController sender, NetworkLinkConnectedChangedEventArgs e){
Debug.WriteLine(e.Connected ? "Link connected" : "Link disconnected");
}

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]);
}

WINC1500 utilities

The Winc15x0Interface class (in the GHIElectronics.TinyCLR.Drivers.Microchip.Winc15x0 driver package) exposes WINC1500-specific operations: access point scanning, RSSI, MAC address, firmware version, and over-the-air (OTA) firmware updates.

note

SetCommunicationInterfaceSettings must be called on the network controller before using any Winc15x0Interface method.

using System;
using System.Diagnostics;
using GHIElectronics.TinyCLR.Drivers.Microchip.Winc15x0;

// Scan for nearby access points.
string[] ssidList = Winc15x0Interface.Scan();

// Signal strength of the currently connected access point.
int signalStrength = Winc15x0Interface.GetRssi();

// WiFi module's MAC address.
byte[] macAddress = Winc15x0Interface.GetMacAddress();

// Currently installed WiFi firmware version.
string fwVersion = Winc15x0Interface.GetFirmwareVersion();

// Firmware versions known to work with TinyCLR.
// (Other versions may also work — these are the tested ones.)
for (int i = 0; i < Winc15x0Interface.FirmwareSupports.Length; i++) {
Debug.WriteLine("Supported firmware version #" + (i + 1) + ": " + Winc15x0Interface.FirmwareSupports[i]);
}

// OTA firmware update — point at a URL serving the .bin file from a reachable web server.
// Example: http://192.168.0.100/m2m_ota_3a0.bin
bool otaUpdate = Winc15x0Interface.FirmwareUpdate("http://192.168.0.100/m2m_ota_3a0.bin", TimeSpan.FromMilliseconds(5000));

Multicast IP

Multicast works out-of-the-box on Ethernet and other transports. The WINC1500 needs the multicast IP address translated to its corresponding multicast MAC address and registered with the module. Online tools (such as DQ Networks' multicast addressing helper) handle the conversion.

For example, multicast IP 239.255.255.254 maps to MAC 01:00:5e:7f:ff:fe:

Multicast IP to MAC converter

Register the multicast MAC with the WINC1500 driver:

Winc15x0Interface.AddMulticastMacAddress(new byte[] { 0x01, 0x00, 0x5e, 0x7f, 0xff, 0xfe });

Multiple multicast addresses can be registered — just call AddMulticastMacAddress once for each. Use RemoveMulticastMacAddress to take one off the list:

Winc15x0Interface.RemoveMulticastMacAddress(new byte[] { 0x01, 0x00, 0x5e, 0x7f, 0xff, 0xfe });

NuGet package needed for multicast: GHIElectronics.TinyCLR.Drivers.Microchip.Winc15x0.

API reference

NamespaceDescription
GHIElectronics.TinyCLR.Devices.NetworkNetwork interface controller for WiFi