Hello, I got an error when running my program with a FEZ T18 card. The program has worked on one card and it does not work on another. Containment problem I have no other card to try …
I updated the firmware of the wifi and the card but I still have the problem.
could you ping the wifi ip address?
yes i can do it even after the bug.
192.168.1.3 works well because it’s domoticz and my light turns on correctly. With google I have the same error.
how can we see the firmware version of the wifi?
https://docs.ghielectronics.com/hardware/components/spwf04sa.html
When the WiFi module starts, it sends a PowerOn message which tells you what firmware version is installed. For example,
PowerOn 171117-0328fe3-SPWF04S
. In this case the firmware is dated 17 November 2017.
in the firmware zip file I found a more recent file. So it works without problem for the 1st call but not for the 2nd, I have an exception “System.invalidOperationException” in the dll SPWF04Sx.dll
I tested by inverting the two SendHttpGet, in 1st it still works.
I also got the message from the wifi card, it is as follows:
#### Exception System.InvalidOperationException - 0x00000000 (1) ####
#### Message:
#### GHIElectronics.TinyCLR.Drivers.STMicroelectronics.SPWF04Sx.SPWF04SxInterface::SendHttpGet [IP: 0009] ####
#### FezClientRestFul.Program::Main [IP: 0153] ####
Hello @letailleur, perhaps it’s better if you post your complete code. So eventually others can try your code on their boards.
Kind regards
RoSchmi
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Spi;
using GHIElectronics.TinyCLR.Drivers.STMicroelectronics.SPWF04Sx;
using GHIElectronics.TinyCLR.Pins;
using System;
using System.Collections;
using System.Diagnostics;
using System.Net.NetworkInterface;
using System.Text;
using System.Threading;
namespace FezClientRestFul
{
class Program
{
private static GpioPin led1;
private static GpioPin led2;
private static GpioPin btn1;
private static SPWF04SxInterface wifi;
static void Main()
{
Debug.WriteLine(“début”);
var cont = GpioController.GetDefault();
var reset = cont.OpenPin(FEZ.GpioPin.WiFiReset);
var irq = cont.OpenPin(FEZ.GpioPin.WiFiInterrupt);
var mode = cont.OpenPin(FEZCLR.GpioPin.PA0);
var scont = SpiController.FromName(FEZ.SpiBus.WiFi);
var spi = scont.GetDevice(SPWF04SxInterface.GetConnectionSettings(SpiChipSelectType.Gpio, FEZ.GpioPin.WiFiChipSelect));
mode.SetDriveMode(GpioPinDriveMode.InputPullDown);
btn1 = cont.OpenPin(FEZ.GpioPin.Btn1);
btn1.SetDriveMode(GpioPinDriveMode.InputPullUp);
led1 = cont.OpenPin(FEZ.GpioPin.Led1);
led1.SetDriveMode(GpioPinDriveMode.Output);
led1.Write(GpioPinValue.Low);
led2 = cont.OpenPin(FEZ.GpioPin.Led2);
led2.SetDriveMode(GpioPinDriveMode.Output);
led2.Write(GpioPinValue.Low);
wifi = new SPWF04SxInterface(spi, irq, reset);
wifi.IndicationReceived += Message;
wifi.ErrorReceived += Erreur;
// wifi.IndicationReceived += (s, e) => Debug.WriteLine($"WIND: {Program.WindToName(e.Indication)} {e.Message}");
// wifi.ErrorReceived += (s, e) => Debug.WriteLine($"ERROR: {e.Error} {e.Message}");
Debug.WriteLine("Configuration broche terminé!");
Thread.Sleep(1000);
wifi.TurnOn();
Debug.WriteLine("wifi.TurnOn()"+ wifi.Description);
Thread.Sleep(1000);
NetworkInterface.ActiveNetworkInterface = wifi;
Thread.Sleep(1000);
// if (wifi.State == SPWF04SxWiFiState.HardwarePowerUp)
// Debug.WriteLine(“etat HardwarePowerUp”);
wifi.JoinNetwork(“Epinay2.4Ghz”, “Epinay2.4Ghz”);
// wifi.
Debug.WriteLine(“connecté”);
Thread.Sleep(2000);
Thread.Sleep(2000);
wifi.ClearTlsServerRootCertificate();
Thread.Sleep(2000);
Debug.WriteLine(“avant appel!!!”);
led1.Write(GpioPinValue.High);
// wifi.SendHttpGet(“192.168.1.3”, “/json.htm?type=command¶m=switchlight&idx=1246&switchcmd=On”, 8080, SPWF04SxConnectionSecurityType.None);
try
{
while (true)
{
WaitForButton();
// wifi.SendHttpGet(“192.168.1.3”, “/json.htm?type=command¶m=switchlight&idx=1839&switchcmd=On”, 8080, SPWF04SxConnectionSecurityType.None);
wifi.SendHttpGet(“192.168.1.3”, “/json.htm?type=command¶m=switchlight&idx=1839&switchcmd=Off”, 8080, SPWF04SxConnectionSecurityType.None); //wifi.SendHttpGet(“www.google.com”, “/”, 80, SPWF04SxConnectionSecurityType.None);
byte[] reponse = new byte[255];
wifi.ReadHttpResponse(reponse, 0, 250);
string texte = System.Text.Encoding.UTF8.GetString(reponse);
Debug.WriteLine(texte);
SPWF04SxWiFiState etat = wifi.State;
Debug.WriteLine(texte);
led2.Write(GpioPinValue.High);
WaitForButton();
wifi.SendHttpGet("192.168.1.3", "/json.htm?type=command¶m=switchlight&idx=1839&switchcmd=On", 8080, SPWF04SxConnectionSecurityType.None);
// wifi.SendHttpGet("192.168.1.3", "/json.htm?type=command¶m=switchlight&idx=1839&switchcmd=Off", 8080, SPWF04SxConnectionSecurityType.None);
led2.Write(GpioPinValue.Low);
}
}catch (Exception e)
{
SPWF04SxWiFiState etat = wifi.State;
}
/* Debug.WriteLine("après appel");
Thread.Sleep(1000);
var buffer = new byte[512];
wifi.ReadHttpResponse(buffer, 0, buffer.Length);
Debug.WriteLine(Encoding.UTF8.GetString(buffer));
Debug.WriteLine("eteindre");
Thread.Sleep(1000);
led1.Write(GpioPinValue.Low);
wifi.TurnOff();
*/
}
private static void WaitForButton()
{
while (btn1.Read() == GpioPinValue.High)
{
Thread.Sleep(50);
}
while (btn1.Read() == GpioPinValue.Low)
Thread.Sleep(50);
}
private static void Message(SPWF04SxInterface sender, SPWF04SxIndicationReceivedEventArgs e)
{
Debug.WriteLine("##" + e.Message + "##");
}
private static void Erreur(SPWF04SxInterface sender, SPWF04SxErrorReceivedEventArgs e)
{
Debug.WriteLine("!!!" + e.Message + "!!!");
}
private static string WindToName(SPWF04SxIndication wind)
{
switch (wind)
{
case SPWF04SxIndication.ConsoleActive: return nameof(SPWF04SxIndication.ConsoleActive);
case SPWF04SxIndication.PowerOn: return nameof(SPWF04SxIndication.PowerOn);
case SPWF04SxIndication.Reset: return nameof(SPWF04SxIndication.Reset);
case SPWF04SxIndication.WatchdogRunning: return nameof(SPWF04SxIndication.WatchdogRunning);
case SPWF04SxIndication.LowMemory: return nameof(SPWF04SxIndication.LowMemory);
case SPWF04SxIndication.WiFiHardwareFailure: return nameof(SPWF04SxIndication.WiFiHardwareFailure);
case SPWF04SxIndication.ConfigurationFailure: return nameof(SPWF04SxIndication.ConfigurationFailure);
case SPWF04SxIndication.HardFault: return nameof(SPWF04SxIndication.HardFault);
case SPWF04SxIndication.StackOverflow: return nameof(SPWF04SxIndication.StackOverflow);
case SPWF04SxIndication.MallocFailed: return nameof(SPWF04SxIndication.MallocFailed);
case SPWF04SxIndication.RadioStartup: return nameof(SPWF04SxIndication.RadioStartup);
case SPWF04SxIndication.WiFiPSMode: return nameof(SPWF04SxIndication.WiFiPSMode);
case SPWF04SxIndication.Copyright: return nameof(SPWF04SxIndication.Copyright);
case SPWF04SxIndication.WiFiBssRegained: return nameof(SPWF04SxIndication.WiFiBssRegained);
case SPWF04SxIndication.WiFiSignalLow: return nameof(SPWF04SxIndication.WiFiSignalLow);
case SPWF04SxIndication.WiFiSignalOk: return nameof(SPWF04SxIndication.WiFiSignalOk);
case SPWF04SxIndication.BootMessages: return nameof(SPWF04SxIndication.BootMessages);
case SPWF04SxIndication.KeytypeNotImplemented: return nameof(SPWF04SxIndication.KeytypeNotImplemented);
case SPWF04SxIndication.WiFiJoin: return nameof(SPWF04SxIndication.WiFiJoin);
case SPWF04SxIndication.WiFiJoinFailed: return nameof(SPWF04SxIndication.WiFiJoinFailed);
case SPWF04SxIndication.WiFiScanning: return nameof(SPWF04SxIndication.WiFiScanning);
case SPWF04SxIndication.ScanBlewUp: return nameof(SPWF04SxIndication.ScanBlewUp);
case SPWF04SxIndication.ScanFailed: return nameof(SPWF04SxIndication.ScanFailed);
case SPWF04SxIndication.WiFiUp: return nameof(SPWF04SxIndication.WiFiUp);
case SPWF04SxIndication.WiFiAssociationSuccessful: return nameof(SPWF04SxIndication.WiFiAssociationSuccessful);
case SPWF04SxIndication.StartedAP: return nameof(SPWF04SxIndication.StartedAP);
case SPWF04SxIndication.APStartFailed: return nameof(SPWF04SxIndication.APStartFailed);
case SPWF04SxIndication.StationAssociated: return nameof(SPWF04SxIndication.StationAssociated);
case SPWF04SxIndication.DhcpReply: return nameof(SPWF04SxIndication.DhcpReply);
case SPWF04SxIndication.WiFiBssLost: return nameof(SPWF04SxIndication.WiFiBssLost);
case SPWF04SxIndication.WiFiException: return nameof(SPWF04SxIndication.WiFiException);
case SPWF04SxIndication.WiFiHardwareStarted: return nameof(SPWF04SxIndication.WiFiHardwareStarted);
case SPWF04SxIndication.WiFiNetwork: return nameof(SPWF04SxIndication.WiFiNetwork);
case SPWF04SxIndication.WiFiUnhandledEvent: return nameof(SPWF04SxIndication.WiFiUnhandledEvent);
case SPWF04SxIndication.WiFiScan: return nameof(SPWF04SxIndication.WiFiScan);
case SPWF04SxIndication.WiFiUnhandledIndication: return nameof(SPWF04SxIndication.WiFiUnhandledIndication);
case SPWF04SxIndication.WiFiPoweredDown: return nameof(SPWF04SxIndication.WiFiPoweredDown);
case SPWF04SxIndication.HWInMiniAPMode: return nameof(SPWF04SxIndication.HWInMiniAPMode);
case SPWF04SxIndication.WiFiDeauthentication: return nameof(SPWF04SxIndication.WiFiDeauthentication);
case SPWF04SxIndication.WiFiDisassociation: return nameof(SPWF04SxIndication.WiFiDisassociation);
case SPWF04SxIndication.WiFiUnhandledManagement: return nameof(SPWF04SxIndication.WiFiUnhandledManagement);
case SPWF04SxIndication.WiFiUnhandledData: return nameof(SPWF04SxIndication.WiFiUnhandledData);
case SPWF04SxIndication.WiFiUnknownFrame: return nameof(SPWF04SxIndication.WiFiUnknownFrame);
case SPWF04SxIndication.Dot11Illegal: return nameof(SPWF04SxIndication.Dot11Illegal);
case SPWF04SxIndication.WpaCrunchingPsk: return nameof(SPWF04SxIndication.WpaCrunchingPsk);
case SPWF04SxIndication.WpaTerminated: return nameof(SPWF04SxIndication.WpaTerminated);
case SPWF04SxIndication.WpaStartFailed: return nameof(SPWF04SxIndication.WpaStartFailed);
case SPWF04SxIndication.WpaHandshakeComplete: return nameof(SPWF04SxIndication.WpaHandshakeComplete);
case SPWF04SxIndication.GpioInterrupt: return nameof(SPWF04SxIndication.GpioInterrupt);
case SPWF04SxIndication.Wakeup: return nameof(SPWF04SxIndication.Wakeup);
case SPWF04SxIndication.PendingData: return nameof(SPWF04SxIndication.PendingData);
case SPWF04SxIndication.InputToRemote: return nameof(SPWF04SxIndication.InputToRemote);
case SPWF04SxIndication.OutputFromRemote: return nameof(SPWF04SxIndication.OutputFromRemote);
case SPWF04SxIndication.SocketClosed: return nameof(SPWF04SxIndication.SocketClosed);
case SPWF04SxIndication.IncomingSocketClient: return nameof(SPWF04SxIndication.IncomingSocketClient);
case SPWF04SxIndication.SocketClientGone: return nameof(SPWF04SxIndication.SocketClientGone);
case SPWF04SxIndication.SocketDroppingData: return nameof(SPWF04SxIndication.SocketDroppingData);
case SPWF04SxIndication.RemoteConfiguration: return nameof(SPWF04SxIndication.RemoteConfiguration);
case SPWF04SxIndication.FactoryReset: return nameof(SPWF04SxIndication.FactoryReset);
case SPWF04SxIndication.LowPowerMode: return nameof(SPWF04SxIndication.LowPowerMode);
case SPWF04SxIndication.GoingIntoStandby: return nameof(SPWF04SxIndication.GoingIntoStandby);
case SPWF04SxIndication.ResumingFromStandby: return nameof(SPWF04SxIndication.ResumingFromStandby);
case SPWF04SxIndication.GoingIntoDeepSleep: return nameof(SPWF04SxIndication.GoingIntoDeepSleep);
case SPWF04SxIndication.ResumingFromDeepSleep: return nameof(SPWF04SxIndication.ResumingFromDeepSleep);
case SPWF04SxIndication.StationDisassociated: return nameof(SPWF04SxIndication.StationDisassociated);
case SPWF04SxIndication.SystemConfigurationUpdated: return nameof(SPWF04SxIndication.SystemConfigurationUpdated);
case SPWF04SxIndication.RejectedFoundNetwork: return nameof(SPWF04SxIndication.RejectedFoundNetwork);
case SPWF04SxIndication.RejectedAssociation: return nameof(SPWF04SxIndication.RejectedAssociation);
case SPWF04SxIndication.WiFiAuthenticationTimedOut: return nameof(SPWF04SxIndication.WiFiAuthenticationTimedOut);
case SPWF04SxIndication.WiFiAssociationTimedOut: return nameof(SPWF04SxIndication.WiFiAssociationTimedOut);
case SPWF04SxIndication.MicFailure: return nameof(SPWF04SxIndication.MicFailure);
case SPWF04SxIndication.UdpBroadcast: return nameof(SPWF04SxIndication.UdpBroadcast);
case SPWF04SxIndication.WpsGeneratedDhKeyset: return nameof(SPWF04SxIndication.WpsGeneratedDhKeyset);
case SPWF04SxIndication.WpsEnrollmentAttemptTimedOut: return nameof(SPWF04SxIndication.WpsEnrollmentAttemptTimedOut);
case SPWF04SxIndication.SockdDroppingClient: return nameof(SPWF04SxIndication.SockdDroppingClient);
case SPWF04SxIndication.NtpServerDelivery: return nameof(SPWF04SxIndication.NtpServerDelivery);
case SPWF04SxIndication.DhcpFailedToGetLease: return nameof(SPWF04SxIndication.DhcpFailedToGetLease);
case SPWF04SxIndication.MqttPublished: return nameof(SPWF04SxIndication.MqttPublished);
case SPWF04SxIndication.MqttClosed: return nameof(SPWF04SxIndication.MqttClosed);
case SPWF04SxIndication.WebSocketData: return nameof(SPWF04SxIndication.WebSocketData);
case SPWF04SxIndication.WebSocketClosed: return nameof(SPWF04SxIndication.WebSocketClosed);
case SPWF04SxIndication.FileReceived: return nameof(SPWF04SxIndication.FileReceived);
default: return "Other";
}
}
}
}
Thanks, which version of the libraries do you have installed in your project?
in visual 2019 nuget give 1.0.0
I had a look on your code and found some things but didn’t get it working in a short time.
Since the SPWF04SX library V 1.0 has some known issues I wouldn’t spend to much time to get it running.
I would suggest to take one of these two options:
- Do not use the master SPWF04Sx library from NuGet but download the library from the dev branch
–https://github.com/ghi-electronics/TinyCLR-Drivers/tree/dev/STMicroelectronics/SPWF04Sx
- About a year ago I had a quite stable application, which I just tried.
From the working initialization there it should be easy to adapt it to your needs.
Thank you but I don’t see how to make a SendHttpGet () with your library?
the namesapce GHIElectronics.TinyCLR.Drivers.STMicroelectronics.SPWF04Sx, have you changed it or not?
Yes, I think that there were some changes. It’s quite a time since I worked on this. I will have a look. But you get the time from the NTP server?, then the basics are working.
after deleting all the Azure part, I actually recover my @ip l hour etc etc.
but as soon as I make a wifi.senhttpget () I have an error IP: 00a3 IP: 000b and IP: 0009 and a Request failed
It’s better if I specify the communication port :).
the order passes and my light turns on but at the second request I have the error (Informations supplémentaire : Variable length response command already outstanding. ) in the method:
protected SPWF04SxCommand GetVariableLengthResponseCommand ()
{
if (this.activeVariableLengthResponseCommand! = null) throw new InvalidOperationException (“Variable length response command already outstanding.”);
return this.activeVariableLengthResponseCommand = this.GetCommand ();
}
I made some more tests.
If I add this code after the line ‘wifi.ClearTlsServerRootCertificate();’
I get a response with this code:
var buffer = new byte[512];
var start = DateTime.UtcNow;
var code = wifi.SendHttpGet("files.ghielectronics.com", "/", 80, SPWF04SxConnectionSecurityType.None);
Debug.WriteLine($"HTTP {code}");
But if I remember right I think that I used the HttpWebRequest Class like it was shown in the GHI example:
private static void TestHttp(string host, string url, string commonName = null)
{
if (commonName != null)
{
wifi.ForceSocketsTls = true;
wifi.ForceSocketsTlsCommonName = commonName;
}
var buffer = new byte[512];
var start = DateTime.UtcNow;
var req = (HttpWebRequest)HttpWebRequest.Create(host + url);
req.HttpsAuthentCerts = new[] { new X509Certificate() };
var res = (HttpWebResponse)req.GetResponse();
var str = res.GetResponseStream();
Debug.WriteLine($"HTTP {res.StatusCode}");
var total = 0;
while (str.Read(buffer, 0, buffer.Length) is var read && read > 0)
{
total += read;
try
{
Debugger.Log(0, "", Encoding.UTF8.GetString(buffer, 0, read));
}
catch
{
Debugger.Log(0, "", Encoding.UTF8.GetString(buffer, 0, read - 1));
}
Thread.Sleep(100);
}
Debug.WriteLine($"\r\nRead: {total:N0} in {(DateTime.UtcNow - start).TotalMilliseconds:N0}ms");
}