And if you call again
wifi.SendHttpGet (“files.ghielectronics.com” …
home it works my first time but if I call SendHttpGet a second time it bug
And if you call again
wifi.SendHttpGet (“files.ghielectronics.com” …
home it works my first time but if I call SendHttpGet a second time it bug
With the new library the response should be read like this:
But it seems to be faulty as I get a http 400 response
var buffer = new byte[512];
var start = DateTime.UtcNow;
var code = wifi.SendHttpGet("files.ghielectronics.com", "/", 80, SPWF04SxConnectionSecurityType.None);
Debug.WriteLine($"HTTP {code}");
while (wifi.ReadResponseBody(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");
I have a response from domoticz and I get it with just these lines.
the problem is during the second request.
var code = wifi.SendHttpGet("192.168.1.3", "/json.htm?type=command¶m=switchlight&idx=1839&switchcmd=On", 8080, SPWF04SxConnectionSecurityType.None);
Debug.WriteLine($"HTTP { code}");
wifi.ReadResponseBody(buffer, 0, buffer.Length);
string texte = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
Debug.WriteLine(texte);
With this url it works:
var code = wifi.SendHttpGet(“www.roschmionline.de”, “/”, 80, SPWF04SxConnectionSecurityType.None);
Debug.WriteLine($“HTTP {code}”);
You should be careful to read only a small part of the response, process this batch and then read the next batch, process it and so on. (Like in my example) The MCU has only few ram and this might be the problem.
the answer is very short, it is this:
{
“status” : “OK”,
“title” : “SwitchLight”
}
the problem comes even if we don’t read the answer.
during the second SendHttpGet the error provided the following information: Variable length response command already outstanding
with “www.google.com” I get the html code of the page without problem and all at once.
with “www.google.com” I get the html code of the page without problem and all at once.
Do you mean no problem with google.com?
In my App with this code added in main()
after
wifi.ClearTlsServerRootCertificate();
while (true)
{
int total = 0;
var buffer = new byte[512];
var start = DateTime.UtcNow;
var code = wifi.SendHttpGet("www.google.com", "/", 80, SPWF04SxConnectionSecurityType.None);
Debug.WriteLine($"HTTP {code}");
while (wifi.ReadResponseBody(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");
Thread.Sleep(5000);
}
Runs and downloads ‘for ever’ (more than 20 times)
I tested your program which therefore works very well. And I looked for which line was required for proper operation. when there is no more answer to read you have to read again, it must do something in the wifi chip.
while (true)
{
int total = 0;
var buffer = new byte[512];
var buffer1 = new byte[512];
var start = DateTime.UtcNow;
var code = wifi.SendHttpGet("192.168.1.3", "/json.htm?type=command¶m=switchlight&idx=1839&switchcmd=Toggle", 8080, SPWF04SxConnectionSecurityType.None);
Debug.WriteLine($"HTTP {code}");
total = wifi.ReadHttpResponse(buffer, 0, buffer.Length);
total = wifi.ReadHttpResponse(buffer1, 0, buffer1.Length);
Debug.WriteLine($"\r\nRead: {total:N0} in {(DateTime.UtcNow - start).TotalMilliseconds:N0}ms");
Thread.Sleep(2000);
}
problem solved
The problem was that you couldn’t run SendHttpGet twice in a row. You must read the content of the response and read again (empty without response) so that the wifi chip is ready to send a new request.
Many thanks to @RoSchmi
my 15 students will be able to work
@letailleur happy to hear that it works now. If you should see problems in future you should consider to use the SPWF04S library from the Github dev branch. There were some issues fixed since Version 1.0.
The ReadHttpResponse command was exchanged against the new ReadResponseBody command.
@Dat_Tran Btw: Where is John ?