I have a sketch which contains a function called from loop() that does the following:
memset(&pkg, 0, sizeof(pkg));
pkg.cmd = REQ_ID_STREAM_INFO;
pkg.payload.stream_info.width = camera.width();
pkg.payload.stream_info.height = camera.height();
Udp.beginPacket(ctx->ip, ctx->port);
Udp.write((uint8_t *)&pkg, sizeof(pkg));
Udp.endPacket();
// frame proper
memset(&pkg, 0, sizeof(pkg));
pkg.cmd = REQ_ID_STREAM_FRAME;
pkg.payload.frame_size = camera.frameSize();
Udp.beginPacket(ctx->ip, ctx->port);
Udp.write((uint8_t *)&pkg, sizeof(pkg));
Udp.write(camera.raw(), 30);//camera.frameSize());
Udp.endPacket(); // OCCASIONAL FAILURE HERE
The last line occasionally fails.
I've noticed it doesn't fail when I reduce the number of bytes written to the second frame or when I introduce a delay between two packets.
Should it be like that or is it just a coincidence?
Can I check somehow that the packet has been sent and I can feed Udp more data? Should I do it?
I'm using WEMOS D1 Mini Lite based on ESP8285, WiFi client mode.