#error "Please specify your BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME" Blynk 2.0

@Zeath did you read the post I linked here…

I’ve tested this and can’t find a bug - only user error where BLYNK_DEVICE_NAME continues to be used instead of BLYNK_TEMPLATE_NAME.

Can you provide an example sketch where the code won’t compile?

Pete.

Hey @PeteKnight sure here’s it is

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

#define BLYNK_TEMPLATE_ID "**********"

#define BLYNK_TEMPLATE_NAME "*************"

#define BLYNK_AUTH_TOKEN "****************************"

char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = "***********";             //Enter your WIFI name

char pass[] = "***********";            //Enter your WIFI password

//Get the button value

BLYNK_WRITE(V0) {

  digitalWrite(D4, param.asInt());

}

void setup() {

  //Set the LED pin as an output pin

  pinMode(D4, OUTPUT);

  digitalWrite(D4, LOW);

  //Initialize the Blynk library

  Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);

}

void loop() {

  //Run the Blynk library

  Blynk.run();

}

That’s because these three lines of code aren’t at the very top of your sketch…

It says this for a reason…

The 1.2.0 version of the library was more forgiving about this, but the rule is once again being enforced rigidly in version 1.3.0

Your code compiles fine for me when I make this change.

I’m going to ammed your earlier post, as it’s not appropriate for users to start hacking around with the libraries to remove the enforcement of these rules.

Pete.

2 Likes

I just checked by reverting the changes i did in the library and putting the defining variables at the top, It seems to have fixed it but a note to the devs (Nobody defines their variables before including their libraries)

The libraries use templates. You need the defines before the includes so the templates can pick them up.

I think the reason why the template ID and name need to be at the top of the sketch are so that they can be parsed correctly by the Blynk.Air process and this is why the library enforces this.

Either way, that’s the rule and Blynk requires it to be followed.

Pete.

1 Like

Hello pete, i already put it on the first of my sketch and it still #error “Please specify your BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME” can you help me?

Not without seeing your code, and compiler error message and knowing which Blynk library version you are using.

Don’t forget the triple backticks with your code and compiler error message.

Pete.

#define BLYNK_TEMPLATE_ID "TMPL6HUbLaRPJ"
#define BLYNK_TEMPLATE_NAME "Water Level Measurement"
#define BLYNK_AUTH_TOKEN "8_JfJQcVMIPGqcRgtHvRY3EZTkO42squ"

#define BLYNK_FIRMWARE_VERSION "1.3.2"
#define BLYNK_PRINT Serial
#include "BlynkEdgent.h"

#define echoPin 32
#define trigPin 33

long duration;
int distance; 

void ultrasonic()
{
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = duration * 0.034 / 2; //formula to calculate the distance for ultrasonic sensor
    Serial.print("Distance: ");
    Serial.println(distance);
    Blynk.virtualWrite(V0, distance);
    delay(500);
}
void setup()
{
  Serial.begin(9600);
  pinMode(34, INPUT);
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT); 
  BlynkEdgent.begin();
  delay(2000); 
}

void loop() 
{
  BlynkEdgent.run();
  ultrasonic();
}

i use Blynk Library ver 1.3.2

Clearly you didn’t take any notice of this…

or this…

Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Then delete the screenshot of your compiler error message and replace it with the text (copied and pasted) from your IDE, and place triple backticks at the beginning and end of that too.

And, if you want help with this, tell us which version of the Blynk library you are using.

Pete.

#define BLYNK_TEMPLATE_ID "TMPL6HUbLaRPJ"
#define BLYNK_TEMPLATE_NAME "Water Level Measurement"
#define BLYNK_AUTH_TOKEN "8_JfJQcVMIPGqcRgtHvRY3EZTkO42squ"

#define BLYNK_FIRMWARE_VERSION "1.3.2"
#define BLYNK_PRINT Serial
#include "BlynkEdgent.h"

#define echoPin 32
#define trigPin 33

long duration;
int distance; 

void ultrasonic()
{
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = duration * 0.034 / 2; //formula to calculate the distance for ultrasonic sensor
    Serial.print("Distance: ");
    Serial.println(distance);
    Blynk.virtualWrite(V0, distance);
    delay(500);
}
void setup()
{
  Serial.begin(9600);
  pinMode(34, INPUT);
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT); 
  BlynkEdgent.begin();
  delay(2000); 
}

void loop() 
{
  BlynkEdgent.run();
  ultrasonic();
}

Screenshot 2023-10-15 160625

extern "C" {
  void app_loop();
  void eraseMcuConfig();
  void restartMCU();
}

#include "Settings.h"
#include <BlynkSimpleEsp32_SSL.h>

#ifndef BLYNK_NEW_LIBRARY
#error "Old version of Blynk library is in use. Please replace it with the new one."
#endif

