ESP8266 Developer Zone The Official ESP8266 Forum 2016-06-29T17:09:13+08:00 https://bbs.espressif.com:443/feed.php?f=65&t=2255 2016-06-29T17:09:13+08:00 2016-06-29T17:09:13+08:00 https://bbs.espressif.com:443/viewtopic.php?t=2255&p=7548#p7548 <![CDATA[Re: Slow sending of a file from Esp8266 to a Python-TCP-Server]]> viewtopic.php?f=31&t=232

Statistics: Posted by Guest — Wed Jun 29, 2016 5:09 pm


]]>
2016-06-06T19:17:20+08:00 2016-06-06T19:17:20+08:00 https://bbs.espressif.com:443/viewtopic.php?t=2255&p=7223#p7223 <![CDATA[Slow sending of a file from Esp8266 to a Python-TCP-Server]]> I have achieved the following :
I have a Teensey-Ultimate GPS Sheild-Esp8266 Setup. I am trying to send a file of 1Mb which is stored in the SD-card to a local python Server using TCP. I am able to send the file but the problem is that it is taking 4 Minutes to send the 1Mb file, whereas the same file when i send from a Python-Client script it takes 5 Seconds.
What is the reason for this slow transfer of data ? Is there a way to improve the speed. Are there any issues with the Arduino and Python Environment ?
Following is my Arduino and Python sketch :

Arduino Sketch:

Code:

#include <SoftwareSerial.h>
//------------------------------------------------------
#include <SPI.h>
//#include <SD.h>
#define TIMEOUT 5000 // mS
#define LED 13
#include <SdFat.h>
SdFat sd;
SdFile myFile;
const int chipSelect = SS;
//---------------------------------------------------------------------------
#define DEBUG true
void setup()
{
  Serial.begin(115200);
  Serial1.begin(2000000);
  Serial1.attachCts(20);
 delay(1000);
 Serial.println("Initializing SD card...");
 if (!sd.begin(chipSelect, SPI_FULL_SPEED)) sd.initErrorHalt();
 delay(1000);
 Serial.println("Card Initialized");

  //AT+UART_DEF=2000000,8,1,0,1....use this command to set BAUD RATE
  sendData("AT\r\n",2000,DEBUG):
  sendData("AT+CIFSR\r\n",2000,DEBUG); // get ip address
  sendData("AT+CIPMUX=0\r\n",1000,DEBUG); // configure for multiple connections
  sendData("AT+CIPMODE=1\r\n",1000,DEBUG);
  sendData2("AT+CIPSTART=\"TCP\",\"192.168.0.119\",80",2000);
//----------------FIND IMPORT STRING--------------------
//Serial.print("ENTER STRING:");
String IncomingString="";
boolean StringReady = false;
delay(2000);
StringReady= true;
if (StringReady){
  //----------------READ FILE IF FOUND IMPORT STRING--------------------
 
  if (!myFile.open("DATA3.TXT", O_READ))
      {
      sd.errorHalt("opening test.txt for read failed");
      }
      millisStartTime = millis();
      sendData2("\r\n",1000);
      sendData2("AT+CIPSEND\r\n",2000);
      while(myFile.available())
       {
          Serial1.print(myFile.read());
      }
      sendData2("\r\n",500);
      sendData2("+++",1000);
      sendData("AT+CIPCLOSE=1\r\n",1000,DEBUG);
      myFile.close();
     }
}
 void loop()
{
 
  }
 String sendData(String command, const int timeout, boolean debug)
{
    String response = "";
    Serial1.print(command);
    long int time = millis();
    while( (time+timeout) > millis())
    {
      while(Serial1.available())
      {
        char c = Serial1.read(); // read the next character.
        response+=c;
      } 
    }
    if(debug)
    {
      Serial.print(response);
    }
    return response;
   }

   String sendData2(String command, const int timeout)
{
    String response = "";
    Serial1.print(command);
    long int time = millis();
    while( (time+timeout) > millis())
    {
      while(Serial1.available())
      {
        char c = Serial1.read(); // read the next character.
        response+=c;
      } 
    }
   Serial.print(response);
   return response;
   }



Python Sketch:

Code:

import socket               # Import socket module
import time

s = socket.socket()         # Create a socket object
host = '192.168.0.119' # Get local machine name
port = 80                 # Reserve a port for your service.
s.bind((host, port))        # Bind to the port
f = open('Got_File.txt','wb')
s.listen(5)                 # Now wait for client connection.
while True:
    c, addr = s.accept()     # Establish connection with client.
    print ('Got connection from', addr)
    start_time = time.time()
    print ("Receiving Data from Client...")
    l = c.recv(1024)
    while (l):
        print ("Receiving...")
        f.write(l)
        #print (l)
        l = c.recv(1024)
    f.close()
    #s.shutdown(socket.SHUT_WR)
    print ("Done Receiving")
    print("--- %s seconds ---" % (time.time() - start_time))
    #c.send('Thank you for connecting')
    c.close()

---------------------------------------------------------------------------------------------------------------------------------------
Any Help would be appreciated. Thank You

Statistics: Posted by tfmdrill — Mon Jun 06, 2016 7:17 pm


]]>