It seems that after sending an UDP packet I can't receive others anymore.
Here my code:
#include <LwIP.h>
#include <STM32Ethernet.h>
#include <EthernetUdp.h>
#include <OSCMessage.h>
#include <OSCBundle.h>
#include <OSCData.h>
#include <Servo.h>
byte mac[] = { /* ... */ };
byte ip[] = { 192, 168, 0, 222 };
const unsigned int port = 9999;
byte outIp[] = { 192, 168, 0, 250 };
const unsigned int outPort = 9999;
EthernetUDP Udp;
OSCErrorCode error;
long previousMillis = 0;
void setup()
{
Serial.begin(115200);
Ethernet.begin(mac, ip);
Udp.begin(port);
}
void led_handler(OSCMessage &msg, int patternOffset)
{
// do something
Serial.println("received!");
}
void sendBundle(int ch)
{
OSCBundle bundle;
char address[32];
sprintf(address, "/led/%u", ch + 1);
bundle.add(address).add((int32_t) 1).add((float) 0.05);
Udp.beginPacket(outIp, outPort);
bundle.send(Udp);
Udp.endPacket();
Serial.println("sent!");
}
void processOSCMessage(void)
{
OSCBundle bundle;
int size = Udp.parsePacket();
if (size > 0)
{
while (size--) bundle.fill(Udp.read());
if (bundle.hasError())
{
error = bundle.getError();
Serial.print("error: ");
Serial.println(error);
}
else
{
bundle.route("/led", led_handler);
}
}
}
void loop()
{
processOSCMessage();
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > 5000) {
previousMillis = currentMillis;
sendBundle(1);
}
}
Every 5 s it sends out the UDP packet, but it receives the incoming packets only before sending out the first one.
Am I missing anything obvious?