ESP8266 won't connect to new Blynk app

So the code I’m using is as below.

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


#define BLYNK_TEMPLATE_ID "TMPL6NTDwdNKR"
#define BLYNK_TEMPLATE_NAME "Test"
#define BLYNK_AUTH_TOKEN "zv6xqv9T48p_CZRugqKPPrgL88bI7SiQ"

char ssid[] = "PLDTHOMEFIBR5G679a8"; // WiFi SSID
char pass[] = "PLDTWIFItcwy5"; // WiFi password

BlynkTimer timer; // Creating a timer object


void myTimerEvent() // This loop defines what happens when timer is triggered
{
Blynk.virtualWrite(A0, millis() / 1000);
}



void setup() {
  Serial.begin(9600); // initialize serial communication at 9600 bits per second
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "https://sgp1.blynk.cloud.com"); // connect to Blynk server
  timer.setInterval(1000L, myTimerEvent); //Staring a timer
}

void loop() {
  if (Serial.available() > 0) { // check if there is any data available from Arduino
    String sensorData = Serial.readStringUntil('\n'); // read the data until newline character
    sensorData.trim(); // remove any whitespace characters
    int sensorValue = sensorData.toInt(); // convert the data to integer
    Blynk.virtualWrite(A0, sensorValue); // send the value to Blynk app
    
  if (Blynk.connected()) {
    Serial.println("NodeMCU is connected to Blynk app.");
  } else {
    Serial.println("NodeMCU is not connected to Blynk app.");
  }
  }
  Blynk.run(); // run Blynk app
  timer.run();

  
}

I’m trying to get my ESP8266 to connect to the Blynk app but no matter what I do it just won’t connect. I’m trying to get the moisture sensor data to go to the app but the microcontroller just will not connect to the Blynk app.

The ESP8266 definitely can connect to the Wifi as I’ve already performed the Wifi scan and it definitely works. But when I run this code, my device on the dashboard remains as “offline.”

I need help. THanks

Please read this:
https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

This is not the url for a Blynk IoT server.

Why are you using this in the Blynk.begin() command? why aren’t you simply using Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

Pete.

I was just trying a bunch of stuff and thought that it might work but it didn’t. But I already got it working. The issue now is that on the app instead of displaying values that should extend from 500 to 1000. The app just shows a value of one.

This is the new code btw:


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

#define BLYNK_TEMPLATE_ID "TMPL6NTDwdNKR"
#define BLYNK_TEMPLATE_NAME "Test"
#define BLYNK_AUTH_TOKEN "syysCAdzqT24ruX4lMJxzVZvbdi86at2"

char ssid[] = "PLDTHOMEFIBR679a8";  // WiFi SSID
char pass[] = "PLDTWIFItcwy5";      // WiFi password

BlynkTimer timer;  // Creating a timer object
SoftwareSerial ardSerial(D9, D10);

void myTimerEvent()  // This loop defines what happens when timer is triggered
{
  Blynk.virtualWrite(V1, millis() / 1000);
}



void setup() {
  Serial.begin(9600);  // initialize serial communication at 9600 bits per second
  WiFi.begin(ssid, pass);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);  // connect to Blynk server
  timer.setInterval(1000L, myTimerEvent);     //Staring a timer
}

void loop() {
  if (Serial.available() > 0) {  // check if there is any data available from Arduino
    Serial.println(ardSerial.read());
    int sensorValue = ardSerial.read();   // convert the data to integer
    Blynk.virtualWrite(V1, sensorValue);  // send the value to Blynk app
  }
  if (Blynk.connected()) {
    Serial.println("NodeMCU is connected to Blynk app.");
  } else {
    Serial.println("NodeMCU is not connected to Blynk app.");
  }

  Blynk.run();  // run Blynk app
  timer.run();
}

And this is what shows up on the app

Its not on right now but it only displays a “1” everytime i turn it on but I need to show in between those values.

Is it an issue about the virtual pin? Is it the code?

Triple.

It might be the min/max values that you’ve defined for the datastream.
Have you tried serial printing the sensorValue before it’s sent to Blynk?

Pete.

I think this is what you mean by serial printing the sensor value. Yes the values I want do show up on the serial monitor so I’m pretty sure I did do that.

It shows up on the serial monitor but not on the Blynk app itself.

And I have already defined the min/max values on the data stream as I show on the picture above. It says from 0 to 1032 but when I activate the system it still just displays 1.

No, this…

is not the same as this…

Serial.println(sensorValue);

which is why I said…

Once you’ve made this change please copy/paste the text from your serial monitor, from the point when your device boots. Use triple backticks at the beginning and end of the text when you post it, like you did with your sketch.

Pete.