Page 1 of 2

The acceptance of message from other device to Wifi shield

PostPosted: Thu Mar 16, 2017 1:35 am
by Lim
Hi, i would like to send some text file from other device to cytron wifi shield via HTTP post, but the text file is quite long and every time i send the text file, the wifi shield only can accept part of the text file, is it because of the time out, or the memory out of space, the text file is about 38 kb space

Re: The acceptance of message from other device to Wifi shie

PostPosted: Mon Mar 20, 2017 11:06 am
by bengchet
Hi,

The problem might come from memory problem, depending on which board you are using with your WiFi Shield. If you are using Uno board and you are keeping received text file content in one variable, it will not be enough. However, if you mind share your coding here, we can come up something else.

Thanks.

Re: The acceptance of message from other device to Wifi shie

PostPosted: Tue Mar 21, 2017 11:48 pm
by Lim
Hi, i am just using normal softap example coding to receive the data, and I just serial print out all the data received, but the problem is the connection always break in the middle, I suspect is the timeout issue instead of memory, how to adjust the time out so the wifi and client connection can be on for a time, since the transferring of data takes time

Re: The acceptance of message from other device to Wifi shie

PostPosted: Tue Mar 21, 2017 11:53 pm
by Lim
I saw there are some timeout in the library:
SERVER_TIMEOUT 5
#define COMMAND_RESPONSE_TIMEOUT 5000
#define COMMAND_PING_TIMEOUT 3000
#define WIFI_CONNECT_TIMEOUT 30000
#define COMMAND_RESET_TIMEOUT 5000
#define CLIENT_CONNECT_TIMEOUT 10000

Can I adjust the timeout to ensure the connectivity and how to adjust them?

Re: The acceptance of message from other device to Wifi shie

PostPosted: Wed Mar 22, 2017 11:04 pm
by Lim
I just want to serial print out every character received, without storing into a variable, sometimes it can be transferred fully but sometimes not, the file i sent is around 36kB, and the time taken to fully send is around 35 seconds, how to prevent timeout of any during this period?

Re: The acceptance of message from other device to Wifi shie

PostPosted: Thu Mar 23, 2017 8:17 am
by bengchet
Hi,

May be you can change this line of code

CODE: SELECT_ALL_CODE
while(client.available){
  Serial.write(client.read());
}


to

CODE: SELECT_ALL_CODE
int timeout = 5000;
while(timeout--){
 if(client.available()){
   Serial.write(client.read());
   timeout = 5000;
 }
 else
  delay(1);
}



The suggested coding I haven't tried it myself. But generally it gives about 5 seconds timeout for next character to be received. You can adjust the timeout as you want. The only drawback is after file is transferred completely you still need to wait for timeout to complete. You can do some coding here to break out from while loop immediately once the file transfer is completed.

Let us know if the method works. Happy coding!

Re: The acceptance of message from other device to Wifi shie

PostPosted: Thu Mar 23, 2017 2:35 pm
by Lim
Can I change the baud rate of ESP8266 of the wifi shield, up to 115200, cos the default 9600 is a bit too slow?Do I need to update the firmware of the ESP8266?

Re: The acceptance of message from other device to Wifi shie

PostPosted: Thu Mar 23, 2017 3:10 pm
by Lim
Hi, i have tried your code and the device still cutout in the middle, is it because of client connect timeout?or wifi timeout?

Re: The acceptance of message from other device to Wifi shie

PostPosted: Thu Mar 23, 2017 9:28 pm
by bengchet
Hi,

Few things to clarify:

1) If you are using Arduino Uno, the maximum baud rate allowed is 9600, so far this is the baud rate the shield works the most stable. It is unrelated to the firmware upgrade. This problem is caused by softwareSerial, so far 9600 is the most stable baud rate for data streaming. Unless you are using hardwareSerial, in that case you will need to remove anything related to Serial monitor, meaning you cannot monitor the progress of your coding.

2) When I observe your screenshot, I found that you are uploading your text file using application/x-www-form-urlencoded? If I am not mistaken, normally you use this content-type if you are making simple and not-too-long requests. For uploading, normally you need to use multipart/form-data. In this way, you are sending file to server without encoding, aka with original bytes amount. With x-www-form-urlencoded, the file content is treated as part of url, and normally it will not ended well according to my experience especially when it is in large chunk.

Re: The acceptance of message from other device to Wifi shie

PostPosted: Fri Mar 24, 2017 10:57 am
by bengchet
Hi,

I have tested the file upload. Seems like it is the AT firmware limitation which only allows up to 10~14kb uploaded at one time. After that limit, the connection is closed automatically.

For this case, I am not clear with your application, but I can give few suggestions. You can try them.

1) If the content received are not processed but just stored into some kind of storage like SD card at Arduino side, you can upload the file in .zip format. I have tested, it reduces to around 800 bytes only.

2) If you are going to process the content, you gonna upload the file in separate chunks, like 10kb in one chunk at one time, then you send about 4 times to complete the full upload.