I've been tasked to create a proof of concept with an Arduino Mega + Yun Shield. I've started from the Bridge sample and I can read my sensors and exposed the data through REST.
But, instead of REST, I want to send packets through UDP. I know there is samples around the web about UDP but I've have found nothing that use UDP with Bridge.
Is this feasible?
UPDATE #1
Ok, I read somewhere that is not possible. But I read also that is possible to run a Python script to send data through UDP.
I made that script:
import socket
import sys
# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = ('192.168.1.100', 9050)
message = 'This is the message. It will be repeated.'
try:
# Send data
print >>sys.stderr, 'sending "%s"' % message
sent = sock.sendto(message, server_address)
finally:
print >>sys.stderr, 'closing socket'
sock.close()
And call it from the Arduino this way:
Process p;
p.begin("python");
p.addParameter("/test/sendUDP.py");
p.run();
The code run without errors apparently, but my UDP server receive nothing. However, it works with PuTTY.
UPDATE #2 It works! I changed this line:
p.addParameter("/root/test/sendUDP.py");
I changed this line and it works like a charm:
p.addParameter("/root/test/sendUDP.py");