Get data from Virtual Pin 1 not working

dear all , i am trying to get data from my datastreams V6 . it is an int. with
BLYNK_WRITE(V6)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
Serial.print("V6 Slider value is: ");
Serial.println(pinValue);
}

however it doesn’t to run ever . I had my full code belwo : can anyone give me some suggetion ?


/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID           "********"
#define BLYNK_TEMPLATE_NAME         "****"
#define BLYNK_AUTH_TOKEN            "****"

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin 1
BLYNK_WRITE(V6)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("V6 Slider value is: ");
  Serial.println(pinValue);
}

void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  
}

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

@tommynewman 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.

Pete.

thank you and i had edit it .

Your topic title, and these comments…

refer to pin 1, whilst your description of the problem…

and your code…

Refer to pin 6.

I suspect that you may have set your virtual datastream and slider widget up incorrectly, so it would help if you posted screenshots of both.

Pete.

sorry for my tuping mistook regarding V1 and V6 .
i had added
Blynk.syncVirtual(V1); after Blynk.run(); in the main loop ().
i am able to read from V1 . It is a good way to do so?

No, it is not.
The only time you should run Blynk.syncVirtual(vPin) is in the BLYNK_CONNECTED() callback function.

If you put it on the void loop then you’ll flood the Blynk server, so you MUST stop doing this.

Pete.

Thank you for your reply !
can you please show me where shall i put in the BLYNK_CONNECTED()
as i don’t have this function in my program!

It’s just a function, so can go anywhere in your sketch, provided it’s not inside another function.

But, its only purpose is to run code once when Blynk first connects or re-connects. I would suggest you read the documentation to understand the correct use of BLYNK_CONNECTED() and Blynk.syncVirtual(vPin before using them in your code.

Pete.

like this ?
BLYNK_CONNECTED()
{

  Blynk.syncVirtual(V6);    /

}

Yes, except 7 hours ago it was pin V1 that you were trying to synchronise, not pin V6.

Pete.

Thank you !