Particle Electron Modem Speed

I have the same code running on a Photon and an Electron. The code runs an FTP client.

Using the board, I am sending a tiny file (jpg) whose size is about 8000 bytes to an FTP server. On the Photon, it takes a couple of seconds, on the Electron it takes “forever” and the board eventually stops responding.

What upload speeds are to be expected on the Electron?

About 3K to 4K bytes/second on the Electron.

However it’s very important that your code send the data with a TCP write of 512 bytes at a time. If you send it in tiny quantities, it will make the rate dramatically lower.

3 Likes

Thank you @rickkas7. I would appreciate your recommendation. My current code is below:

if (ftp.open(hostname, port, timeout)) {
ftp.user(username);
ftp.pass(password);
ftp.type("I");
ftp.stor(filename);
while ((data = mFile.read()) >= 0) {
ftp.data.write(data);
}
long int sendTime = millis() - now;
ftp.data.flush();
ftp.quit();

I’d rather fill the data into a buffer (e.g. uint8_t buf[512]) and then send the data in bulk via ftp.data.write(buf, sizeof(buf));
ftp.data is an instance of TCPClient so you have all the functions available listed here
https://docs.particle.io/reference/firmware/electron/#tcpclient

3 Likes

Thank you @ScruffR. I am now using the code below but whether I use 256 or 512 for the buffer, the 8k image still takes over 20 seconds.

I did some more debugging, and it looks likes once the transfer starts, the 8k image only takes 4 seconds to be sent so the rest must be the overhead of opening the connection.

Is there anyway this can be reduced? BTW, I am always sending to a dedicated FTP server that is under my control.

  byte clientBuf[ftpChunk];
  int clientCount = 0;
  while(mFile.available())
  {
    clientBuf[clientCount] = mFile.read();
    clientCount++;
  if(clientCount > (ftpChunk-1))
    {
      ftp.data.write(clientBuf,ftpChunk);
      clientCount = 0;
    }
  }
 // here is where the extra bytes are sent if the file isn't an exact multiple of 64 bytes.
 if(clientCount > 0) ftp.data.write(clientBuf,clientCount);
1 Like

That's what I thought. Most the time is lost during connect and login. And the other actions like navigate, open, upload, flush, close process just add to that.

This is the reason why I rather run a dedicated service to directly connect via TCPClient and let the file administration be done on the server side.
Since FTP is just as insecure I don't see the big problem in that.

2 Likes

I also tried using

if (!ftp.connected())

So that the connection overhead is only done the first time and then client does not disconnect (... idle clients are not disconnected by server).

However, this did not work. Is this the correct way to check if a client is still connected to the server?

Thanks in advance for your help.

1 Like