我取得了以下成就:
我有一个 Teensey-Ul
timate GPS sheild-esp8266 设置。我正在尝试使用 TCP 将存储在 SD 卡中的 1Mb 文件发送到本地 python 服务器。我能够发送文件,但问题是它正在占用
4 分钟发送 1Mb 文件,而当我从一个发送时,同一个文件
Python 客户端脚本需要 5 秒。
数据传输缓慢的原因是什么?有没有办法提高速度。Arduino和Python环境有任何问题吗?
以下是我的Arduino和Python草图:
#include
//------------------------------------------------------
#include
//#include
#define TIMEOUT 5000 // mS
#define LED 13
#include
SDF标准差;
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("ATrn",2000,DEBUG):
sendData("AT+CIFSRrn",2000,DEBUG); // get ip address
sendData("AT+CIPMUX=0rn",1000,DEBUG); // configure for multiple connections
sendData("AT+CIPMODE=1rn",1000,DEBUG);
sendData2("AT+CIPSTART="TCP","192.168.0.119",80",2000);
----------------查找导入字符串--------------------
//Serial.print("ENTER STRING:");
String IncomingString="";
布尔值 StringReady = false;
延迟(2000);
StringReady= 真;
如果 (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("rn",1000);
sendData2("AT+CIPSENDrn",2000);
while(myFile.available())
{
Serial1.print(myFile.read());
}
sendData2("rn",500);
sendData2("+++",1000);
sendData("AT+CIPCLOSE=1rn",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;
}
import socket # Import socket module
导入时间
s = socket.socket() # Create a socket object
主机 = '192.168.0.119'
port = 80 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port
f = 开('Got_File.txt','WB')
s.listen(5) # Now wait for client connection.
而 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()