Device getting disconnected while sending data

Hi,

It is been a week we started seeing device disconnection once in a while during data upload operation to AGENT. The only change committed in that code is to increase the upload data size from 10K to 30K.

Any pointers for this behavior ?.

Attaching the server log screen shot.

Uploading 30k in one go will typically cause the imp to block while it sends all the data up (especially on high latency connection) this means it won’t be able to respond to server pings and so gets marked offline. You can either increase your send buffer size (https://electricimp.com/docs/api/imp/setsendbuffersize/) to be larger than your maximum transmit or you can break the data down into smaller chunks and send them one at a time (non-blockingly).

The other option is to ignore those messages entirely. The agent should still receive the data so unless you are tracking disconnects it doesn’t really matter.

Thanks brandon. This almost breaking the application functionality. The data uploaded in multipart and we are running the device in “return-on-error” mode. Once the device gets disconnected while uploading one part the entire upload operation is coming to halt.

I will try by increasing the buffer size using setsendbuffersize.

Ah, so what you are likely running into is a setsendtimeoutpolicy issue (https://electricimp.com/docs/api/server/setsendtimeoutpolicy/). If you have a sendtimeout which is shorter than it takes to transmit data minus free space in sendbuffer then you will always timeout on that transmit. The solution is to increase sendtimeout, decrease data or increase sendbuffer. Increasing the sendbuffer has the added advantage of faster throughput but the drawback of eating more memory.

Just verified the code, timeout is set to 120 seconds.