Hello,
i am using esp32_devkitc_v4, blynk library 1.1.0, plus version of blynk. arduino ide doit esp32 devkit v1.
im having a disconnection issues. also, on serial monitor it says heartbeat timeout
i think my problem may be related to timers.
in this project i have some i2c devices like ads1115, mcp23017(digital mux). right now, i have 20 sensor data that needs to be updated constantly.
they are not that time critical i dont need them to be updated instantly. moreover, i have 6 relays that are turned on/off by BLYNK_WRITE.
think like in the future i may want to update 60-65 data and some of them might be time critical.
as you can see below i am trying to measure the execution time with some serial prints. i know that this method is not so accurate, but i think it gives some idea about the functionality.
executes around 500-600ms
void send()
{
Serial.println("sendstart");
Blynk.virtualWrite(V4, sensor);
Blynk.virtualWrite(V5, sensor1);
Blynk.virtualWrite(V6, sensor2);
Blynk.virtualWrite(V7, sensor3);
Blynk.virtualWrite(V8, sensor4);
Blynk.virtualWrite(V9, sensor5);
Blynk.virtualWrite(V10, sensor6);
Blynk.virtualWrite(V11, sensor7);
Serial.println("sendend");
}
i also tested my sensor read function with the same way.
i discovered that math operations, some calculations, reading from i2c, sending some data to another serial port is very easy task for the mcu. i mean executes almost instantly or 60-100ms max.
void read()
{
Serial.println("readstart");
math operations;
calculations;
analogreads;
read from i2c;
serial2.print;
Serial.println("readend");
}
things that i tried:
i put some blynk.run() outside the loop
i used more timers.
i used less timers(by combining virtualwrites).
using different timer staggering method
timer.setInterval(101L, xxx);
timer.setInterval(4571L, ttt);
timer.setInterval(2453L, yyy);
timer.setInterval(3013L, aaa);
timer.setInterval(986L, bbbbb);
timer.setInterval(6039L, cccc);
i realized my arduino ide esp32 board version was 1.0.6 updated to 2.0.12 nothing changed. which version should i use? which version do you use?
which firmware(by espressif .sdk .at) should i use?
here is the general idea of my code:
as you can see im doing very basic stuff just reading and sending
void feedback() ///i dont think feedback function creates much problem because it is only updated when its changed.
{
feedback_all = mcp.readGPIO(1);
fdback = bitRead(feedback_all, 0);
if (fdback != fdback_old) {
if(fdback == 1){
Blynk.virtualWrite(V14,1);
}
else{
Blynk.virtualWrite(V14,0);
}
fdback_old = fdback;
}
////// more feedback max 8-16
}
void read_write() //read_write reads the data. as i explained reading data is very fast therefore, i am also using some of blynkwrites in there.
{
a_0 = ads0.readADC_SingleEnded(3); //ads1115
a_1 = ads0.readADC_SingleEnded(2);
a_2 = ads0.readADC_SingleEnded(1);
a_3 = ads0.readADC_SingleEnded(0);
a_4 = ads1.readADC_SingleEnded(3);
a_5 = ads1.readADC_SingleEnded(2);
a_6 = ads1.readADC_SingleEnded(1);
a_7 = ads1.readADC_SingleEnded(0);
s_0 = a_0;
s_1 = a_1;
s_2 = a_2;
s_3 = a_3;
s_4 = a_4;
s_5 = a_5;
s_6 = a_6;
s_7 = a_7;
volt0 = ina0.getBusVoltage_V();
amp0 = ina0.getCurrent_A();
volt1 = ina1.getBusVoltage_V();
amp1 = ina1.getCurrent_A();
volt2 = ina2.getBusVoltage_V();
amp2 = ina2.getCurrent_A();
a_sens_0 = analogRead(33);
a_sens_1 = analogRead(32);
a_sens_2 = analogRead(35);
a_sens_3 = analogRead(34);
a_sens_4 = analogRead(39);
a_sens_5 = analogRead(36);
Blynk.virtualWrite(V8, volt0);
Blynk.virtualWrite(V9, volt1);
Blynk.virtualWrite(V10, volt2);
Blynk.virtualWrite(V11, amp0);
Blynk.virtualWrite(V12, amp1);
Blynk.virtualWrite(V13, amp2);
//Blynk.run();
}
void write()
{
Blynk.virtualWrite(V6, s_6);
Blynk.virtualWrite(V7, s_7);
Blynk.virtualWrite(V22, a_sens_0);
Blynk.virtualWrite(V23, a_sens_1);
Blynk.virtualWrite(V24, a_sens_2);
Blynk.virtualWrite(V25, a_sens_3);
Blynk.virtualWrite(V26, a_sens_4);
Blynk.virtualWrite(V27, a_sens_5);
//Blynk.run();
}
void write1()
{
Blynk.virtualWrite(V0, s_0);
Blynk.virtualWrite(V1, s_1);
Blynk.virtualWrite(V2, s_2);
Blynk.virtualWrite(V3, s_3);
Blynk.virtualWrite(V4, s_4);
Blynk.virtualWrite(V5, s_5);
//Blynk.run();
}
BLYNK_WRITE(V28) //rly0
{
if(param.asInt() == 1)
{
mcp.digitalWrite(7, HIGH);
}
else
{
mcp.digitalWrite(7, LOW);
}
}
/// more relays max 16
void setup()
{
Serial.begin(115200);
mcp.begin_I2C(0x20);
ads0.begin(0x48);
ads1.begin(0x49);
Wire.begin();
ina0.init();
ina0.setResistorRange();
ina1.init();
ina1.setResistorRange();
ina2.init();
ina2.setResistorRange();
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setTimeout(100, [](){
timer.setInterval(1000L, feedback);
});
timer.setTimeout(200, [](){
timer.setInterval(1000L, read_write);
});
timer.setTimeout(300, [](){
timer.setInterval(1000L, write);
});
timer.setTimeout(400, [](){
timer.setInterval(1000L, write1);
});
mcp.pinMode(7, OUTPUT); //rly0
mcp.pinMode(8, INPUT); //fdback_0
}
void loop()
{
Blynk.run();
timer.run();
}