Add details :
• Hardware model + communication type. For example: ESP32
• Smartphone OS (iOS or Android) + OS version
• Blynk server region
• Blynk Library version
• Post your FORMATTED sketch code. Remove your AUTH TOKEN from code. Don’t post screenshots
• Post your serial monitor output when experiencing some issues
If you don’t format your code, your topic can be deleted by moderators.
Here is a correct example of code formatting:
#include <Wire.h>
#include <U8g2lib.h>
#include <Adafruit_HDC1000.h>
#include <Adafruit_Sensor.h>
#define BLYNK_TEMPLATE_ID "TMPL6nbINoFLa"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "VLzoDUg8OgnDUuK6se_YmTFxkOiVh3mF"
#include <ESP8266_Lib.h>
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = "VLzoDUg8OgnDUuK6se_YmTFxkOiVh3mF";
char server[] = "blynk-cloud.com";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "PLDTHOMEFIBR2b770";
char pass[] = "17sRjamielg1701_";
int port = 8080;
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
Adafruit_HDC1000 hdc1080;
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
BlynkTimer timer;
float temperature;
float humidity;
const int AirValue = 895; // Replace with your values
const int WaterValue = 370; // Replace with your values
int soilMoistureValue = 0;
int soilmoisturepercentage = 0;
const int soilmoisturePin = A0;
bool isEspConnected = false;
void connectToWiFi()
{
// Configure Blynk with Auth Token
Blynk.config(wifi, auth, "blynk-cloud.com", 80);
// Set up WiFi connection
Blynk.connectWiFi(ssid, pass);
// Check connection status
if (Blynk.connected())
{
isEspConnected = true;
Serial.println("Connected to Blynk server.");
}
else
{
isEspConnected = false;
Serial.println("Connection to Blynk server failed.");
}
}
void checkEspConnection()
{
// Check if the ESP-01S is connected to the internet
if (Blynk.connected())
{
isEspConnected = true;
Serial.println("ESP connected to Blynk server.");
}
else
{
isEspConnected = false;
Serial.println("ESP not connected to Blynk server.");
}
}
void readHDC1080()
{
temperature = hdc1080.readTemperature();
humidity = hdc1080.readHumidity();
soilMoistureValue = analogRead(soilmoisturePin);
soilmoisturepercentage = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
if (isEspConnected)
{
Blynk.virtualWrite(V1, temperature);
Blynk.virtualWrite(V2, humidity);
Blynk.virtualWrite(V3, soilmoisturepercentage);
}
}
void displayData()
{
u8g2.clearBuffer();
u8g2.setBitmapMode(1);
u8g2.setFontMode(1);
u8g2.setFont(u8g2_font_6x10_tr);
u8g2.setCursor(3, 28);
u8g2.print("T: ");
u8g2.print(temperature);
u8g2.print("°C");
u8g2.setCursor(69, 28);
u8g2.print("H: ");
u8g2.print(humidity);
u8g2.print("%");
u8g2.setCursor(3, 50);
u8g2.print("S: ");
u8g2.print(soilmoisturepercentage);
u8g2.print("%");
u8g2.sendBuffer();
delay(500);
}
void setup()
{
Serial.begin(115200);
Wire.begin();
pinMode(soilmoisturePin, INPUT);
// Initialize the HDC1080 sensor
hdc1080.begin();
// Initialize the OLED display
u8g2.begin();
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
// Connect to WiFi and Blynk
connectToWiFi();
// You can also specify the server:
// Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass, "blynk.cloud", 80);
timer.setInterval(1000L, readHDC1080);
}
void loop()
{
// Process incoming commands and maintain Blynk connection
Blynk.run();
if (isEspConnected)
{
readHDC1080();
displayData();
timer.run();
}
else
{
readHDC1080();
displayData();
}
}
can you help me fix it i am using arduino mega and ESP-01s and i cant use <ESP8266Wifi.h>. is there any way so that i can use blynk.begin and still run my code even if there is no wifi connection?