Statistics: Posted by Guest — Wed Jun 29, 2016 5:09 pm
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;
}
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()
Statistics: Posted by tfmdrill — Mon Jun 06, 2016 7:17 pm