Go Down

Topic: UDP supported? (Read 24979 times) previous topic - next topic

RalfK

Yun seems to be great!

Can i send UDP Packets with Bridge Library?

federicofissore

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

RalfK

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



RalfK

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


RalfK

no, UDP broadcasts are required

RalfK

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 ...



federicofissore

@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

RalfK

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?




federicofissore

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

richard47


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

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.

sonnyyu

#10
Mar 22, 2014, 09:02 am Last Edit: Mar 22, 2014, 09:06 am by sonnyyu Reason: 1
Even use the standard Arduino Ethernet UDP and Wi-Fi UDP libraries at regular arduino might be not smart move.


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.

RalfK

Quote

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

richard47


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.

sonnyyu

#13
Mar 22, 2014, 11:19 am Last Edit: Mar 22, 2014, 11:22 am by sonnyyu Reason: 1
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






richard47

When I send the command 'echo "G" | nc -u 192.168.1.123 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 192.168.1.123 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?

Code: [Select]
/*
  Running shell commands using Process class.
*/

#include <Process.h>
// cmd = echo "G" | nc -u 192.168.1.123 8888
String cmd = "echo \"G\" | nc -u 192.168.1.123 8888";

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

  // Wait until a Serial Monitor is connected.
  while(!Serial);
}

void loop() {
  Process p;
  p.runShellCommand(cmd);

  // do nothing until the process finishes, so you get the whole output:
  while(p.running());

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

Go Up