Need help about discconects

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();
}


@electrosurfer Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

1 Like

You should post your entire sketch, along with details of all of the hardware you are using.

Pete.

1 Like

this code was my last attempt
3x ina226(voltage and current sensor ic)
2x ads1115 (adc ic)
1x mcp23017 (digital mux)
6x relays
these are fed with buck converter

#define BLYNK_TEMPLATE_ID "xxxx"
#define BLYNK_TEMPLATE_NAME "xxxx"
#define BLYNK_AUTH_TOKEN "xxxx"

#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Adafruit_MCP23X17.h>
#include <Wire.h>
#include <Adafruit_ADS1X15.h>
#include <INA226_WE.h>

INA226_WE ina0 = INA226_WE(0x40);
INA226_WE ina1 = INA226_WE(0x41);
INA226_WE ina2 = INA226_WE(0x44);
Adafruit_ADS1115 ads0;
Adafruit_ADS1115 ads1;
Adafruit_MCP23X17 mcp;

//ina226
float volt0, volt1, volt2;
float amp0, amp1, amp2;
//ina226
//ads1115
int16_t ads0_0, ads0_1, ads0_2, ads0_3;
int16_t ads1_0, ads1_1, ads1_2, ads1_3;

int sens_0, sens_1, sens_2, sens_3;
int sens_4, sens_5, sens_6, sens_7;
//ads1115
//feedback
int feedback_all;
bool fdback_0, fdback_0_old;
bool fdback_1, fdback_1_old;
bool fdback_2, fdback_2_old;
bool fdback_3, fdback_3_old;
bool fdback_4, fdback_4_old;
bool fdback_5, fdback_5_old;
bool fdback_6, fdback_6_old;
bool fdback_7, fdback_7_old;
//feedback
//relay_cur_sens
float cur_sens_0, cur_sens_1, cur_sens_2;
float cur_sens_3, cur_sens_4, cur_sens_5;
//relay_cur_sens

char ssid[] = "xxxxxxxx";
char pass[] = "xxxxxxxxxx";
BlynkTimer timer;

void sensor()
{
  feedback_all = mcp.readGPIO(1);
  //Serial.println(feedback_all, HEX);
  fdback_0 = bitRead(feedback_all, 0);
if (fdback_0 != fdback_0_old) {
   if(fdback_0 == 1){
    Blynk.virtualWrite(V14,1);
   }
  else{
    Blynk.virtualWrite(V14,0);
  }
   fdback_0_old = fdback_0;
}

  fdback_1 = bitRead(feedback_all, 1);
if (fdback_1 != fdback_1_old) {
   if(fdback_1 == 1){
    Blynk.virtualWrite(V15,1);
   }
  else{
    Blynk.virtualWrite(V15,0);
  }
   fdback_1_old = fdback_1;
}

  fdback_2 = bitRead(feedback_all, 2);
if (fdback_2 != fdback_2_old) {
   if(fdback_2 == 1){
    Blynk.virtualWrite(V16,1);
   }
  else{
    Blynk.virtualWrite(V16,0);
  }
   fdback_2_old = fdback_2;
}

  fdback_3 = bitRead(feedback_all, 3);
if (fdback_3 != fdback_3_old) {
   if(fdback_3 == 1){
    Blynk.virtualWrite(V17,1);
   }
  else{
    Blynk.virtualWrite(V17,0);
  }
   fdback_3_old = fdback_3;
}

  fdback_4 = bitRead(feedback_all, 4);
if (fdback_4 != fdback_4_old) {
   if(fdback_4 == 1){
    Blynk.virtualWrite(V18,1);
   }
  else{
    Blynk.virtualWrite(V18,0);
  }
   fdback_4_old = fdback_4;
}

  fdback_5 = bitRead(feedback_all, 5);
if (fdback_5 != fdback_5_old) {
   if(fdback_5 == 1){
    Blynk.virtualWrite(V19,1);
   }
  else{
    Blynk.virtualWrite(V19,0);
  }
   fdback_5_old = fdback_5;
}

  fdback_6 = bitRead(feedback_all, 6);
if (fdback_6 != fdback_6_old) {
   if(fdback_6 == 1){
    Blynk.virtualWrite(V20,1);
   }
  else{
    Blynk.virtualWrite(V20,0);
  }
   fdback_6_old = fdback_6;
}

  fdback_7 = bitRead(feedback_all, 7);
if (fdback_7 != fdback_7_old) {
   if(fdback_7 == 1){
    Blynk.virtualWrite(V21,1);
   }
  else{
    Blynk.virtualWrite(V21,0);
  }
   fdback_7_old = fdback_7;
}
}

