Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receive doesn't work after sending a message #99

Open
ghost opened this issue Jan 19, 2019 · 1 comment
Open

Receive doesn't work after sending a message #99

ghost opened this issue Jan 19, 2019 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 19, 2019

I'm not sure where the problem is, here my code:

#include <LwIP.h>
#include <STM32Ethernet.h>
#include <EthernetUdp.h>

#include <OSCMessage.h>
#include <OSCBundle.h>
#include <OSCData.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 can receive incoming packets until the first one is sent. After, it doesn't receive anything anymore.

@alf45tar
Copy link

alf45tar commented Feb 8, 2020

Use 2 different EthernetUDP variables. One for udp packet input and one for udp packet output.

EthernetUDP UdpIn;
EthernetUDP UdpOut;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant