I have an Arduino Yun connected via ethernet to my PC.
Although I receive successfully UDP packets from my PC, I can't send UDP packets from Arduino to my PC.
This is my code:
#include <Process.h>
#include <BridgeUdp.h>
BridgeUDP Udp;
IPAddress IP(172, 31, 92, 10); //MY PC'S IP
void setup() {
Bridge.begin();
Udp.begin(9911);
Serial.begin(9600);
}
void loop() {
//TAKES UDP - PRINTS TO SERIAL
if (Udp.parsePacket()) {
int udp_received = Udp.available();
char udp_buffer[udp_received + 1];
Udp.read(udp_buffer, udp_received);
udp_buffer[udp_received] = '\0';
Serial.println(udp_buffer);
}
//SENDING UDP TO PC (TESTING)
char udp[] = "test";
Udp.beginPacket(IP, 9911);
Udp.write(udp, sizeof(udp));
Udp.endPacket();
delay(1000);
}
I send UDP packets from PC to Arduino using ncat -u 172.31.92.3 9911.
Then I use ncat -lu 172.31.92.10 -p 9911 to set up a UDP listening server on my PC, but I receive nothing from Arduino.
UPDATE:
Monitoring the connection with Wireshark shows that UDP packets from Arduino Yun to PC are actually sent, but I still can't see them in the console of the listening server.