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?
/*
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
}