What can I do about runtime errors? I'm sure its in a tutorial, manual, or post that i can't find. I see posts saying error code 2 (et al). where/how do I see the 2?
Any code, any board I use mostly pico or ESP8266 variants, (d1-mini, node mcu, etc) how do I get the rc? Maybe the same question, how do i know what each rc means, wade through the .cpp file?
My latest MQTT project runs for an hour or a day, then just stops. I'm sure, even without try-except, I could somehow deal with the error if I could only get the error/return code. Several times I've caught line X execute a dianostic print and then it hangs without executing the publish (the very next line). It has already executed this sequence 5 or 100 or 53000 times. There has to be an error code or return code, but any search I try describes compile time errors. Can I capture runtime error/rc? What I'd like to do in several scripts is a poor man's try catch, try accept sub routine:
If return code X, run MyFunction, or lite an LED. Is that possible?
there is no general registry of error codes. Each library / piece of code is free to use whatever code it wants to report that something went wrong. So you need to either look at the documentation if there is one, otherwise in the source code to see which issue returns which code.
The compilation process on Arduino does not support try/catch Exceptions handling (too memory intensive).
It sounds very likely that your problem is caused by an array bounds exception or the sketch running out of resources
In the case of arrays, you should do a bounds check before using any value as an array index and either prevent the error by adjusting the index value or better by outputting a message
Resource usage is more tricky. Does your sketch use String objects by any chance ?
Thanks, i was afraid of that. Then how about the bigger issue. My code runs for some period of time then I suspect wifi burps, or MQTT hickups or something happens. If there is a return code, can I capture it? If it's a rc, I should be able to do something about it if I knew what happened. How do I capture rc?
In other languages with a "try" I could - try this; except print e
Then rewrite to handle e, but if i cant see the "e", I can't respond.
I publish the same string each time in this pgm. On a pico, I publish "vac1" (to prove he's running in a single thread) then sub on a d1- mini and if I miss 5 timed pubs in a row, this whatever hang has happened so the mini uses a gpio to hit a relay which POR the pico. But if I could see the rc of the hanging pub on the pico I may not need the mini for the sole purpose to POR the pico (tried proc 0 resetting proc1, but couldn'tmake that work monitoring heartbeat LED gpio).
I don't need this bug fixed for me, i just can't find how to capture a return code so I can deal with it. Like if wifi not 3 start wifi again (or whatever rc that would be). I dont think I can Serial.print because it's hung. Did I just answer my own question or ... How if something if i don't know the something? Assume it's non 0? How do I capture any return code in any Arduino IDE program?
Oh, no array involved
Can't do: if (rc0) do this mqtt pub because its the pub causes the rc. Is there as way to say pub this mqtt, now what was the rc for that pub?
I am intrigued by this example
Please post the section of code that you use to start WiFi
I don't use a 3. I use the standard in most samples and posts
Wifi.begin(ssid, pw);
While (wifi status() != wl_connected){
Delay(500);
Serial.print(,);
}
And I think the wl_connect is a 3
But that is not the point. Hmmm how do I know about wifi.status()? More germaine something.status, or
if (rc){ for mqtt or whatever I'm using at the time. Or simpler how do i get the rc and ill figure out what that rc means. This is not a bug this is training me. How do i get the return code in a running program so i can do something to correct a situation?
And where on the phone is the format tool bar for ?
it will depend on your Arduino and the network library you use. On an ESP32 you can set callbacks on various events happening to your WiFi with WiFi.onEvent()
see this example an for example ARDUINO_EVENT_WIFI_STA_DISCONNECTED will be fired if your ESP32 looses WiFi
When a call does not succeed sometimes you also get an error code upon return, so you need to also deal with that.
In a more general term, as you can't try and handle things if it fails (esp. if you end up stuck) you need to check first if everything is fine to be successful.
Im a very simple kind of guy. If I could find wifi.h there should be a wifi.cpp I think. Where do I look to find WL_CONNECTED and if it is 3, where do i see that.
The structure should be similar on other libraries. If it is missing, oh well. But if there are codes in a library are they in a table in .cpp or scattered through the .h ???
Or where do i go to learn such structural things. As far as I know return codes should be run time info. I thought the question was simple, but I have communication issues, so is the question clear? "If they exist for a given library, where are the return codes and how do I print them in a running program?"
Very cool, sorry I was typing (old and one fingered at typing) and missed this. Trouble sharing screens on phone and can't find all this detail on laptop (my first post). Is that wifi.cpp? I don't see any that use parms or explanations outside of intuitive names.
Now i see the printlines, i thought, who cares what I thought. Now with that example, I include wifi.h like you sent me. Where is wifi.begin(ssid, pw). How do I know its not wifi.start and what parms if it wasn't in EVERY sample online. And where does it say WL_CONNECTED and what rc that is
here
it's from the Arduino API documentation
you should never need to know it's promoted to the integer 3, your code should always use WL_CONNECTED as the real type is wl_status_t, not int and it's always best to compare within the same type rather than rely on promotions.
Very cool, now I'm starting to understand. There will be a source file for TickTwo.h, AsyncMqtt.h, and MCP_ADC.h, (their GitHub??)
So in AsyncMqttClient_Generuc the only rc are listed under enum?
All I get is:
CONNECTING
CONNECTED
DISCONNECTING
DISCONNECTED
No subscribed
No published
No recieved
I'm dead! Am I reading that right? Is that what enum means?
sure
etc
or just look in your Library directory you probably installed them
can you provide a link to the library you used?