[Solved] Send packets via Wifi to udp port

Hi,

is there any option like the "EthernetUDPWrite", but through wifi?

Thanks.

vicmerlis:
Hi,

is there any option like the "EthernetUDPWrite", but through wifi?

http://arduino.cc/en/Reference/EthernetUDPWrite

Thanks.

Yes,
Just as a reminder, this is the Yún section of the forum for Arduino

Start Here:
Arduino Yún

Then read:
Guide to the Arduino Yún

Make sure to read:

Configuring the onboard WiFi

Communicating with OpenWrt-Yun via Bridge

Using Bridge to pass information between processors

AND, of course, read the 'Reference Section' on the Bridge:

Jesse

jessemonroy650:
Start Here:
Then read:
Make sure to read:
AND, of course, read the 'Reference Section' on the Bridge:

It's always good advice to read the documentation. But would you please be so kind as to tell us where in all of that documentation it says anything about UDP? Lots of examples on different ways to communicate using TCP streams, but not one mention of UDP that I can find.

I don't believe the Bridge library, or any other Yun compatible library has any native UDP support. (Only the EthernetShield library mentions it, but that library doesn't work with the Yun.) I think you will have to do the UDP communications with code on the Linux side, and then communicate with that code using one of the Bridge library features. I'd love to be proven wrong.

UDP between Arduino Uno to Arduino Yun.

TCP over UDP

sonnyyu:
UDP between Arduino Uno to Arduino Yun.

Thanks for the link. As I suspected, control the UDP socket from the Linux side.

TCP over UDP

This made me do a double take! :o I first read it as a proposal to do a TCP stream on top of a UDP socket. That would be quite the feat! (And a terrible waste of effort!) But now that I followed the link, I see it's a discussion of the pros and cons of TCP vs UDP. That makes a lot more sense. :wink:

ShapeShifter:
::::

I don't believe the Bridge library, or any other Yun compatible library has any native UDP support. (Only the EthernetShield library mentions it, but that library doesn't work with the Yun.) I think you will have to do the UDP communications with code on the Linux side, and then communicate with that code using one of the Bridge library features. I'd love to be proven wrong.

Yes, you are right. With the Yun, the method to use is: have Linux do the UDP communications.

I guess I've just been working with this so long, I did not think I need to explain that.
Please forgive, I'll try to be more aware in the future.

Also, thanks to Sonnyyu for posting the link to the example code.

Jesse

Thanks sonnyyu.

i decide to try the python script from the linux side befor i use yun.

my script is:

#!/usr/bin/python
import socket
UDP_IP = "82.80.159.211" #Server IP address
UDP_PORT = 8001 #Server port

MESSAGE = [01, 00, 48, 00, 33, 33, 33, 33, 33, 01, 01, 01, 02, 02, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 01, 01, 31, 3]

for i in range(len(MESSAGE)):
print MESSAGE
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
a = sock.sendto(bytearray(MESSAGE), (UDP_IP, UDP_PORT))
print a
sock.close()
[/quote]
and i get the following output:

(i ran the script on linux and windows)
but nothings happened on the server side....
i try to use "Packet Sender" software. i send the same packet to same ip and port and i get succesfully the packet on the server side.
do you see any problme with my script?

I'm not familiar with the socket library, and I don't know if this is significant. But I do see something different between the example code and your code.

The example opens the socket, sends a message, receives a response, and then closes the socket.

Your code opens the socket, sends a message, and closes the socket.

Could the socket transmission be asynchronous, and you are closing the socket before the outbound message gets sent? With the example waiting for a response, that would automatically give enough time for the outbound message to actually get sent.

It's a shot in the dark, but does adding a delay() call between the send and the close help? I'm not proposing that as a good final solution, just as an aid in testing.

Hopefully someone with some experience in the library will speak up.

Edit: I don't think this is the issue. Looking at some socket documentation, by default the socket is created in blocking mode. In that mode, sendto() doesn't return until the data is sent. In addition, the description of close() states that the socket is closed after all queued data is flushed.

You say you've tested your receiver side code. Did you try using a packet sniffer like WireShark to see what (if anything) is sent by your python code? Perhaps some data is going out, but it's not addressed or formatted properly? Might give a clue...

vicmerlis:
Thanks sonnyyu.

i decide to try the python script from the linux side befor i use yun.

my script is:
and i get the following output:
::::

(i ran the script on linux and windows)
but nothings happened on the server side....

i try to use "Packet Sender" software. i send the same packet to same ip and port and i get succesfully the packet on the server side.

do you see any problme with my script?

I'm looking at your script I don't see any problems, but I do question your payload.

I have working code here:

Ignore the multicast, just use the send_unicast.py and receive_udp.py in the directory -> simple_ex/
Once that works, you can try the send_unicast.py and uni2multi.py in the root directory.
(comment out appropriate lines, if you do.)

Also, I run on Linux or FreeBSD; I depend on associates for Mac and Windows.
Currently running Linux 3.13.0-43-generic #72-Ubuntu SMP.

Lastly, on closing the socket too early, I forget if that is an issue. I usually depend
on my notes in the code. FWIW: I know over a dozen computer languages, and
I often forget details such as this -- to my OWN hazard!

Let me know how it goes.

Best of Luck
Jesse

Thanks ShapeShifter. i found the problem with the help of wireshark :slight_smile:
the problem was on my side.

Thanks jessemonroy650. i'll use the receiver code.

vicmerlis:
Thanks ShapeShifter. i found the problem with the help of wireshark :slight_smile:
the problem was on my side.

Would you please share the problem and solution? It could help the next person who has that problem and finds this thread.

ShapeShifter:
Would you please share the problem and solution? It could help the next person who has that problem and finds this thread.

The problem was with the configurations of my router, some issue with the static ip (to solve the problem i’d restarted the router configuration).

*** I think it will be more helpful if the admin of this forum will post a sticky messages of a common problems ***

Thanks :slight_smile: