WiFi disconnection when reading stream from HTTP request

I use a mini HTTP server on my FezDuino board and I try to upload files from client.
Every time a WiFi disconnection occured while reading the bytes of the stream.

WiFi configuration is :

WiFiNetworkInterfaceSettings wifiSettings = new WiFiNetworkInterfaceSettings()
{
    Ssid = "WiFiWebServerSample",
    Password = "0123456789",
    Address = IPAddress.Parse("192.168.0.20"),
    SubnetMask = IPAddress.Parse("255.255.255.0"),
    DhcpEnable = true,
    DynamicDnsEnable = true,
    Mode = WiFiMode.AccessPoint
};

I launch web server like as below :

webServer = new HttpListener("http");
webWorkerThread = new Thread(() =>
{
    while (webServer.IsListening)
    {
        try
        {
            HttpListenerContext context = webServer.GetContext();
            ProcessInboundGetRequest(context);
          }
        catch (Exception)
        {
            Debug.WriteLine("Failed to read context");
        }
    }
});

And I manage the HTTPRequest to upload like this :

private static void ProcessInboundGetRequest(HttpListenerContext context)
{
    try
    {
        switch (context.Request.HttpMethod.ToUpper())
        {
            case "POST":
                switch (context.Request.RawUrl.ToUpper())
                {
                    case "/UPLOAD":
                        Stream str = context.Request.InputStream;
                        buffer = new byte[CHUNKS];
                        int count = 1, total = 0;
                        Debug.WriteLine("Upload file is progress...");

                        while (count > 0)
                        {
                            count = str.Read(buffer, 0, CHUNKS);
                            Debug.WriteLine("(" + count + " bytes read)");
                            total += count;
                        }
                        Debug.WriteLine("Upload file is successful : " + total + " bytes read");
                        break;
                }
        }
    }
    finally
    {
        context.Response.OutputStream.Close();
    }
}

Of course I can join the project files with index.html for testing.

The form used for this example is :

<form id="myForm" action="/upload" enctype="multipart/form-data" method="post">
  <label class="custom-uploader" for="file">Upload Your File</label>
  <input id="file" accept=".ghi,.tca" name="fileToUpload" type="file" />
  <br><button class="btn btn-success" name="submit" type="submit">Upload File</button>
</form>

I try to read the HTTP request stream slower with Thread.Sleep(10) and it seems I succes read more bytes but the WiFi conenction is always ended before reading the end of uploaded file.
Have you any ideas about this problem ?

I have exactly the same problem when I upload a file via a FTP server. I think the problem is around the opened stream…

Hi,

We use the FezDuino board for our professional products and would like a road map to fix these last issues. Currently we are unable to optimally use our HTTPS WiFi server…

How long is the support for TinyCLR still ?

Please give us feedback so that we can consider further developments.

could you send us simple project please?

When we see an issue that easy to reproduce, we usually check and have answer / solution quick.

But if an issue needs a lot of steps or guessing to reproduce, we will try asap, as we have multiple projects :d.

1 Like

Send us a small project when you have time, please.

Hi,

I’m working today on this topic.
You can download a simplified project which allows to reproduce this issue by clicking this link :
https://drive.google.com/file/d/14gRvUVTUYWW7h43_b5mE1uslVSc9jCBf/view?usp=sharing

Yo can try to upload files >100 kbytes via a HTTP client. Every time I have an “End of WiFi connection” message.

Somehow I can’t access the link, could you send the zip file to email?

Sorry. I send an email with the sample project via support GHI address.
Have you received it ?

My mail has been rejected. What is your email for this ?

Otherwise I change the permissions on my drive.
You can now download the .zip file.

we have it, you can delete the zip file now.

1 Like

Hi, we were able to reproduce issue,

Seems to me, problem comes from Wifi module FW, we consider to check/upgrade the firmware on Wifi module but it will be long research: WiFi AP mode auto disconnect when read to fast · Issue #1385 · ghi-electronics/TinyCLR-Libraries · GitHub

For now, increase the speed to 12MHz or 16MHz will help this issue. I can upload few MB just fine with 12 or 16MHz. Higher speed (20 or 24MHz) will be failed.

ClockFrequency = 16000000,

Seems I can up more than 100MB without issue, using your code, just change to 16MHz

Very interesting. Thanks a lot for your analysis
Indeed increasing the speed to 12MHz or 16MHz is better and the issue doesn’t occur.

Actually Fez Duino boards are delivered with the WiFi firmware v19.6.1.
I upgrade some boards with OTA WiFi firmware v19.7.3.
I have the same issue in both versions.

However I don’t dare to upgrade to a higher firmware version because ATWINC15x0 software release notes mentions :

Support for the WEP protocol is deprecated
in 19.7.5. Attempts to configure it will result
in error.

The newer WiFi firmware is v19.7.7 but I’m afraid this one won’t be compatible with TinyCLR as long as it doesn’t handle WPA-2 keys. What do you think ?

You can try but the recommend version is 19.5.xxx if I remember correctly.

19.6.xxx seems to work but not recommended.

19.7.xxx we have never tested it

We will look into this issue soon.