void sensor1()
{
  ads0_0 = ads0.readADC_SingleEnded(3);
  ads0_1 = ads0.readADC_SingleEnded(2);
  ads0_2 = ads0.readADC_SingleEnded(1);
  ads0_3 = ads0.readADC_SingleEnded(0);

  ads1_0 = ads1.readADC_SingleEnded(3);
  ads1_1 = ads1.readADC_SingleEnded(2);
  ads1_2 = ads1.readADC_SingleEnded(1);
  ads1_3 = ads1.readADC_SingleEnded(0);
  
  sens_0 = ads0_0;
  sens_1 = ads0_1;
  sens_2 = ads0_2;
  sens_3 = ads0_3;
  
  sens_4 = ads1_0;
  sens_5 = ads1_1;
  sens_6 = ads1_2;
  sens_7 = ads1_3;
  
  volt0 = (float) 0.001234 * (ina0.readRegister(2)) - 0.015915;
  amp0 = ina0.getCurrent_A();
  volt1 = (float) 0.001234 * (ina1.readRegister(2)) - 0.015915;
  amp1 = ina1.getCurrent_A();
  volt2 = (float) 0.001234 * (ina2.readRegister(2)) - 0.015915;
  amp2 = ina2.getCurrent_A();
  
  cur_sens_0 = analogRead(33);
  cur_sens_1 = analogRead(32);
  cur_sens_2 = analogRead(35);
  cur_sens_3 = analogRead(34);
  cur_sens_4 = analogRead(39);
  cur_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 sensor2()
{ 
  Blynk.virtualWrite(V6, sens_6);

  Blynk.virtualWrite(V7, sens_7);
  
  Blynk.virtualWrite(V22, cur_sens_0);

  Blynk.virtualWrite(V23, cur_sens_1);
  
  Blynk.virtualWrite(V24, cur_sens_2);

  Blynk.virtualWrite(V25, cur_sens_3);
  
  Blynk.virtualWrite(V26, cur_sens_4);

  Blynk.virtualWrite(V27, cur_sens_5);
  //Blynk.run();
}

void sensor3()
{
  Blynk.virtualWrite(V0, sens_0);

  Blynk.virtualWrite(V1, sens_1);
  
  Blynk.virtualWrite(V2, sens_2);

  Blynk.virtualWrite(V3, sens_3);
  
  Blynk.virtualWrite(V4, sens_4);

  Blynk.virtualWrite(V5, sens_5);
  //Blynk.run();
}

BLYNK_WRITE(V28) //rly0 
{ 
  if(param.asInt() == 1)
  {
    mcp.digitalWrite(7, HIGH);
  }
  else
  { 
    mcp.digitalWrite(7, LOW);
  }
}

BLYNK_WRITE(V29) //rly1 
{ 
  if(param.asInt() == 1)
  {
    mcp.digitalWrite(6, HIGH);
  }
  else
  { 
    mcp.digitalWrite(6, LOW);
  }
}

BLYNK_WRITE(V30) //rly2 
{ 
  if(param.asInt() == 1)
  {
    mcp.digitalWrite(5, HIGH);
  }
  else
  { 
    mcp.digitalWrite(5, LOW);
  }
}

BLYNK_WRITE(V31) //rly3 
{ 
  if(param.asInt() == 1)
  {
    mcp.digitalWrite(4, HIGH);
  }
  else
  { 
    mcp.digitalWrite(4, LOW);
  }
}

BLYNK_WRITE(V32) //rly4 
{ 
  if(param.asInt() == 1)
  {
    mcp.digitalWrite(3, HIGH);
  }
  else
  { 
    mcp.digitalWrite(3, LOW);
  }
}

BLYNK_WRITE(V33) //rly5 
{ 
  if(param.asInt() == 1)
  {
    mcp.digitalWrite(2, HIGH);
  }
  else
  { 
    mcp.digitalWrite(2, LOW);
  }
}

void setup()
{
  Serial.begin(115200);
  mcp.begin_I2C(0x20);
  ads0.begin(0x48);
  ads1.begin(0x49);
  Wire.begin();
  ina0.init();
  ina0.setResistorRange(0.0001,200);
  ina1.init();
  ina1.setResistorRange(0.0001,200);
  ina2.init();
  ina2.setResistorRange(0.0001,200);
 
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  
  timer.setTimeout(100, [](){
	timer.setInterval(1000L, sensor1);
  });
  timer.setTimeout(200, [](){
	timer.setInterval(1000L, sensor1);
  });
  timer.setTimeout(300, [](){
	timer.setInterval(1000L, sensor2);
  });
  timer.setTimeout(400, [](){
	timer.setInterval(1000L, sensor3);
  });
  
  
//def I/O
  mcp.pinMode(2, OUTPUT); //rly5
  mcp.pinMode(3, OUTPUT); //rly4
  mcp.pinMode(4, OUTPUT); //rly3
  mcp.pinMode(5, OUTPUT); //rly2
  mcp.pinMode(6, OUTPUT); //rly1
  mcp.pinMode(7, OUTPUT); //rly0

  mcp.pinMode(8, INPUT);  //fdback_0
  mcp.pinMode(9, INPUT);  //fdback_1
  mcp.pinMode(10, INPUT); //fdback_2
  mcp.pinMode(11, INPUT); //fdback_3
  mcp.pinMode(12, INPUT); //fdback_4
  mcp.pinMode(13, INPUT); //fdback_5
  mcp.pinMode(14, INPUT); //fdback_6
  mcp.pinMode(15, INPUT); //fdback_7
//def I/O
}

void loop()
{
  Blynk.run();
  timer.run();
}

Does anyone know about firmware, library versions?

What do you want to know?

Pete.

Could my problem related to library, board version?
Do you think this code is ok?

Possibly, always worth updating to the latest version.

I’ve not looked at it, because you didn’t really answer my questions about hardware, because you’ve told us nothing about how everything is connected, and what sort of power supplier you’re using and how all of your devices are powered from this.

Pete.

Oh sorry about it
They are on a custom pcb. Everything is fed with 5v by single buck converter. Buck converter is powered by 12v power supply. 5v is also connected to esp32s 5v pin, 3.3v is generated by its regulator. i2c signal is converted to 3.3v by logic level converter modules. Every component/ic is working properly without blynk. Measurement results are verified with printing to serial monitor

You’ve provided no information about the power output abilities of your buck converter. If it’s being used to energise the coils of 6 relays, power your ESP32 and all of your peripherals then you may have a power supply issue.

That shouldn’t be necessary, the ESP32 is 5v tolerant on its GPIOs.

Why do you have two timers that both call the sensor1() function?

You’ve still not either provided a schematic or a full pinout description for all of your peripherals, so I’m not going to spend hours trying to reverse engineer your code and descriptions into something that gives me an overview of your hardware setup, and without that diving an6 deeper into your code would be a waste of time for me.

Pete.

1 Like