Compilation error: no matching function for call to 'BlynkWifi::begin

Hi, so I tried this code to run in my esp32, but the verify always tell that i couldn’t upload it because the compilation were error.

// Virtual Pin function in my console
V1 as humidity
V2 as temperature
V3 as relay
V4 as Slider Water Amount
V5 as to start the Watering Process

Is there any methods on how make this code more readable and simple ?

Thank’s in advance.


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

// Replace with your Blynk Auth Token
char auth[] = "Your_Auth_Token_Here";

// Replace with your WiFi credentials
const char* ssid = "Your_WiFi_SSID";
const char* password = "Your_WiFi_Password";

// Pin definitions
#define DHT_PIN 4
#define RELAY_PIN 12

// Define the type of DHT sensor (DHT11 or DHT22)
#define DHT_TYPE DHT22

// Create an instance of the DHT sensor library
DHT dht(DHT_PIN, DHT_TYPE);

// Variables to store the humidity and temperature readings
float humidity, temperature;

// Watering amount (adjustable with the slider)
int wateringAmount = 0;

// Blynk virtual pin for the humidity reading
#define VIRTUAL_PIN_HUMIDITY 1

// Blynk virtual pin for the temperature reading
#define VIRTUAL_PIN_TEMPERATURE 2

//Blynk virtual pin for the relay 
#define VIRTUAL_PIN_RELAY 3

// Blynk virtual pin for the slider
#define VIRTUAL_PIN_SLIDER 4

// Blynk virtual pin for the button
#define VIRTUAL_PIN_BUTTON 5

void setup() {
  // Start the serial communication
  Serial.begin(115200);

  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");

  // Connect to Blynk
  Blynk.begin(auth, WiFi.localIP());
  Serial.println("Connected to Blynk");

  // Initialize the DHT sensor
  dht.begin();

  // Set the relay pin as an output
  pinMode(RELAY_PIN, OUTPUT);
}

void loop() {
  // Read the humidity and temperature from the DHT sensor
  humidity = dht.readHumidity();
  temperature = dht.readTemperature();

  // Check if the read was successful
  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT sensor");
    return;
  }

  // Send the humidity and temperature readings to Blynk
  Blynk.virtualWrite(VIRTUAL_PIN_HUMIDITY, humidity);
  Blynk.virtualWrite(VIRTUAL_PIN_TEMPERATURE, temperature);

  // Read the value of the slider from Blynk
  wateringAmount = Blynk.getValue(VIRTUAL_PIN_SLIDER).asInt();
  Serial.print("Watering amount: ");
  Serial.println(wateringAmount);

  // Read the value of the button from Blynk
  if (Blynk.getValue(V
.virtualRead(VIRTUAL_PIN_BUTTON)) {
// If the button is pressed, turn on the relay for the specified watering amount
Serial.println("Starting watering process");
digitalWrite(RELAY_PIN, HIGH);
delay(wateringAmount * 1000);
digitalWrite(RELAY_PIN, LOW);
Serial.println("Finished watering process");
}

Blynk.run();
}

You should read this👇🏻

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

There are so many things wrong with this sketch that it’s difficult to know where to begin.

Why don’t you use the example from the Sketch Builder?

Pete.

Hi Pete, thanks for reply.

The device that i’ve using is ESP32 Devkit DoiT v1 With Expansion Board
D4 pin connect to Data pin at DHT22
D12 pin connect to IN pin at Relay

I tried to rewrite the code and make it more compact, i guess,
which the function is to read Humidity&Temperature from DHT22 Sensor, also it can control relay to ON/OFF .

i got this error code while im trying to upload it to the board itself (straight connect to microcontroller, not in Expansion board)

fatal error occurred: Timed out waiting for packet content
Failed uploading: uploading error: exit status 2

Here’s the code


#define BLYNK_PRINT_SERIAL
#define BLYNK_TEMPLATE_ID "TMPLXgw0WMbs"
#define BLYNK_TEMPLATE_NAME "Pump Automation"

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

#define DHTPIN 4      // DHT22 data pin connected to GPIO4
#define DHTTYPE DHT22 // DHT22 sensor type

int pin = 12;

char auth[] = "";    // Blynk auth token
char ssid[] = "ESP32_HOTSPOT";     // WiFi SSID
char pass[] = "ESP323220"; // WiFi password

DHT dht(DHTPIN, DHTTYPE);

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

  dht.begin();

  pinMode(pin, OUTPUT);
  pinMode(pin, HIGH);

}

void loop()
{
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();
  
  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Blynk.virtualWrite(V1, humidity);
  Blynk.virtualWrite(V2, temperature);

  Blynk.run();
}