UDP supported?

Yun seems to be great!

Can i send UDP Packets with Bridge Library?

Short answer: no, but you can make a script in python (or your favourite language) and invoke it with the Bridge

Longer: Bridge is made to give your sketch access to the linux console, to a shared in-memory storage to share data between your sketch and the outside world, and to create sort of REST APIs to communicate with your sketch (see the Bridge and the TemperatureWebPanel examples) In order to play with low level networking, your should create a script with python (or ruby or others) and call that script from your sketch via Bridge

hmmmmmmm .....

understand, this makes YUN really flexible.

But basic stuff like UDP should work out of the box.

Wifi Library and Ethernet Library supports UDP.

If you have existing UDP code (which uses Ethernet or Wifi Library) and you want to migrate to YUN, then you will miss the UDP library ...

i hope this is coming soon

UDP broadcasts are very helpful to announce hardware on LANs and is necessary for Plug and Play Hardware if YUN acts as a server ...

no, UDP broadcasts are required

i want easy UDP support for YUN from the ARDUINO side - out of the box

Most Arduino users want it convenient. The Ethernet Library and WiFi Library did it in a good way.

It looks for me that it is simply forgotten in the YUN Bridge Library

I know that i can do a lot of stuff on the linux side as Federico Fissore already explained, but this it is inconvenient ...

@RalfK if your requirements for the broadcasted message are not too strict, you can do what the yun is already doing to notify the IDE of its presence

In folder /etc/avahi/services you'll find an arduino.service file: google for more info on avahi and how it works

Basically, dropping an appropriate .service file in that folder, avahi will broadcast its contents

Federico, thanks for the hint, i think this will be helpful ...

But for now, i will put the YUN in the corner and progress the project with Arduino Ethernet. Still hoping that the bridge library will be extended soon ...

What do you think, any chance that there will be an updated or extended Bridge Library in the near future?

There surely will be, not just one, but many updates.

[quote author=Federico Fissore link=topic=187287.msg1395840#msg1395840 date=1379488730] There surely will be, not just one, but many updates. [/quote] This thread is now 6 months old!

I would like to use the standard Arduino Ethernet UDP and Wi-Fi UDP libraries with the Yun and I was hoping that this would have been implemented by now.

Failing that would someone post a complete sketch that would show me (an oldie) how to send and receive simple UDP messages from the "Arduino" side of the Yun. I have a number of sketches running on a Uno with an ethernet shield and I would like to run these using the Wi-Fi on the Yun.

Even use the standard Arduino Ethernet UDP and Wi-Fi UDP libraries at regular arduino might be not smart move.

sonnyyu: my 2 cents;-

UDP is a lightweight protocol that by design doesn't handle things like packet sequencing. It does not guarantee that your packets will arrive in order (It does not even guarantee that your packets will arrive at all.) . Say send command set voltage=1 v, then set voltage=4 v, You might get 0v or 1v or 4v if default is 0v. TCP is a better choice if you want robust packet delivery and sequencing. If you're limited to using UDP you would have to develop a method of identifying the out of sequence packets and resequencing them or request to resend, but for Arduino is tough task.

a lot people implement UDP with Arduino, I mean neither OP nor this thread please hold fire.

I guess either they drink too much Italian coffee or I drink too much, might be both. :P

Let's stay in TCP.

Let's stay in TCP.

The advantages of TCP are known

But it is NOT possible to broadcast with TCP

UDP is required !!!

It is a best practicee to announce a arduino device with UDP broacast in a network. This makes PnP possible ...

Lets stay TCP and UDP

UDP is a lightweight protocol that by design doesn’t handle things like packet sequencing. It does not guarantee that your packets will arrive in order (It does not even guarantee that your packets will arrive at all.) .

In my UDP application the received packets are order independent and keyed so that I can action them correctly.

My problem is that I can’t get started with how to implement UDP on the Yun so I would appreciate a complete sketch from someone.

Yun is based on Linux that has full stack of TCP/UDP. It answer PnP problem by implemented Zero-configuration networking via Avahi (similar to Apple Bonjour). Avahi uses IP multicast User Datagram Protocol (UDP) packets.

Beside broadcast, anytime low-latency, real-time overweight guarantee packet delivery and sequencing such as audio or video stream use UDP at most case.

My "Let's stay in TCP" which only stay bridge between Arduino and Yun.

Lets stay TCP and UDP :P

When I send the command 'echo "G" | nc -u 8888' to an Arduino Uno on my network from the Terminal app in OS X I receive the expected response of G,42

When I try to send the same command from a Yun, using the script shown below, the p.runShellCommand never seems to finish.

Sending 'echo "L12" | nc -u 8888' to my Uno from the Yun should switch on one of my Wi-Fi lights but this does not happen, although the same command issued in the Terminal app does.

How can I check that the UDP message is being sent?

  Running shell commands using Process class.

// cmd = echo "G" | nc -u 8888
String cmd = "echo \"G\" | nc -u 8888";

void setup() {
  Bridge.begin();  // Initialize the Bridge
  Serial.begin(9600);  // Initialize the Serial

  // Wait until a Serial Monitor is connected.

void loop() {
  Process p;

  // do nothing until the process finishes, so you get the whole output:

  // Read command output.
  while (p.available() > 0) {
    char c = p.read();
  delay(5000);  // wait 5 seconds before you do it again

At Yun:

nano /mnt/sda1/udp.py
import socket
UDP_IP = ""   #Mac or Linux box's IP
UDP_PORT = 8888
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.sendto(bytes(MESSAGE), (UDP_IP, UDP_PORT))
chmod 755 /mnt/sda1/udp.py

At Linux/Mac box( wait to call):

nc -ul  8888

At Yun:


If every thing is OK( Mac Box got "G"), then change UDP_IP = "Uno IP address", test it again.

Now is time make Arduino of Yun to call "/mnt/sda1/udp.py"

String cmd = "/mnt/sda1/udp.py";

Thank you for taking the time to help me. You have certainly given me a lot to think about.

I understand the procedure that you have set out but I still need to sort out how to implement the various bits of code but I will try.

Many thanks, Richard

Thank you for putting me on the right track :) I am now able to control my Wi-Fi lights from the Yun.

I have learnt a lot with your help.

However, I am missing one feature now. Some of my UDP commands have replies and I would like to retrieve them. I think that I can modify the Python script to get the reply but how do I pass the reply back to the Arduino side of the Yun?

Did you like try this?

#print recvmsg

sonnyyu: Did you like try this?

#print recvmsg

I have just modified the Python code to include recvmsg=sock.recv(1024)

print recvmsg

and I still do not get a reply sent across to the Arduino side of the bridge. What does #print recvmsg do?