-->
Page 1 of 1

some problem with WiFiClient in arduino enviroment

PostPosted: Sun Apr 09, 2017 4:47 pm
by nikan110
hi to all, i am working on project that in it i need some file(around 750kb) to my device and i decide to use esp8266 in order to done that.i successfully config arduino and now i can use arduno ide to write program for esp8266.
but i have a problem, when i send my file from my computer to esp8266, i can only find part of that on esp8266; for example when i send a 750kb file i can receive only 5 kb on esp8266 and i do n't know what is problem.
here is my code
Code: Select all#include <ESP8266WiFi.h>

uint8_t data = 0;

WiFiServer server(8888);
int counter = 0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);

  WiFi.softAP("akbar","akbar11041");

 
  server.begin();

}

void loop() {
   // put your main code here, to run repeatedly:
   WiFiClient con = server.available();
   
   if(con)
   {
      Serial.println("new connection");
      counter = 0;
      while(con.connected())
      {
        if(con.available())
        {
          counter += con.read(&data,1);
         
          Serial.print(data);
         
        }
      }
      Serial.println("Connection closed");
      Serial.println("number of items :");
      Serial.println(counter);
      con.stop();
   }
}

and i use below python code to send data to esp:
Code: Select allimport socket
import time



fl = open("2.dat","rb")
data = fl.read()
con = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
con.connect(("192.168.4.1",8888))
con.send(data)
con.close()
fl.close()


i am new in esp and i do n't know hove solve this problem,any one can help me ???

Re: some problem with WiFiClient in arduino enviroment

PostPosted: Thu Apr 13, 2017 11:41 am
by jeffas
It probably isn't a good idea to try to read the whole file in one call of loop(). For example, sitting for a long time in loop() won't let the watchdog run. I'm not sure that this would cause your problem, but I'm pretty sure that you should read whatever is available, and then return from loop() (which will be called again soon after, and you can then read some more).