Main Site Documentation

Fez Domino + Fez Connect Shield,slow download and download problem with WebRequest (maybe timeout)


#1

Hi Everyone,
i have FezDomino + Fez ConnectShield and i want to download mp3 files from my server,
(also i am using mp3 shield and a 2x16 lcd display but they are not connected in this test).

it starts downloading, but it is very very slow downloading… i am downloading the same file with my pc in 10 seconds near ~800kb/s but fez connect shield gets it 2kb/s :slight_smile:
while downloading, it suddenly cuts the connection in random time… sometimes at 400kb downloaded or 200 kb or event 1.5mb and not giving any error…

here is my wiznet configuration…


byte[] mac = { 0x00, 0x26, 0x1C, 0x7B, 0x29, 0xE8 };
                WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di7, true); // WIZnet interface on FEZ Connect

                Dhcp.EnableDhcp(mac, "wiznet");

and here is the download class i use…


using System;
using Microsoft.SPOT;
using System.IO;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.Sockets;

namespace smg.utulity.downloader
{
    class downloader
    {

        public static event Progress onProgress;
        public delegate void Progress(long currentSize, long TotalSize, string Filename);

        public static event DownloadFinished onDownloadFinished;
        public delegate void DownloadFinished(string errMsg);

        public static int DownloadFile(String remoteFilename,
                               String localFilename)
        {

            string fname = localFilename.Split('\\')[localFilename.Split('\\').Length - 1];
            // Function will return the number of bytes processed
            // to the caller. Initialize to 0 here.
            int bytesProcessed = 0;

            // Assign values to these objects here so that they can
            // be referenced in the finally block
            Stream remoteStream = null;
            Stream localStream = null;
            WebResponse response = null;

            // Use a try/catch/finally block as both the WebRequest and Stream
            // classes throw exceptions upon error
            try
            {
                // Create a request for the specified remote file name
                WebRequest request = WebRequest.Create(remoteFilename);
                if (request != null)
                {
                    // Send the request to the server and retrieve the
                    // WebResponse object 
                    // request.ContentLength
                    response = request.GetResponse();
                    if (response != null)
                    {
                        // Once the WebResponse object has been retrieved,
                        // get the stream object associated with the response's data
                        remoteStream = response.GetResponseStream();
                        long total = response.ContentLength;

                        // Create the local file
                        localStream = File.Create(localFilename);

                        // Allocate a 1k buffer

                        byte[] buffer = new byte[1024];
                        int bytesRead;

                        // Simple do/while loop to read from stream until
                        // no bytes are returned
                        do
                        {
                            // Read data (up to 1k) from the stream
                            bytesRead = remoteStream.Read(buffer, 0, buffer.Length);

                            // Write the data to the local file
                            localStream.Write(buffer, 0, bytesRead);

                            // Increment total bytes processed
                            bytesProcessed += bytesRead;

                            if (onProgress != null) { onProgress(bytesProcessed, total, fname); }
                        } while (bytesRead > 0);
                    }
                }
                if (onDownloadFinished != null) { onDownloadFinished("finished"); }
            }
            catch (WebException webEx)
            {
                Debug.Print("Web Exception Occured");
                if (webEx.InnerException is SocketException)
                {
                    SocketException sock = webEx.InnerException as SocketException;
                    Debug.Print("Socket error code: " + sock.ErrorCode.ToString());
                }
            }
            catch (Exception ex)
            {
                Debug.Print("Exception of type: " + ex.GetType().FullName);
                Debug.Print(ex.Message);
                if (onDownloadFinished != null) { onDownloadFinished(ex.Message); }
            }
            finally
            {
                // Close the response and streams objects here 
                // to make sure they're closed even if an exception
                // is thrown at some point
                if (response != null) response.Close();
                if (remoteStream != null) remoteStream.Close();
                if (localStream != null) localStream.Close();
            }

            // Return total bytes processed to caller.
            return bytesProcessed;
        }
    }
}


so here are the questions:
1-why it downloads too slow?
2-why it stops downloading suddenly?
3-mp3 shield and fez connect shield uses the same spi module “SPI.SPI_module.SPI1” , will it makes a problem?


#2

USBizi has very little memory. It is meant to transfer sensor data, not megabytes.

You should upgrade to FEZ Cobra or FEZ Spider.


#3

Also it is using the W5100 chip which is not a 100 mb/s interface…


#4

[quote]USBizi has very little memory. It is meant to transfer sensor data, not megabytes.

You should upgrade to FEZ Cobra or FEZ Spider.
[/quote]

yes i know we have very little memory… thats why i used 1kb buffer area for downloading…
i can play mp3,wma etc, i can make http connection etc…
what i am asking is, why it stops suddenly and not giving any error…
i mean, if memory is full, it must give overflow…
if the connection cancelled it must give connection reset or such error…
it is not giving any error… it suddenly finishes and comes to

 if (onDownloadFinished != null) { onDownloadFinished("finished"); }

code…
can you explain me why?
or can you suggest better approach? ftp? socket connection etc?
which one is safer?

we started drawing our own pcb and hardware design based on fez domino + vs1053 + w5100 + 8gb microsd… we came nearly to the end… so i want to use this configuration…


#5

and also can you tell me something about my third question?


#6

Yes,


#7

yes ? :slight_smile: so how will i solve this? :))

also mike, you said w5100 is not 100mbit
but the http://mct.de/download/wiznet/w5100.pdf says it is 100mbit, it must download at least 50~100 kb per second… it downloads at 2kb/s…


#8

how to fix SPI1 clash? Easy, use a different set of pins for one of the devices. SPI cannot share the “bus” like I2C, you need unique pins. Look on your Domino schematic and see if you can locate a second set of SPI pins.

The Wiz document you talk about surely does say it connects to a 100mbit network; but that doesn’t mean you can push or pull data from the net at that speed. You are using SPI; this is the limiting factor for how fast you can transfer data.


#9

what is the speed limit of spi in fez domino?


#10

its probably irrelevant what the speed limit of SPI is.

You have to understand that you are moving data around, you’re responding to the data, and only one piece of the puzzle is actually putting data on the wire or taking data off the wire. I don’t think you will get any deterministic value for how fast that is.


#11

I had same problems on cobra when Im using WebRequest over PPP connection. If Im use Wifi or LAN downloading 3MB file has not be problem(Download in chunks) but when Im download same files over PPP(GPRS) connection Im receive corupted files sometime 100kb some time 1,5Mb … When Im switch to Socket has PPP start working without problems…


#12

Brett,
i have written an ftp client with socket and i used the webserver code in wiki page…
alll i get is download and upload speed is locked to 8kb/s , but when i use netduino plus, i can download at 400-600 kb/s…
result:
1 - there maybe a problem with “my” fez connect shield
2 - the spi bus really works very slow with this shield (design issue)
3 - connecting shields over and over may produce low speed on spi bus…

so , i really want to know if my devices have problem or not, or fez domino + fez connect shield is not suitable for downloading large files…
we hired a freelance hardware designer to design us a pcb that has vs1053 + wiznet + nxp chip… we nearly come to end of design… and we will use more then 2.000 device…
so i have to solve this problem immediately… or choose another chipset…


#13

as i said in the other thread, if this is a production level issue contact GHI directly.

I also think you should consider that the two solutions you’re looking at have different technologies and chips; so it makes sense that there may be differences.

SPI = SERIAL (ie one bit at a time) and the Wiz5100 chip has inbuilt IP stack. Netduino uses a parallel connection and LWIP.