Network samples?

hello John,

I haven’t updated the firmware of the WIFI, only the FEZ itself. I received the board last week from Mouser, so I’m not sure what version it is supposed to have.
I saw that the WIFI module is now end of life. so I will stay tuned on GHI steps on that matter.

About GitHub, I was able to download the repos (tinyclr-ports, tinyclr-samples and tiniclr-drivers) but I was expecting a full repo that has all the components in a single repo. At this moment I am not able to run my project and includes the drivers (it still use nuget).
I will read carefully the link you send and play around that,

thanks !

We do recommend updating the firmware on the Wi-Fi module, http://docs.ghielectronics.com/hardware/components/spwf04sa.html has some steps on how to do that.

So to work with the source for the Wi-Fi driver, you only need the drivers repo. You can just add the SPWF04Sx project to your own solution, then add a reference to that project in your project (you may need to uninstall then reinstall the NuGet packages). Alternatively, just take the source files for the Wi-Fi and add them to your project.

2 Likes

Just want to set expectations here… but I am an outsider, I don’t represent GHI…

Just because a part becomes EOL, does not mean GHI will do anything about current inventory or already produced units. Those are what they are, they’re complete and in the market. They may also have completed a purchase of more inventory of wifi modules waiting to be assembled, which again doesn’t change anything for anyone. GHI have shown over the years that they stand behind their products as long as possible, longer than many others, and so I expect you will see continuing support for Fez devices with that wifi module on in TinyCLR for some time to come, at a software level. You as a new owner just need to realise that sometime in the future GHI will release a new product with a new wifi module, that will be different to your current one. No problem really, but there will be nothing for you or GHI to do, no “steps on that matter”

3 Likes

To add wifi access point (open), here is the portion of code to add to SPWF04SxInterface.cs:

The default IP is 192.168.5.1, when connecting to this IP, will show an web UI that allow to define all network wifi settings.

	public void CreateOpenMiniAP(string ssid)
	{
		this.DisableRadio();

		var cmd = this.GetCommand()
			.AddParameter("wifi_mode")
			.AddParameter("3")
			.Finalize(SPWF04SxCommandIds.SCFG);
		this.EnqueueCommand(cmd);
		cmd.ReadBuffer();
		this.FinishCommand(cmd);

		cmd = this.GetCommand()
			.AddParameter("wifi_priv_mode")
			.AddParameter("0")
			.Finalize(SPWF04SxCommandIds.SCFG);
		this.EnqueueCommand(cmd);
		cmd.ReadBuffer();
		this.FinishCommand(cmd);

		cmd = this.GetCommand()
			.AddParameter("wifi_auth_type")
			.AddParameter("0")
			.Finalize(SPWF04SxCommandIds.SCFG);
		this.EnqueueCommand(cmd);
		cmd.ReadBuffer();
		this.FinishCommand(cmd);

		cmd = this.GetCommand()
			.AddParameter("wifi_channelnum")
			.AddParameter("1")
			.Finalize(SPWF04SxCommandIds.SCFG);
		this.EnqueueCommand(cmd);
		cmd.ReadBuffer();
		this.FinishCommand(cmd);

		cmd = this.GetCommand()
			.AddParameter("ip_ipaddr")
			.AddParameter("192.168.5.1")
			.Finalize(SPWF04SxCommandIds.SCFG);
		this.EnqueueCommand(cmd);
		cmd.ReadBuffer();
		this.FinishCommand(cmd);

		cmd = this.GetCommand()
			.AddParameter(ssid)
			.Finalize(SPWF04SxCommandIds.SSIDTXT);
		this.EnqueueCommand(cmd);
		cmd.ReadBuffer();
		this.FinishCommand(cmd);

		this.EnableRadio();

		cmd = this.GetCommand()
			.Finalize(SPWF04SxCommandIds.WCFG);
		this.EnqueueCommand(cmd);
		cmd.ReadBuffer();
		this.FinishCommand(cmd);
	}
1 Like

hello John,

I need your opinion, I started to write a few queries to get variables value (like the MAC or the serial number).
please let me know what you think of the 2 functions below.

