JoaoLopesF / RemoteDebug

Library for Arduino to debug projects over WiFi, with web app or telnet, with print commands like Serial Monitor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Break execution until connected

VoxCodice opened this issue · 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.

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.

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.

Hi, sorry by delay on response

I will see it soon, thanks for this feedback

Regards

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);
}