The code was working fine but I don’t know why it is sending multiple pings without completing the connection
The Blynk cloud is now switching between online and offline every time it sends a ping
Looks like your device is disconnecting then reconnecting.
What does your void loop look like?
Pete.
void loop()
{
clockDisplay();
SoilMoisture();
Wlevel();
Soilph();
if (millis() - time1 >= 10000)
{
time1 = millis();
Soilph();
}
else if (millis() - time2 >= 1000)
{
time2 = millis();
SoilMoisture();
}
else if (millis() - time3 >= 200)
{
time3 = millis();
Wlevel();
}
else if (millis() - time4 >= 10)
{
time4 = millis();
clockDisplay();
}
}
You should read this
https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean
It was very helpful
I cleaned the loop()
and it solved the problem but it recurs when I add this
void Soilph()
{
Blynk.virtualWrite(V2, soil1);
Blynk.virtualWrite(V1, "7 is Neutral Soil ,6.5-0 is Acidic Soil ,7.5-14 is Alkaine Soil");
}
Full sketch needed.
Pete.
I’ve made thousands of attempts
It turns out that the code works fine when I put it alone, but the problem starts when you put all the loops together in one code.
I am wondering if there is a specific number of episodes allowed or something
Post your full sketch, else we can’t help you
#define BLYNK_TEMPLATE_ID "*****"
#define BLYNK_DEVICE_NAME "*****"
#define BLYNK_AUTH_TOKEN "*****"
#define BLYNK_PRINT Serial
#define ESP8266_BAUD 9600
#define RE 8
#define DE 7
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <SoftwareSerial.h>
char auth[] = "*****";
char ssid[] = "*****";
char pass[] = "*****";
const int trigPin = 12;
const int echoPin = 13;
const int RELAY_PIN = A5;
long cm;
long duration;
int sensorPin = A0;
int soilMoistureValue = 0;
int percentage = 0;
const byte ph[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
byte values[11];
SoftwareSerial mod(2,3); // R0,D1
SoftwareSerial EspSerial(10, 11); // RX, TX
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
WidgetRTC rtc;
void Soilph()
{
byte val;
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
if (mod.write(ph, sizeof(ph)) == 8)
{
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
for (byte i = 0; i < 11; i++)
{
values[i] = mod.read();
}
Serial.println();
}
float soil_ph = float(values[4]) / 10;
Serial.print("Soil Ph: ");
Serial.println(soil_ph, 1);
Blynk.virtualWrite(V2, soil_ph);
Blynk.virtualWrite(V1, "7 is Neutral Soil ,6.5-0 is Acidic Soil ,7.5-14 is Alkaine Soil");
}
void Wlevel()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(4);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin,HIGH);
cm = duration / 29 / 2;
if (cm == 10)
{
Blynk.logEvent("tank");
Serial.println("Tank is empty so pump is off");
digitalWrite(A5,LOW);
}
Blynk.virtualWrite(V3, cm);
Serial.print ("Water Level: ");
Serial.print(cm);
}
BLYNK_WRITE(V0)
{
if(param.asInt()==1){
digitalWrite(RELAY_PIN, HIGH);
}
else{
digitalWrite(RELAY_PIN, LOW);
}
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V0);
}
void SoilMoisture()
{
soilMoistureValue = analogRead(sensorPin);
percentage = map(soilMoistureValue, 490, 1023, 100, 0);
if(percentage <= 60 )
{
Blynk.logEvent("on");
digitalWrite(RELAY_PIN,HIGH);
}
else if (percentage >= 61 && percentage <= 79 )
{
Serial.println("pump Unoutomatic");
}
else if (percentage >= 80 < 490 )
{
Blynk.logEvent("off");
Serial.println("pump off");
digitalWrite(A5,LOW);
}
else {
Serial.println("pump Unoutomatic");
}
}
void Clockdispla()
{
// You can call hour(), minute(), ... at any time
// Please see Time library examples for details
String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + "/" + month() + "/" + year();
Serial.print ("Current time: ");
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();
Blynk.virtualWrite(V4, currentTime);
Blynk.virtualWrite(V5, currentDate);
Blynk.logEvent("remind");
}
void setup() {
Serial.begin(9600);
mod.begin(4800);
EspSerial.begin(ESP8266_BAUD);
Blynk.begin(auth, wifi, ssid, pass);
rtc.begin();
setSyncInterval(10 * 60);
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
pinMode(RELAY_PIN, OUTPUT);
// Waterlevel
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
timer.setInterval(20000L, Soilph);
timer.setInterval(10L, Wlevel);
timer.setInterval(10000L, Clockdispla);
timer.setInterval(1000L, SoilMoisture);
}
void loop()
{
Blynk.run();
timer.run();
}
You are calling the wlevel() function 100 times per second, increase the time to 1000L for example.
also, I’d suggest using a flags to limit event logging, otherwise you will exceed the daily limit quickly ( the daily limit is 100 events per device per day ).
This test for the water level isn’t very sensible. It requires the water level to be EXACTLY 10cm, not 10.00001 or 9.9999999 but EXACTLY 10.
In reality you could easily miss taking a reading which returns exactly 10, so it’s better to make this <=10
As @John93 said, you also need to include a flag variable which sends just one event/alert for each low water level situation, and to reset this flag when the water level is significantly greater than 10 (so that you don’t get false resets of the water level status when the readings are fluctuating around the 10cm level).
More info here…
Also, this…
Is the legacy way of getting the time from the Blynk server. You should read the official documentation on the correct IoT method.
Pete.
Where can I read it ?
Click the “Docs” link at the top of this page, and type “RTC” into the search box.
Pete.
I corrected everything and the problem is still the same I don’t know why this is happening to me
#define BLYNK_TEMPLATE_ID "***"
#define BLYNK_DEVICE_NAME "***"
#define BLYNK_AUTH_TOKEN "***"
#define BLYNK_PRINT Serial
#define ESP8266_BAUD 9600
#define RE 8
#define DE 7
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <SoftwareSerial.h>
char auth[] = "***";
char ssid[] = "***";
char pass[] = "***";
const int trigPin = 12;
const int echoPin = 13;
const int RELAY_PIN = A5;
long cm;
long duration;
int sensorPin = A0;
int soilMoistureValue = 0;
int percentage = 0;
const byte ph[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
byte values[11];
SoftwareSerial mod(2,3); // R0,D1
SoftwareSerial EspSerial(10, 11); // RX, TX
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
BLYNK_WRITE(V0)
{
if(param.asInt()==1){
digitalWrite(RELAY_PIN, HIGH);
}
else{
digitalWrite(RELAY_PIN, LOW);
}
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V0);
}
void Soilph()
{
byte val;
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
if (mod.write(ph, sizeof(ph)) == 8)
{
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
for (byte i = 0; i < 11; i++)
{
values[i] = mod.read();
}
Serial.println();
}
float soil_ph = float(values[4]) / 10;
Serial.print("Soil Ph: ");
Serial.println(soil_ph, 1);
Blynk.virtualWrite(V2, soil_ph);
Blynk.virtualWrite(V1, "7 is Neutral Soil ,6.5-0 is Acidic Soil ,7.5-14 is Alkaine Soil");
}
void Wlevel()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(4);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin,HIGH);
cm = duration / 29 / 2;
if (cm >= 10)
{
Blynk.logEvent("tank");
Serial.println("Tank is empty so pump is off");
digitalWrite(A5,LOW);
}
Blynk.virtualWrite(V3, cm);
Serial.print ("Water Level: ");
Serial.print(cm);
}
void SoilMoisture()
{
soilMoistureValue = analogRead(sensorPin);
percentage = map(soilMoistureValue, 490, 1023, 100, 0);
if(percentage <= 60 )
{
Blynk.logEvent("on");
digitalWrite(RELAY_PIN,HIGH);
}
else if (percentage >= 61 && percentage <= 79 )
{
Serial.println("pump Unoutomatic");
}
else if (percentage >= 80 < 490 )
{
Blynk.logEvent("off");
Serial.println("pump off");
digitalWrite(A5,LOW);
}
else {
Serial.println("pump Unoutomatic");
}
}
void Clockdispla()
{
// You can call hour(), minute(), ... at any time
// Please see Time library examples for details
String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + "/" + month() + "/" + year();
Serial.print ("Current time: ");
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();
Blynk.virtualWrite(V4, currentTime);
Blynk.virtualWrite(V5, currentDate);
Blynk.logEvent("remind");
}
void setup() {
Serial.begin(9600);
mod.begin(4800);
EspSerial.begin(ESP8266_BAUD);
Blynk.begin(auth, wifi, ssid, pass);
Blynk.sendInternal("rtc", "sync");
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
pinMode(RELAY_PIN, OUTPUT);
// Waterlevel
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
timer.setInterval(20000L, Soilph);
timer.setInterval(1000L, Wlevel);
timer.setInterval(10000L, Clockdispla);
timer.setInterval(1000L, SoilMoisture);
}
void loop()
{
Blynk.run();
timer.run();
}
In that case, think you’ve posted the wrong version of your sketch.
Pete.
Of course it is not
I read the article about RTC but I still don’t understand
In which loop should I put
Blynk.sendInternal("rtc", "sync");
And do I need to include any libraries?
Even though you weren’t talking to me but I have the same problem
I’m so upset
I need to fix it today or tomorrow
It’s been a while since I’ve been trying to fix this problem
I hope you can help me
#define BLYNK_TEMPLATE_ID "***"
#define BLYNK_DEVICE_NAME "***"
#define BLYNK_AUTH_TOKEN "***"
#define BLYNK_PRINT Serial
#define ESP8266_BAUD 9600
#define RE 8
#define DE 7
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <SoftwareSerial.h>
char auth[] = "***";
char ssid[] = "***";
char pass[] = "***";
const int trigPin = 12;
const int echoPin = 13;
const int RELAY_PIN = A5;
long cm;
long duration;
int sensorPin = A0;
int soilMoistureValue = 0;
int percentage = 0;
const byte ph[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
byte values[11];
SoftwareSerial mod(2,3); // R0,D1
SoftwareSerial EspSerial(10, 11); // RX, TX
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
BLYNK_WRITE(V0)
{
if(param.asInt()==1){
digitalWrite(RELAY_PIN, HIGH);
}
else{
digitalWrite(RELAY_PIN, LOW);
}
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V0);
}
void Soilph()
{
byte val;
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
if (mod.write(ph, sizeof(ph)) == 8)
{
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
for (byte i = 0; i < 11; i++)
{
values[i] = mod.read();
}
Serial.println();
}
float soil_ph = float(values[4]) / 10;
Serial.print("Soil Ph: ");
Serial.println(soil_ph, 1);
Blynk.virtualWrite(V2, soil_ph);
Blynk.virtualWrite(V1, "7 is Neutral Soil ,6.5-0 is Acidic Soil ,7.5-14 is Alkaine Soil");
}
void Wlevel()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(4);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin,HIGH);
cm = duration / 29 / 2;
if (cm >= 10)
{
Blynk.logEvent("tank");
Serial.println("Tank is empty so pump is off");
digitalWrite(A5,LOW);
}
Blynk.virtualWrite(V3, cm);
Serial.print ("Water Level: ");
Serial.print(cm);
}
void SoilMoisture()
{
soilMoistureValue = analogRead(sensorPin);
percentage = map(soilMoistureValue, 490, 1023, 100, 0);
if(percentage <= 60 )
{
Blynk.logEvent("on");
digitalWrite(RELAY_PIN,HIGH);
}
else if (percentage >= 61 && percentage <= 79 )
{
Serial.println("pump Unoutomatic");
}
else if (percentage >= 80 < 490 )
{
Blynk.logEvent("off");
Serial.println("pump off");
digitalWrite(A5,LOW);
}
else {
Serial.println("pump Unoutomatic");
}
}
void Clockdispla()
{
// You can call hour(), minute(), ... at any time
// Please see Time library examples for details
String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + "/" + month() + "/" + year();
Serial.print ("Current time: ");
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();
Blynk.virtualWrite(V4, currentTime);
Blynk.virtualWrite(V5, currentDate);
Blynk.logEvent("remind");
}
void setup() {
Serial.begin(9600);
mod.begin(4800);
EspSerial.begin(ESP8266_BAUD);
Blynk.begin(auth, wifi, ssid, pass);
Blynk.sendInternal("rtc", "sync");
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
pinMode(RELAY_PIN, OUTPUT);
// Waterlevel
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
timer.setInterval(20000L, Soilph);
timer.setInterval(1000L, Wlevel);
timer.setInterval(10000L, Clockdispla);
timer.setInterval(1000L, SoilMoisture);
}
void loop()
{
Blynk.run();
timer.run();
}
@shmukh I’ve moved your latest post into this topic. Please don’t spam the forum by posting the same thing in multiple places, especially when the topic is about a Legacy issue not a Blynk IoT issue.
You’d be far better spending your time re-reading what has already been posted in this topic, as you haven’t taken on board most of the guidance that you’ve been given.
You’re not likely to get any further assistance until you’ve done that.
Pete.
Thank you
But I’m looking for related topics
I also took all instructions into consideration
If there is an error, please guide me
Thanks for everything