UDP Python script is not working if arduino is started from scratch

Hi guys,
I have a issue with my yun in conjunction with python. The python script sends udp broadcasts and works fine from ssh.

Case 1.
I connect my arduino by usb and upload my ino file, the python script works properly

Case 2.
if I start the arduino with the uploaded file from scratch, the python script doesn’t work.

It seems like a timing issue. I tried with several delays in the setup method to give linux a chance to start up but without success.

#include <Process.h>

String sText = "python /$HOME/send_udp.py off"; 

unsigned int runShellCmd(const String &cmd)
{
  Process p;
  
  p.runShellCommand(cmd);
  while(p.running()); 
  while (p.available() > 0) 
  {
    char c = p.read();
    Serial.print(c);
  }
  Serial.flush();
}

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

  // Wait until a Serial Monitor is connected.
  while(!Serial);
  
  Serial.println("Running Shell Commands...");
  for (int i=1;i<20;i++)
  {
    runShellCmd(sText);
    Serial.println(i);
    delay(1000);
  }
  Serial.println("\nEnd."); 
}

void loop()
{
   Serial.println("... in loop");
  
    runShellCmd(sText);
    Serial.println(i);
    delay(1000);
   
}

Thanks for your help
Andreas

Since you have a while(!Serial); I suppose you're opening the serial monitor in both cases. Try putting a Serial.println("hello") after that "while" and check if it gets printed

Hi Frederico,

I removed all serial commands. Just now it works also from scratch. I don’t know what is the problem with serial commands.

Greetings Andeas

Well, if my guess was correct, your sketch required you to open serial monitor before starting. Maybe you didn't when you restarted the yun