IoT with FEZ rules them all

Hi RoSchmi,

I have now used: if (Wifi.State == SPWF04SxWiFiState.ReadyToTransmit) and everything works reliable at the moment. Thank very much for the hint!

In the mean I can receive incoming sockets and read the data entered in the SP Google app over the public internet. I have only added:
public int OpenServerSocket(int port, SPWF04SxConnectionType connectionType, SPWF04SxConnectionSecurityType connectionSecurity)
and
public int ReadServerSocket(int SockIdServer, int SockIdClient, byte[] buffer, int buflen=0)

Next: to implement: WriteServerSocket and CloseServerSocket.

So nearly ready to start!

Best Regards,
Aart

1 Like

Hi all,

I would let you know that everything has been solved! I have added OpenServerSocket, ReadServerSocket, WriteServerSocket and SocketClientGone to the GHI ST Wifi driver. With tests with SP Google app last problem was when SP closses the socket (after a time out). In that case the wait for: SPWF04SxIndication.PendingData: had to be stopped on the event: SPWF04SxIndication.SocketClientGone so that SP can reconnect. Last test will be with multiple SP clients (module support max 8 sockets). After that I can start the IoT with FEZ rules them all board.

Thanks a lot for all the help!

Best Regards,
Aart

2 Likes

Sorry this text:

had to be:
WriteServerSocket and CloseServerSocket to the

1 Like

Thanks for posting your results. Would be very nice if you could post some code on Github or elsewhere for download.

2 Likes

Hi RoSchmi,

The new functions are merely copies of the existing ones in the GHI SPWF04SxInterface.cs file but changed with the needed AT command. But if you want them it is OK. Where I ahd tom upload?

May be I should finish the orher functions first. I have allready made the MiniAP mode functions and I can use the FEZ as an AP now. I that this the mode after a reset with an easy predefined IP. This actualy works. I have the AP now with IP: 222.222.222.222 and my phone gets IP 222.222.222.223.

Strange thing is that this din’t work with a Winoows phone but it did with an Android. With this the user should be able to join an existing network or keep this ip for ad hoc device control. This user config had to be remembered but also flash and memory function are not implemented. Also after a reset the device had to return to the MiniAP mode with the easy IP address.

In had read everything about the memory and flash control functions of the ST Wifi module. Mentioned was that this module is obsolete?

Best Regards,
Aart

Yes sir. Replacing the ST WiFi Modules

@aartastona Yes, I think it is the best to post the code when all intended functions are ready. A good place to upload is Github.
@Gus_Issa Curios that STM stopped SPWF04SA without having a successor. Is there any information if they are going to have a successor in the next time and why the gave up this product. How about your efforts to find another WiFi module?

Hi RoSchmi,

Thanks for your reply! At ST there is still a living discussion about the SPWF04S but nobody seems to ask, May be it should be asked there? ST Community

I will upload to Githup teh additions to the GHI SPWF04S driver. I think I had to use GHI’s code sign assembly? This I had to remove first to be able to use the GHI driver VS 2017 solution.

The code to use the ST Socket Server I will post here. Here are some special thing to watch and use the WIND event in harmony.

Best Regards,
Aart

We have a lot of work done internally but can’t share anything yet. The guys made me promise.

Gus, Gus, Gus… When has this ever stopped you ?

2 Likes

Hi RoSchmi,

Should I ask at the ST forum about EOL of SPWF04S?

Also just discovered that the with STS command the status of “reset_reason” allways returns 4 (=hardware reset). Gives the FEZ board a hard reset to the Wifi module at power on?

Thanks for knowledge!

Regards,
Aart

According to the eol report front ST a part used on their module has been eol’d.

Seems odd to me…

1 Like

Somebody asked already… but with no answer from STM.

I don’t know. I’m just exploring the module myself.

Lol. I wish they can be at least honest about it.

I reckon…

It is not easy to find out why unless you know what to search for (SPWF04S PCN).

So from the PCN the part has “Standard Mutiple Source” with no suggested repleacement part…

Like i said… Odd

2 Likes

Are these the successors of STM SPWF04Sx ?
https://www.inventeksys.com/uncategorized/azure-iot-cloud/

@aartastona
Hi, there is just a discussion about adding some commands to the GHI SPWF04SA WiFi driver.
If you could post your commands for socket server applications they could be discussed to be part of an evt. future release of the library.

Hi RoSchmi,

I didn’t work on this lately. I have made an android app to switch the leds on or off and read te status, This works. If you put led1 on on one phone you can see it a few moments later on other phones. Next by pressing btn1 the FEZ becames a AP with a predefined IP address and port number. Once connected directly you can join a wifi network. In that case the FEZ gets its IP from the network. The last 3 digits of the IP4 will be made configurable so that the user know which IP is to be used. Everything work well for some hours and the it hangs in the GHI Wifi driver at an semaphore implementation at overwritten function: WaitOne. I had to look up the details again.

The added driver functions are available. Do you want the signatures of the added function or also the implemetations. And where do I make them available? Here?

Best regards,
Aart

Hi @aartastona
thanks, nice project.
If you have made additional commands that could be valuable for others (e.g. socket server commands) we could ask GHI to include them in the official driver.
I think that if there are not to many commands you could post them here in the form like this example:

        public void ClearTlsServerRootCertificate() {
        var cmd = this.GetCommand()
            .AddParameter("content")
            .AddParameter("2")
            .Finalize(SPWF04SxCommandIds.TLSCERT);

        this.EnqueueCommand(cmd);

        cmd.ReadBuffer();
        cmd.ReadBuffer();
        this.FinishCommand(cmd);
    }

Best regards
RoSchmi

Hi RoSchmi,

I have added the following functions to the SPWF04SxInterface class in the file: SPWF04SxInterface.cs:

public int OpenServerSocket(int port, SPWF04SxConnectionType connectionType, SPWF04SxConnectionSecurityType connectionSecurity)
public int ReadServerSocket(int SockIdServer, int SockIdClient, byte[] buffer, int buflen = 0)
public void WriteServerSocket(int SockIdServer, int SockIdClient, byte[] buffer, int buflen)
public void CloseServerSocket(int SockIdServer, int SockIdClient = -1)
public string GetStatus(string sts_var)
public string GetConfigValue(string cfg_var)
public void SetConfigValue(string cfg_var, string newval)
public string GetSSID()
public void SetMiniAP(string ssid, string password, string ipaddress = null)

The implementatation of these functions will be send in the next message.

Furthermore the Semaphore class (see below) in the file: Helpers.cs was modified several times without solving the problem. After several hours, depending on the socket requests frequency (more phones / clients sending sockets) the driver hangs. In that case the software loops forever because: this.evt.WaitOne(33, false) allways return false. I have changed form 10 to 33ms and seems somewaht to gelp. When it loops here the board had to be reset to resolve.

Best Regards,
Aart

internal class Semaphore : WaitHandle {
private readonly object lck = new object();
private readonly ManualResetEvent evt = new ManualResetEvent(false);
private int count;

    public override bool WaitOne() {
        while (true)
        {
            //if (this.evt.WaitOne(10, false)) { astona
            if (this.evt.WaitOne(33, false))
            {
                lock (this.lck)
                {
                    if (this.count > 0)
                    {
                        if (--this.count == 0)
                            this.evt.Reset();

                        return true;
                    }
                }
            }
        }
    }
    

    public int Release() {
        lock (this.lck) {
            var cnt = this.count;

            this.count++;

            this.evt.Set();

            return cnt;
        }
    }
}