Mangiare Senza Glutine disponibile su App Store

Per altre informazioni scrivi a

ParsePacket UDP freeze with Arduino

Da Programmazione Software.

Using intensively udp read with Arduino, you'll see that Arduino freeze if you send big packet, > 100 bytes very quickly.

Try this python code to generate data (1000 bytes) to send quickly (every 0.1 seconds):

# Send UDP broadcast packets
MYPORT = 8888
import sys, time
from socket import *
from random import choice
from string import lowercase
n = 1000
s = socket(AF_INET, SOCK_DGRAM)
s.bind(('', 0))
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
led = 0
data = "".join(choice(lowercase) for i in range(n))
while 1:
    led ^= 1;
    s.sendto(data, ('<broadcast>', MYPORT))

parsePacket of EthernetUDP will be frozen in flush() method to dispatch all remaining bytes.

But if in setup() method of your sketch you'll insert these lines:

  // To parse correctly udp packets

Arduino will not frozen, because it'll handle correctly data queue.