Cannot find Auth token

Hello,

I am having a hard time with my data publishing to the Blynk server. I noticed that the code I am using is asking for a 'Blynk AUTH token". However, I cannot find a Blynk token anywhere on the Web or Mobile platforms. Ultimately, the goal is to have the NodeMCU ESP-8266 send a push notification to the mobile Blynk app when the water sensor detects any amount of water. Below is the code I am using. Please advise. Thanks in advance!

P.S. removing ssid and pass for security purposes. The water sensor is this one:https://www.amazon.com/gp/product/B08C7L7GBK/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1

#define BLYNK_TEMPLATE_ID "TMPLrQFu49qC"
#define BLYNK_DEVICE_NAME "Water Sensor 2"
#define BLYNK_AUTH_TOKEN ""
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// Authorization token from the Blynk App.
char auth[] = " ";

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



const int sensorPin= A0; //sensor pin connected to analog pin A0
float liquid_level;
int liquid_percentage;
int top_level = 500;//Maximum water level
int bottom_level = 0;//Minimum water level


void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(sensorPin, INPUT);
  Blynk.virtualWrite(V0, liquid_level);
  Blynk.virtualWrite(V1, liquid_percentage);//This will show the percentage of water in the container in a virtual pin V1
  Blynk.run();
}


void loop() {
  liquid_level = analogRead(sensorPin);
  liquid_percentage = ((liquid_level-bottom_level)/top_level)*100;//Percentage of water in the container 
  Serial.println(liquid_level);//This will print the liquid level in the monitor 
  Serial.println(liquid_percentage);//This will print the percentage of liquid in the monitor
  Blynk.virtualWrite(V0, liquid_level);
  Blynk.virtualWrite(V1, liquid_percentage);
  delay(100);
  Blynk.run();
}

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

@PeteKnight Just finished editing.

Thanks

Jay

Https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

I assume that you’ve created a template in the web console, but you’ve not created a device from that template.

Go to the spyglass icon at the top left of the web console and click the “+ New Device” button.
Choose “From Template” and select the template you’ve created and fill-in the other info. When you’ve created the device you will then be able to click on the Device Info tab and you’ll see the Firmware Configuration information. These three lines of code should be copied and pasted into the top of your sketch, to replace the incomplete lines of code that were there previously.

However, your sketch has some serious issues….

These three lines of code don’t belong in your void setup, and won’t produce the result you are probably expecting.

Also, your void loop is a mess, and if you read the link that @Madhukesh provided you’ll realise why, and that you need to move most of this code into a separate function and call that with a BlynkTimer.

Pete.

Pete,

Thanks a lot for the direction.
This is what I came up with below.
I am receiving push notifications from the Blynk app, but they are not getting sent out exactly when water comes in contact with the sensor. Any thoughts?

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID           "TMPLrQFu49qC"
#define BLYNK_DEVICE_NAME           "Water Sensor"
#define BLYNK_AUTH_TOKEN            "B1tP4QMt1uPJcIG1_HtshYkrt5Wq-Ns5"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Versace_24";
char pass[] = "Evoxjay!29";


const int sensorPin= A0; //sensor pin connected to analog pin A0
float liquid_level;
int liquid_percentage;
int top_level = 500;//Maximum water level
int bottom_level = 0;//Minimum water 

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, analogRead(A0) );
  Blynk.virtualWrite(V0, liquid_level);
  Blynk.virtualWrite(V1, liquid_percentage);//This will show the percentage of water in the container in a virtual pin V1
}

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

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

Thanks.

Jay

Do you really mean push notifications?
You have no push notification code in your sketch. Are you using Automations, or just teg wrong terminology?

This implies that there is some sort of delay, but you’ve not qualified this in any way. Are we talking milliseconds, seconds, minutes or hours?

Pete.

I am using Automations.
Is that the right thing to do for my scenario?

Ideally, when I dip the water sensor into a cup of water, it will send a push notification notifying me of a water leak. At the moment, it is sending notifications every minute, even when water isn’t detected.

Thanks,

Jay.

It’s not the approach I’d take.
You’d probably be better doing the notification in your sketch.

You also need to use a flag variable to ensure that only one notification is sent for each detection event. You should probably read this for more info…

Pete.

Pete,

Thank you for the reference.
After reading, I see the code below and attempted to add it to my sketch, and received an error for the “if(reading”. Do you have any advice on how I can adjust this sketch for the water sensor?

Thanks,

Jay

You have not defined reading anywhere in your code. That is why you are getting this error.

You can’t add any snippet code just like that. You will have defined all the variables first.

You need to post your full sketch.

Pete.

Sorry about not posting the full code. I have decided to move on from the notifications as I cannot seem to figure out the necessary code. I am now attempting to use local indicators… red, green, and yellow LEDs that will light up depending on the amount of water that is detected by the water sensor. Below is the code I am using. Any thoughts?

Thanks,

Jay

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID           "TMPLrQFu49qC"
#define BLYNK_DEVICE_NAME           "Water Sensor"
#define BLYNK_AUTH_TOKEN            "B1tP4QMt1uPJcIG1_HtshYkrt5Wq-Ns5"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = BLYNK_AUTH_TOKEN;

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


const int sensorPin= A0; //sensor pin connected to analog pin A0
float liquid_level;
int liquid_percentage;
int top_level = 500;//Maximum water level
int bottom_level = 0;//Minimum water     
  if(A0> 400 )  
   {   
    digitalWrite(14,HIGH);   // Red led ON   
   }   
  else   
   {   
   digitalWrite(14,LOW);    // Red led OFF  
   }   
  if(A0>540 )   
   {   
   digitalWrite(12,HIGH);   // Green led ON   
   }  
   else   
   {   
   digitalWrite(12,LOW);   // Green led OFF   
   }   
   if(A0>580 )   
   {  
   digitalWrite(13,HIGH);  // Yellow led ON   
   }  
   else  
   {  
   digitalWrite(13,LOW);  // Yellow led OFF   
   }  
  }  
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, analogRead(A0) );
  Blynk.virtualWrite(V0, liquid_level);
  Blynk.virtualWrite(V1, liquid_percentage);//This will show the percentage of water in the container in a virtual pin V1


void setup()
{
  // Debug console
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

You should do some basic learning about C++ code structure. YouTube maybe?

This code…

Needs to be inside a function, called with a BlynkTimer.

Pete.