Hi im having disconnection issues with my device im running the MEGA+WiFi R3 ATmega2560 +ESP8266, it lasts about 15 minutes then disconnects I have tried so many different things with Blynk connection management and nothing seems to work long term. personally I think the device is shit but it was perfect for the project due to the amount of analogue/digital inputs. I’m also using a nodmcu esp/12e to operate one sensor and 8 buttons and it works great so Im struggling to understand what’s wrong.
This is the code im running on the Mega/wifi
// LIBRARY
//====================================================
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
//====================================================
// DEKLARASI AWAL
//====================================================
char auth[] = "";
char ssid[] = "";
char pass[] = "";
#define EspSerial Serial3
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
#define waterLevel_trigger 7 // Water level sensor
#define waterLevel_echo 6
#define hydroTrig 5 // Water level sensor
#define hydroEcho 4
#define motherTrig 3 // Water level sensor
#define motherEcho 2
#define MAX_DISTANCE 450
#define PI 3.1415926535897932384626433832795
const int Diameter1 = 36.5;
const int Depth1 = 56;
const int Area1 = 1046.21592;
int Litres1, distance1, WaterDepth1;
#include <DHT.h>
#define DHT1 9 // What digital pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht1(DHT1, DHTTYPE);
#define DHT2 8
#define DHTTYPE2 DHT11 // DHT 11
DHT dht2(DHT2, DHTTYPE2);
//==================================================================================================================
void setup()
{
Serial.begin(115200);
Serial3.begin(115200);
dht1.begin();
dht2.begin();
delay(10);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass); //Reguler server
// Blynk.begin(auth, wifi, ssid, pass, "192.168.43.120", 8080); //Local server
timer.setInterval(900L, sendWaterlevel);
timer.setInterval(800L, sendHydroLevel);
timer.setInterval(1000L, sendMotherLevel);
timer.setInterval(1050L, sendDHT1Sensor);
timer.setInterval(1010L, sendDHT2Sensor);
pinMode(waterLevel_trigger, OUTPUT);
pinMode(waterLevel_echo, INPUT);
pinMode(hydroTrig, OUTPUT);
pinMode(hydroEcho, INPUT);
pinMode(motherTrig, OUTPUT);
pinMode(motherEcho, INPUT);
// 12v Relay Board
digitalWrite(26,HIGH); // Return Valve
digitalWrite(27,HIGH); // Waste Valve
digitalWrite(28,HIGH); // Water Main
// 240v Relay Board
digitalWrite(38,HIGH); // Circulation Pump
digitalWrite(39,HIGH); // Intake Pump
digitalWrite(40,HIGH); // Intake2 Pump
digitalWrite(41,HIGH); // Return Pump
digitalWrite(53,HIGH); // Waste Pump
pinMode(10, OUTPUT);
// 12v Output Pins
pinMode(26,OUTPUT);
pinMode(27,OUTPUT);
pinMode(28,OUTPUT);
// 240v Output Pins
pinMode(38,OUTPUT);
pinMode(39,OUTPUT);
pinMode(40,OUTPUT);
pinMode(41,OUTPUT);
pinMode(42,OUTPUT);
pinMode(43,OUTPUT);
pinMode(44,OUTPUT);
pinMode(45,OUTPUT);
pinMode(46,OUTPUT);
pinMode(47,OUTPUT);
pinMode(48,OUTPUT);
pinMode(49,OUTPUT);
pinMode(50,OUTPUT);
pinMode(51,OUTPUT);
pinMode(52,OUTPUT);
pinMode(53,OUTPUT);
}
void loop(){
timer.run();
Blynk.run();
}
void sendWaterlevel()
{
long duration1, distance1;
digitalWrite(waterLevel_trigger, LOW);
delayMicroseconds(2);
digitalWrite(waterLevel_trigger, HIGH);
delayMicroseconds(10);
digitalWrite(waterLevel_trigger, LOW);
duration1 = pulseIn(waterLevel_echo, HIGH);
distance1 = (duration1/2) / 29.1;
if (distance1 >= Depth1 || distance1 == 0 ) distance1 = Depth1;
WaterDepth1 = Depth1 - distance1;
Litres1 = (Area1 * WaterDepth1) / 1000;
Blynk.virtualWrite(V1, distance1);
Blynk.virtualWrite(V2, WaterDepth1);
Blynk.virtualWrite(V3, Litres1);
Serial.println();
Serial.println("Tank 1 water distance1: " + String(distance1));;
Serial.println("Tank 1 water depth: " + String(WaterDepth1)); //print depth
Serial.println("Tank 1 Litres: " + String(Litres1)); //print litres
delay(200);
}
//==================================================================================================================
void sendHydroLevel()
{
long duration2, distance2;
digitalWrite(hydroTrig, LOW);
delayMicroseconds(2);
digitalWrite(hydroTrig, HIGH);
delayMicroseconds(10);
digitalWrite(hydroTrig, LOW);
duration2 = pulseIn(hydroEcho, HIGH);
distance2 = (duration2/2) / 29.1;
Serial.print(distance2);
Serial.println("Centimeter");
Blynk.virtualWrite(V5, distance2);
}
//==================================================================================================================
void sendMotherLevel()
{
long duration3, distance3;
digitalWrite(motherTrig, LOW);
delayMicroseconds(2);
digitalWrite(motherTrig, HIGH);
delayMicroseconds(10);
digitalWrite(motherTrig, LOW);
duration3 = pulseIn(motherEcho, HIGH);
distance3 = (duration3/2) / 29.1;
Serial.print(distance3);
Serial.println("Centimeter");
Blynk.virtualWrite(V6, distance3);
}
//==================================================================================================================
//==================================================================================================================
//==================================================================================================================
//==================================================================================================================
//=============================================================================================================
void sendDHT1Sensor()
{
float h = dht1.readHumidity();
float t = dht1.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT1 sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V9, h);
Blynk.virtualWrite(V10, t);
}
//==================================================================================================================
void sendDHT2Sensor()
{
float h = dht2.readHumidity();
float t = dht2.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT2 sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V11, h);
Blynk.virtualWrite(V12, t);
}
if you have a solution which may help me that would be great
and this is the code which is on the nodemcu
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "FMi7d2cKnlem_XUHlVJhVELHG8D36iCL";
char ssid[] = "belkin.227";
char pass[] = "4a28664f";
//PH Sensor
int sensorPin = A0; // select the analog input pin for the pH sensor
int sensorValue = 0; // variable to store the value coming from the sensor
float ad7 = 583.0; // change this value to the one on serial monitor when in pH7 buffer
float ad4 = 749.0; // change this value to the one on serial monitor when in pH4 buffer
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
digitalWrite(D1, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D3, HIGH);
digitalWrite(D4, HIGH);
digitalWrite(D5, HIGH);
digitalWrite(D6, HIGH);
digitalWrite(D7, HIGH);
digitalWrite(D8, HIGH);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(D7, OUTPUT);
pinMode(D8, OUTPUT);
}
void loop()
{
Blynk.run();
Get_pH();
}
///////////////////////////////////////////
void Get_pH()
{
int currentValue = 0;
for (int i = 0; i < 10; i++)
{
currentValue += analogRead(sensorPin);
delay(100);
}
sensorValue =(currentValue / 10);
Serial.println(sensorValue);
float m =(-3.0/(ad4-ad7));
//Serial.println(m);
float c = 7-(m*ad7);
//Serial.println(c);
float a =((m*sensorValue)+c);
Serial.print("PH = ");
Serial.println(a);
delay(500);
}
I thought I would get issues with this code because im not using the timer but it works great
but the other board seems to be absolute useless
- Search forum for similar topics
- Check http://docs.blynk.cc and http://help.blynk.cc/
- Add details :
• Hardware model + communication type. For example: Arduino UNO with Ethernet Shield
• Smartphone OS (iOS or Android) + version
• Blynk server or local server
• Blynk Library version
• Add your sketch code. Code should be formatted as example below.
Simply paste your code between ``` If you don’t format your code, your topic can be deleted by moderators.
void loop()