basically I was thinking of 3 options :
create a function per variable
or create a generic function that cover all variable and return an array
or alternatively, return only the value of the variable we pass in parameters. (we have to keep in mind some are int and some are strings
what would you think ?

thanks !

public string QueryMACAddr()
{
var cmd = this.GetCommand()
.AddParameter(“nv_wifi_macaddr”)
.Finalize(SPWF04SxCommandIds.GCFG);

		this.EnqueueCommand(cmd);

		cmd.ReadBuffer();

		var str = string.Empty;
		while (cmd.ReadString() is var s && s != string.Empty)
			str += s;

		this.FinishCommand(cmd);
		
		return str.TrimEnd('\r', '\n'); ;
	}

	public string QuerySerialNumber()
	{
		var cmd = this.GetCommand()
			.AddParameter("nv_serial")
			.Finalize(SPWF04SxCommandIds.GCFG);

		this.EnqueueCommand(cmd);

		var result = cmd.ReadString().Split('=');
		//string serialnb = result[1];
		//serialnb = serialnb.TrimEnd('\r', '\n');

		cmd.ReadBuffer();

		this.FinishCommand(cmd);

		return result[1].TrimEnd('\r', '\n'); ;
	}

So if I were adding this I’d probably do it like so:

public delegate void CommandCallback(SPWF04SxCommand cmd);

public void ReadConfiguration(string variable, CommandCallback callback) {
    var cmd = this.GetCommand()
                  .AddParameter(variable)
                  .Finalize(SPWF04SxCommandIds.GCFG);

    this.EnqueueCommand(cmd);

    callback.Invoke(cmd);

    this.FinishCommand(cmd);
}

public string ReadSerialNumber() {
    var res = "";

    this.ReadConfiguration("nv_serial", cmd => {
        res = cmd.ReadString();
        cmd.ReadBuffer();
    });

    return res.Split('=')[1].TrimEnd('\r', '\n');
}

I’ve not actually ran the above code, but it’s the rough idea. If we had generics the delegate could be generic over the return type and I could return directly instead of using shared state like I do.

2 Likes

I give a new try with TinyClr-Drivers (lastest changes) and all seems working very well with new firmware (171117-0328fe3-SPWF04S) !
Good job as usual at GHI. Now I can reach my http site.

Next step is to try httpS.

4 Likes

@John_Brochue:
Few question about https:

  • certificate in resources must be a crt or pem file ?
  • when it is a chain of certificate, Which one must be given ? Root, intermediate, or final one ?
1 Like

Hi, I can only say how it is in NetMF. The certificate in the resources had to have the extension .cer and the root certificate had to be used.

Kind regards
RoSchmi

Our driver currently only supports the DER format (which is usually found on Windows with a crt extension). The Wi-Fi module itself supports PEM, but our driver does not.

In the common case you only need to load the root certificate (the module also supports client authentication, but our driver currently does not). For example, if you were trying to connect to our main site, the SSL cert you’d want from our chain is DigiCert Global Root CA with a SHA1 fingerprint of A8:98:5D:3A:65:E5:E5:C4:B2:D7:D6:6D:40:C6:DD:2F:B1:9C:54:36.

The following may be useful to you.

2 Likes

@John_Brochue thank you for this.
I have implemented this code and apart from having to change void to string in the declaration of ReadSerialNumber() it works.

1 Like

Thanks for the catch, I updated the snippet

It’s working ! I can now get https on few site. TinyClr can now be tagged ‘IoT’ ! :hugs:

5 Likes

I confirm that UC5550 Wifi is working in SSL using root certificate after fw update.

3 Likes

With preview3 in release notes:

SPWF04Sx Wi-Fi on the FEZ does not work unless PA0 is manually set low before initialization

are these lines correct (I can’t join network) ?

            var _pa0 = cont.OpenPin(FEZ.GpioPin.A0);
            _pa0.SetDriveMode(GpioPinDriveMode.Output);
            _pa0.Write(GpioPinValue.Low);
2 Likes

yes, or

var _pa0 = cont.OpenPin(FEZ.GpioPin.A0);
_pa0.SetDriveMode(GpioPinDriveMode.InputPullDown);

Can’t join network should be a different thing.

Indeed, I receive no message from wifi module such ActiveConsole …

You have the wrong pin, you have A0 which is the first pin on the analog Arduino-style header. You want PA0: FEZCLR.GpioPin.PA0.

1 Like

You are the King ! I’m an idiot … It is working !
So:

var _pa0 = cont.OpenPin(FEZCLR.GpioPin.PA0);
_pa0.SetDriveMode(GpioPinDriveMode.InputPullDown);

do perfectly the job !

I just acquired two FEZ boards from Mouser and needed to update the firmware on the WiFi module. All the instructions on the GHI site for updating the WiFi firmware (https://docs.ghielectronics.com/hardware/components/spwf04sa.html#flash-the-wi-fi-module) are correct except for one missing step. Right before you plug the FEZ back into to the computer (use the computer for power via USB) after clearing the FEZ (Tinyclr Config works great), hold the reset button on the FEZ down, then plug in the USB power for the FEZ, then plug in the USB/Serial (TTL) cable, then start the ST Demonstrator GUI program. Keep holding the button until the ST Demonstrator GUI connects to the WiFi module which requires a few ‘Next’ button presses, then release the reset button and one can then program the WiFi with the newer code. In the GHI instructions, this button press and hold would be right below the picture of the serial wiring on the FEZ board. User’s choice, but I always check the verify download. The process took just a bit more than 15 minutes. Once I reprogrammed the WiFi, I was able to run the test programs and was able to pull down a webpage from Google using an unsecure access via port 80. No issues whatsoever with the WiFi or the board, so far…:slight_smile: Still working on secure access.

3 Likes