Defining a UDP port to write to (Arduino WiFi)

Hi all. I'm taking my first steps into Arduino WiFi. I'm looking to get an AdaFruit Feather M0 communicating with MaxMSP.

I'm playing around with the WiFiUDPSendReceiveString example code and am having some success. I can send to the Feather from Max via the [udpsend] object, but am a bit stuck on how to return a message to Max's [udpreceive] object.

The example code is sending data back to the port from which it received data, which I can see in the serial monitor, but the upd send/receive objects in Max cannot (so far as I understand) connect to the same port - see the attached image for the error that Max's console gives.

How would I define a specific port for the Feather to write data to? I have only a rudimentary understanding of what the code does, so I'm sure the answer is obvious.

image

image

so the example reads the port from the received message and uses it as port to send the message. this is not a common usage.
just use any port you want in beginPacket

Thanks @Juraj - so the line that contains

    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());

I can enter any port number within the brackets after Udp.remotePort?

EDIT - I get a 'no matching function for call to WiFiUDP::remotePort(int)' message when I do that.

@Juraj meant that you replace Udp.remotePort() with an integer, not place an integer inside the parenthesis.

Udp.beginPacket(Udp.remoteIP(), 612);

1 Like

Udp.remotePort() gets the origin port of the last received message.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.