#if !defined(BLYNK_TEMPLATE_ID) || !defined(BLYNK_DEVICE_NAME)
#error "Please specify your BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME"
#endif

#include "BlynkState.h"
#include "ConfigStore.h"
#include "ResetButton.h"
#include "ConfigMode.h"
#include "Indicator.h"
#include "OTA.h"

inline
void BlynkState::set(State m) {
  if (state != m && m < MODE_MAX_VALUE) {
    DEBUG_PRINT(String(StateStr[state]) + " => " + StateStr[m]);
    state = m;

    // You can put your state handling here,
    // i.e. implement custom indication
  }
}

void printDeviceBanner()
{
  Blynk.printBanner();
  DEBUG_PRINT("--------------------------");
  DEBUG_PRINT(String("Product:  ") + BLYNK_DEVICE_NAME);
  DEBUG_PRINT(String("Hardware: ") + BOARD_HARDWARE_VERSION);
  DEBUG_PRINT(String("Firmware: ") + BLYNK_FIRMWARE_VERSION " (build " __DATE__ " " __TIME__ ")");
  if (configStore.getFlag(CONFIG_FLAG_VALID)) {
    DEBUG_PRINT(String("Token:    ...") + (configStore.cloudToken+28));
  }
  DEBUG_PRINT(String("Device:   ") + BLYNK_INFO_DEVICE + " @ " + ESP.getCpuFreqMHz() + "MHz");
  DEBUG_PRINT(String("MAC:      ") + WiFi.macAddress());
  DEBUG_PRINT(String("Flash:    ") + ESP.getFlashChipSize() / 1024 + "K");
  DEBUG_PRINT(String("ESP sdk:  ") + ESP.getSdkVersion());
  DEBUG_PRINT(String("Chip rev: ") + ESP.getChipRevision());
  DEBUG_PRINT(String("Free mem: ") + ESP.getFreeHeap());
  DEBUG_PRINT("--------------------------");
}

void runBlynkWithChecks() {
  Blynk.run();
  if (BlynkState::get() == MODE_RUNNING) {
    if (!Blynk.connected()) {
      if (WiFi.status() == WL_CONNECTED) {
        BlynkState::set(MODE_CONNECTING_CLOUD);
      } else {
        BlynkState::set(MODE_CONNECTING_NET);
      }
    }
  }
}

class Edgent {

public:
  void begin()
  {
    indicator_init();
    button_init();
    config_init();

    WiFi.persistent(false);
    WiFi.enableSTA(true);   // Needed to get MAC

    printDeviceBanner();

    if (configStore.getFlag(CONFIG_FLAG_VALID)) {
      BlynkState::set(MODE_CONNECTING_NET);
    } else if (config_load_blnkopt()) {
      DEBUG_PRINT("Firmware is preprovisioned");
      BlynkState::set(MODE_CONNECTING_NET);
    } else {
      BlynkState::set(MODE_WAIT_CONFIG);
    }
  }

  void run() {
    app_loop();
    switch (BlynkState::get()) {
    case MODE_WAIT_CONFIG:       
    case MODE_CONFIGURING:       enterConfigMode();    break;
    case MODE_CONNECTING_NET:    enterConnectNet();    break;
    case MODE_CONNECTING_CLOUD:  enterConnectCloud();  break;
    case MODE_RUNNING:           runBlynkWithChecks(); break;
    case MODE_OTA_UPGRADE:       enterOTA();           break;
    case MODE_SWITCH_TO_STA:     enterSwitchToSTA();   break;
    case MODE_RESET_CONFIG:      enterResetConfig();   break;
    default:                     enterError();         break;
    }
  }

};

Edgent BlynkEdgent;
BlynkTimer timer;

void app_loop() {
    timer.run();
}

Are you going to post your compiler error message text?

Pete.

Hi Peter
I have the same issue.
I’m using the BlynkEdgent and the 3 mentioned lines are on the top of the code.
On the first (main) page.
The error message looks like this:

In file included from C:\Users\Sandor\Documents\Arduino\KozpontiFigyeles-OTA-08_clone\KozpontiFigyeles-OTA-08_clone.ino:40:
C:\Users\Sandor\Documents\Arduino\KozpontiFigyeles-OTA-08_clone\BlynkEdgent.h:16:2: error: #error "Please specify your BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME"
   16 | #error "Please specify your BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME"
      |  ^~~~~

exit status 1

Compilation error: #error "Please specify your BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME"

Thank You

Your triple backticks need to be immediately above and below your compiler error message, not at the beginning and end of your post. You can use the pencil icon at the bottom of the post to fix this.

Please post your sketch (with triple backticks, as explained above) and tell us which version of the Blynk library you have installed.

Pete.

So instead of editing your original post and fixing the location of the triple backticks you’ve decided to post your compiler error message again!

Are you planning to provide the other information I asked for?

Pete.

Edited my previous message.
Should i include anything else?

Thank You

Pete.