Function-definition is not allowed here before '{' token while coding nrf24l01

Hi, i doing coding with nrf24l01 and i got issue where a function-definition is not allowed here before ‘{’ token at
BLYNK_WRITE(V1) {
and
BLYNK_WRITE(V2) {
can anyone help me to find the problem? im already looking for clue in provious topic but it didnt help

here’s my code to be exact



#define BLYNK_PRINT Serial//code_receiverv4_nrf24L01 | Arduino IDE 2.3.2
#define BLYNK_TEMPLATE_ID "TMPL65QkzPU9S"
#define BLYNK_TEMPLATE_NAME "WSN lamp"
#define BLYNK_AUTH_TOKEN  "27CEcwlLSJ_02flZjsWpkBr1NiFhUV-D"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "realme X";
char pass[] = "jeruk123";

//#define CE_PIN   8
//#define CSN_PIN  7

const byte addresses [][6] = {"00001", "00002"}; // Define the transmit pipe

typedef struct 
{
  //int DevID;
  // float DevVal;
  // int DevSig;
  float Voltage; //ta
  float Value; //ta
} SensorData;

SensorData sensorNode;

RF24 radio(D0, D8); // Create a Radio

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  delay(1000);
  Serial.println("Nrf24L01 Receiver Starting");
  radio.begin();
  radio.openWritingPipe(addresses[1]);     //Setting the address at which we will send the data
  radio.openReadingPipe(1, addresses[0]);  //Setting the address at which we will receive the data
}

void loop()
{
  if (radio.available())
  { 
    BLYNK_WRITE(V1) {
      LED = param.asInt();
      radio.write(&LED, sizeof(LED));
    }
    BLYNK_WRITE(V2) {
      Auto = param.asInt();
      radio.write(&Auto, sizeof(Auto));
    }
    radio.read(&sensorNode, sizeof(sensorNode));
    Blynk.virtualWrite(V0, "sensorNode.Value");
    Serial.print(", Value=");
    Serial.print(sensorNode.Value);
    Serial.print(", Voltage=");
    Serial.println(sensorNode.Voltage);
    // Serial.print("Received: DevID=");
    // Serial.print(sensorNode.DevID);
    // Serial.print(", DevVal=");
    // Serial.print(sensorNode.DevVal);
    // Serial.print(", DevSig=");
    // Serial.print(sensorNode.DevSig);
  }
  else
  {
    // If no data available, you might want to add a delay or other logic
    // to prevent busy-waiting, depending on your application requirements.
    delay(100); // Example delay to prevent excessive looping
  }
}

BLYNK_WRITE() is a function.
C++ does not allow a function to sit inside another function. You have yours inside the void loop() function.

Also, you shouldn’t have Blynk.virtualWrite() inside the void loop() and you shouldn’t use blocking delay() commands with Blynk.

Pete.

i see, so the BLYNK_WRITE() should be outside of void loop

Correct.

Pete.