BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Compilation error when use Data structures, Name of virtual pin - BLYNK_WRITE

Hello, is it possible to use the virtual pin name in the BLYNK_WRITE macro from the data structure?
The code crashes, it’s easier and clearer for me than V0 …

Does not work with BLYNK_WRITE(v_pins.test) but work with BLYNK_WRITE(V0)

Error:
sketch_nov22a:20:19: error: expected initializer before ‘.’ token
BLYNK_WRITE(v_pins.test) {
^
/home/emsit/Arduino/libraries/Blynk/src/Blynk/BlynkHandlers.h:152:30: note: in definition of macro ‘BLYNK_WRITE_2’
void BlynkWidgetWrite ## pin (BlynkReq BLYNK_UNUSED &request, const BlynkParam BLYNK_UNUSED &param)
^~~
/tmp/arduino_modified_sketch_21883/sketch_nov22a.ino:20:1: note: in expansion of macro ‘BLYNK_WRITE’
BLYNK_WRITE(v_pins.test) {
^~~~~~~~~~~


#define BLYNK_TEMPLATE_ID           "TMPLxxxxxx"
#define BLYNK_DEVICE_NAME           "Device"
#define BLYNK_AUTH_TOKEN            "XXX"

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

struct BlynkVirtual {
  uint8_t test;
};
BlynkVirtual v_pins {
  V0
};

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

BLYNK_WRITE(v_pins.test) { //work with V0 ...
  int pinValue = param.asInt();
}

void setup() {
  Blynk.begin(auth, ssid, pass);
}

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

No, it’s not possible.
You should use BLYNK_WRITE_DEFAULT() instead.

Read this:

Pete.

1 Like

Thanks, I will use BLYNK_WRITE_DEFAULT () :slightly_smiling_face: