Bytearrays not sent consistently over socket

Discussion related to "under the hood" OpenMV topics.
Jhc999
Posts: 26
Joined: Fri Nov 06, 2020 4:31 pm

Bytearrays not sent consistently over socket

Postby Jhc999 » Thu Nov 26, 2020 5:14 am

I'm trying to send 8000 bytes from the OpenMV to my PC using sockets with the wifi shield. However, the OpenMV is not sending the message consistently.

Code: Select all

s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
s.connect((HOST, PORT))
s.settimeout(2.0)  

data = bytearray(os.urandom(8000)
s.write(send)
On the PC side, I receive bytes from the socket until the length is 8000. As a test, I print out the lengths of the messages that the PC is receiving. Sometimes the OpenMV sends one message of 8000 bytes and the PC receives all 8000. Sometimes the OpenMV sends 5 messages of lengths 2800, 1400, 1400, 1400, 1000. Sometimes the OpenMV sends 5 messages of lengths 1400, 2800, 1400, 1400, 1000.

For my application, it would be great if the OpenMV is able to consistently send 8000 bytes at once. Or, at least I'd like the OpenMV to send predictable message sizes. The OpenMV uses the same wifi module as the Adafruit Feather M0, but I haven't had this problem with the Feather. Please advise.
Last edited by Jhc999 on Thu Nov 26, 2020 5:17 am, edited 2 times in total.
Jhc999
Posts: 26
Joined: Fri Nov 06, 2020 4:31 pm

Re: Bytearrays not sent consistently over socket

Postby Jhc999 » Thu Nov 26, 2020 5:16 am

Just did another run, this time it sent the 8000 bytes in 3 messages of lengths 2400, 1400, 3800. Not sure what's going on...
User avatar
iabdalkader
Posts: 1285
Joined: Sun May 24, 2015 3:53 pm

Re: Bytearrays not sent consistently over socket

Postby iabdalkader » Thu Nov 26, 2020 8:49 am

The max packet size is 1400 (MTU) it seems some packets are combined on the PC/router side, try blocking until you receive the whole 8000 bytes or send the packet in chunks of 1400 bytes.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest