RemoteDebug icon indicating copy to clipboard operation
RemoteDebug copied to clipboard

Break execution until connected

Open VoxCodice opened this issue 5 years ago • 4 comments

Would it be possible to add a function which will pause the execution of all code until someone connects to the debugger?

It would be useful in situations where, for example, you have some code that is executed during setup, before you have the chance to connect.

VoxCodice avatar Mar 29 '19 21:03 VoxCodice

HI @user1969903

You can use this code, after Debug init codes :

while (!(Debug.isConnected())) { Debug.handle(); delay(250); }

You can use the setSerialEnabled to see debugs in setup.

JoaoLopesF avatar Mar 31 '19 13:03 JoaoLopesF

Thanks for the info. I actually used the custom function capability of the library to write my own 'break' function and called it during setup but it is good to know that this functionality exists out of the box. Is this documented anywhere? I was not able to find it prior to asking this question. If it isn't, perhaps you could include a list of all exposed methods on the main page of this git.

VoxCodice avatar Apr 23 '19 14:04 VoxCodice

Hi, sorry by delay on response

I will see it soon, thanks for this feedback

Regards

JoaoLopesF avatar May 09 '19 20:05 JoaoLopesF

I ended up using a small modification in my sketch so that in case I never connect the sketch will still run. I chose a 20 second delay to ensure Wifi had time to fully connect (it seems to take somewhere between 10 and 15 seconds on my network using a static IP, but you can tweak it to suite your needs).

Here's the code:

unsigned long launchMillis = millis();
while (!Debug.isConnected()) {
    Debug.handle();
    if (millis() - launchMillis > 20000) break; // Allow 20 seconds to connect before starting
    delay(100);
}

einsteinx2 avatar Jul 24 '19 19:07 einsteinx2