Name and ID Template as an char array - Is it possible?

Hello everyone.

As read from other threads and announcements, the new Blynk libraries require these two #defines to be integrated into the sketch:

#define BLYNK_TEMPLATE_ID "++++++++++++"
#define BLYNK_TEMPLATE_NAME "Name"

Okay. All clear. What I was wondering is whether there is the possibility of integrating these two instructions, as an array of chars, rather than as #define.

In fact, if I declare these two as #define, the connection occurs without problems, however if I declare them as

char BLYNK_TEMPLATE_ID [] = "++++++++++++";
char BLYNK_TEMPLATE_NAME[] = "Name";

I have no problems with errors in the code (such as the one indicating that the two constants for the name and ID of the template have not been added), but no connection occurs: I remain stuck in this “blocking” instruction Blynk.begin(); .

I ask if there is a way to add these as a char array because, in my application I would have liked to set that, at a first start and a reset of the settings, my ESP8266 board would be set in AP mode and have the possibility of insert via local web page (192.168.4.1), the ssid, password, auth token, and template name and ID data, saved in EEPROM. At a subsequent restart, with data already present, use these to start the connection with Blynk.

Here’s how you can see that in this case you need variables, and not constants.

Isn’t it possible to do this somehow? Thanks for any replies.

I don’t understand how you’re managing to avoid the #error "Please specify your BLYNK_TEMPLATE_ID and BLYNK_TEMPLATE_NAME" compiler error.

Can you post the full sketch that has this format…

Pete.

I tried this before write the final sketch.
Data entered via serial. If I compile I have no errors.

But what I would like to know, since you have to use #define for those constants, if there was a method to use them as char array type variables. Because I need to insert them when I have already started the program.

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char ssid[32] = "";
char pass[32] = "";
char auth[32] = "";
char BLYNK_TEMPLATE_ID[32] = "";
char BLYNK_TEMPLATE_NAME[32] = "";

void setup() {
  Serial.begin(115200);

  Serial.println("Insert SSID:");
  readSerial(ssid);
  Serial.println("You wrote: " + String(ssid));
  
  Serial.println("Insert password:");
  readSerial(pass);
  Serial.println("You wrote: " + String(pass));

  Serial.println("Insert auth token:");
  readSerial(auth);
  Serial.println("You wrote: " + String(auth));

  Serial.println("Insert Template ID:");
  readSerial(BLYNK_TEMPLATE_ID);
  Serial.println("You wrote: " + String(BLYNK_TEMPLATE_ID));

  Serial.println("Insert Template Name:");
  readSerial(BLYNK_TEMPLATE_NAME);
  Serial.println("You wrote: " + String(BLYNK_TEMPLATE_NAME));

  if (strlen(ssid) > 0 && strlen(pass) > 0 && strlen(auth) > 0) {
    Blynk.begin(auth, ssid, pass);
    if (Blynk.connected()) {
      Serial.println("CONNECTED!");
    } else {
      Serial.println("NO CONNECTED");
    }
  } else {
    Serial.println("ERROR! RETRY!");
  }
}

void loop() {
  Blynk.run();
}

void readSerial(char result[]) {
  int i = 0;
  while (1) {
    while (Serial.available() > 0) {
      char inChar = Serial.read();
      if (inChar == '\n' || inChar == '\r') {
        result[i] = '\0';
        Serial.flush();
        return;
      }
      result[i] = inChar;
      i++;
    }
  }
}

I’m not sure what version of the Blynk library you’re using, but your sketch diesnt compoile inder the latest version (1.3.2)…

C:\Users\Pete Knight\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkApi.h:39:6: error: #error "Please specify your BLYNK_TEMPLATE_ID and BLYNK_TEMPLATE_NAME"
   39 |     #error "Please specify your BLYNK_TEMPLATE_ID and BLYNK_TEMPLATE_NAME"
      |      ^~~~~
Using library ESP8266WiFi at version 1.0 in folder: C:\Users\Pete Knight\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266WiFi 
Using library Blynk at version 1.3.2 in folder: C:\Users\Pete Knight\Documents\Arduino\libraries\Blynk 
exit status 1
Error compiling for board LOLIN(WEMOS) D1 R2 & mini.

Pete.

Yes, it’s correct, I updated it and it gives me an error during compilation.
But the discussion is not about this. I was referring to whether perhaps there was the possibility of somehow being able to insert this data as a char array to allow it to be inserted during run.

But I assume that with the new libraries this cannot be done.

The new library is looking for a #define for these two identifiers. Without those the code won’t compile.

Pete.

Yes, it’s clear. Too bad the library provides them as #defines and therefore as constants. And you can’t put them as character arrays.

Thanks the same.