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.
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.
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?
@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?
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.
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?
@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.
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?
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);
}
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;
}
}
}