Chat freely about anything...

User avatar
By Joe_Southern
#51133 I have an ESP8266 V1 hooked up to a USB serial and they communicate fine... kinda .. except..

I have the ESP pull a file from a web site (my own) and then echo it back to the Serial Port which I read in the computer. I plan for the Serial to go to an Arduino, but for now I'm debugging.

If the file is say under 500KB, then it will pull the file and send it back to the Serial Port. I can capture it and compare it to the original file and it's the same - although this took awhile to do.

If it's over 500KB then it seems to drop the connection to the web page but then picks it back up after a few moments(the light goes out). I've tried all sorts of things to stabilize it.

Even on the small ones - if it's really small file (100KB) then maybe 5 of 6 tries work perfect. Little larger then 3 of 6 tries work. Still larger 0 of 6.

I've set the timeouts, added delays, changed baud speed, simplified, but can't get it to be consistent.

I've used the 1.65 IDE and the 1.69. I have the most recent esp code - 2.5 I think it is.

So, to restate the problem - I can get it to connect to a web page, retrieve it and send it to the Serial port. It's that it won't do it consistently and if the file is too large (over 500KB or so) then it will drop the connection ever so often too.

I have a 10K resistor on GPIO01, 02 and Rst, and a 64K resistor on the CHPD (I read here that this increases stability...and I kind of agree).

Any ideas? Thanks!

Here is my code -

----

#include <ESP8266WiFi.h>
const long BaudRate = 38400;

//*********** WiFi Setup **********************
WiFiClient client;
const char* ssid = "myWifi";
const char* password = "XXXX";

//******** Website info ***********************
const char* host = "192.168.0.75";
const char* baseWebPath = "/joeswindows/users/";
const char* hostUser = "joe/";
const char* imageWebFile = "imageArray00.jpg";
String webPageToGet = ""; // for example "/joeswindows/users/joe/imageArray00.jpg"

bool bRunning = false;

void setup()
{
Serial.begin(BaudRate);
delay(10);

//Setup the WiFi and establish connection
SetupWiFi();

webPageToGet = "";
webPageToGet += baseWebPath;
webPageToGet += hostUser;
webPageToGet += imageWebFile;
Serial.println(webPageToGet);

//Give the Arduino board time to start up
delay(5000);
}

void GetPage()
{
unsigned long totalBytes = 0;
const int httpPort = 80;

if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}

Serial.println("Did connect");

client.print(String("GET ") + webPageToGet + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");

Serial.setTimeout(5000); // tried with different values as well as commenting out
client.setTimeout(5000); // tried with different values as well as commenting out

unsigned long iWhileCount = 0;

unsigned long timeStart = millis();
unsigned long HowOften = 20000;
unsigned long DelayFor = 100;

while(client.available())
{
iWhileCount += 1;

byte inChar = (byte)client.read();
Serial.write(inChar);

yield();

//added this part recently but has no real effect on dropping connection

if(millis() > timeStart + HowOften)
{
delay(DelayFor);
timeStart = millis();
}
}

Serial.println("closing connection with " + String(totalBytes) + " and while count of - " + String(iWhileCount));
Serial.flush();
bRunning = false;
}


//*************** Hardware Loop **********************************
void loop()
{
delay(10000);
if(!bRunning)
{
bRunning = true;
Serial.println("***************Start Get page*****************");
GetPage();
Serial.println("***************Out of Get page*****************");
}
}

//*************** WiFi Setup ***********************************
void SetupWiFi()
{
delay(10);

// We start by connecting to a WiFi network
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}


Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}