arduinoesp32arduino-c++arduino-esp32blynk

Please specify your BLYNK_TEMPLATE_ID and BLYNK_TEMPLATE_NAME


in this case i want to make a dust monitoring projet with Blynk connection. But when i integrated my program code with blynk template code, i meet some error : #error "Please specify your BLYNK_TEMPLATE_ID and BLYNK_TEMPLATE_NAME"

In this case im very confused, I had declared BLYNK_TEMPLATE_ID and BLYNK_TEMPLATE_NAME at the beginning of the program like the following snippet of my program code:

#include <Blynk.h>
#include <BlynkSimpleEsp32.h>
#include <WiFi.h>

#define BLYNK_TEMPLATE_ID "xxxxxxx"
#define BLYNK_TEMPLATE_NAME "xxxxxxx"
#define BLYNK_AUTH_TOKEN "xxxxxxxx"

But the error says, i must to defined the BLYNK_TEMPLATE_ID and BLYNK_TEMPLATE_NAME. How supposed i do in this case? Thank you

In this case i already try to downgrade my Blynk library from 1.3.0 to 1.2.0, and the problem BLYNK_TEMPLATE_ID and BLYNK_TEMPLATE_NAME error was solved. But with Blynk 1.2.0 libraries my ESP-32 cannot connect to Blynk Cloud.

If i upgrade my Blynk Library to 1.3.0 again, the problem comes again.


Solution

  • tldr: Put your #define BEFORE any Blynk headers

    #include will essentially "copy-paste" the file you're including at the place you have the include. So if the Blynk library has this in one of the headers:

    #ifndef BLYNK_TEMPLATE_ID
    #error "Please specify id"
    #endif
    

    and you define the BLYNK_TEMPLATE_ID later, it will not compile, because at the compilation, the full code will look like this:

    // from Blynk.h
    #ifndef BLYNK_TEMPLATE_ID
    #error "Please specify id"
    #endif
    // Blynk.h end
    #define BLYNK_TEMPLATE_ID "xxxxxxx"
    #define BLYNK_TEMPLATE_NAME "xxxxxxx"
    #define BLYNK_AUTH_TOKEN "xxxxxxxx"
    

    Since the check is before the #define, it will not compile. Also, since this is an auth token, you probably should not define it in code. Instead, you can pass parameter to the compiler to set #define that will apply for the entire compilation.