ESP-IDF for Arduino Users Tutorials Part 3, App Setup and Loop

This is the 3rd part of a series of ESP-IDF tutorials that I will complete as I learn stuff. Read part 2.

Arduino uses this idiom which we all know and love.

// Set up the application
void setup() {
}
// Loop forever
void loop() {
}

On first sight this seems absolutely fine. On second sight it seems fairly ridiculous. Let’s rewrite it as ESP-IDF expects it.

void app_main() {
// Set up the application
for (;;) {
// Loop forever
}
}

Every other use of C for making executable applications uses the rewritten idiom. For me, this is an example of adding an abstraction that attempts to make things easier but actually obscures things and makes them ultimately harder —

should this piece of code be in setup() or loop()?

Well, you know what, it doesn’t matter.