Correct method of writing Blynk IOT code

I normally use VSC and platformIO to write my code and declare function prototypes after the includes and defines. I then have my setup and loop functions, with all functions after the main loop. Looking at the Blynk IOT code examples, and playing, about with them, it doesn’t seem to me that they need prototype declarations. Additonally it appears the BlynkIOT functions can be placed anywhere in the code. I presume the Blynk IOT library ‘finds’ the Blynk functions, is that correct?

Function prototypes are something that aren’t really needed in C++. You can use them if you want to do it that way, but you can’t use them for Blynk’s ‘special functions - which are in effect callbacks - like BLYNK_WRITE(vPin) and BLYNK_CONNECTED().

The only thing to beware of is that the three lines of firmware code from the Device screen in the Blynk web console MUST be at the top of your sketch.


Thanks Pete, Callbacks was what I was missing. Yep, adopted the discipline of putting the formware code at the top. For whatever reason I have to use prototypes in PIO and I am happy to do so because, for me anyway, it is a more structured way to work. Each to their own eh!

1 Like

Yep, if that’s what you’ve grown-up with then it’s good to keep-up that method.
Also essential when you’re using ISRs, so all good if you use them.