// Processing UDP example to send and receive binary data
// https://thearduinoandme.wordpress.com/t utorials/esp8266-send-receive-binary-data/
// Badly hacked by Ray B. to display the UDP broadcast from ESP8266
import hypermedia.net.*; // http://ubaa.net/shared/processing/udp/udp_class_udp.htm
String ip = "10.10.10.1"; // the remote IP address of ESP8266
int port = 8888; // the destination port - any unused port
long previousMillis = 0;
long interval = 500;
UDP udp;
void setup() {
udp = new UDP(this, 8888);
udp.listen( true );
}
void draw() {
if (previousMillis < millis() - interval) {
previousMillis = previousMillis + interval;
byte[] message = new byte[2];
message[0] = 0; message[1] = 0;
udp.send(message, ip, port);
}
}
void keyPressed() {
if (key == '-')
{
byte[] message = new byte[2];
message[0] = 0; message[1] = 0;
udp.send(message, ip, port);
}
}
void keyReleased() {
if (key != '-') {
byte[] message = new byte[2];
message[0] = 0; message[1] = 0;
udp.send(message, ip, port);
}
}
void receive( byte[] data ) { // <– default handler
for (int i=0; i < data.length; i++)//void receive( byte[] data, String ip, int port ) { // <– extended handler
print(char(data[i]));
println();
}
Moderator: igrr
The code supplied above needs to know the ip of the UDP broadcaster...sure it is in the UDP packet but it isn't known at compile time.
I see you point with Unix
It is unpleasant for Microsoft to decide what I can do in the way on networking with Win 10 on a PC I own and with a Home network that only serves my home and is also fully owned by me. I was hoping we were past 1984 and big brother corporations. What I don't get is that if I turn off the Microsoft firewall it still seems to firewall
broadcast UDP packets.
I used Docklight scripting.
https://docklight.de/downloads/
I know it is written Serial port terminal but it can do TCP/UDP/USB HID communication too.
Just go to Tools-> Project settings
and type in
Send/Receive Comm.: UDP:255.255.255.255:9761
and press "play" button or F5 to start.
It will send broadcast packages to specified port (9761) to network and also receive broadcast packages at that same port to terminal window.
You can use Send/Receive sequences to define strings to send or recognize at reception or activate keyboard typing with Ctrl+F5 or click on the keyboard icon.
I have received broadcast packets from client on same subnet, but also when client with completely unrelated random IP/SUBNET/GW is sending them. No problem there.
Great option for device detection on network is needed.