Blynk Issue with Nodemcu aka ESP8266

Hello community this is abhishek
i have been working on the project which name called patient monitoring system which basically takes the health parameter of the patient ,it has 3 main sensors Spo2(MAX30100) and IR temprateremeter and last Blood pressure sensor and Main controller ESP8266 ,spo2 and IR tempmeter usually connects on I2c pins and blood pressure sensor interface with softwareserial pins its brief working

#include <Blynk.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include<SPI.h>
#include <Wire.h>
//#include <SoftwareSerial.h>
#include "MAX30100_PulseOximeter.h"
#include <Adafruit_MLX90614.h>
#define BLYNK_PRINT Serial
#define REPORTING_PERIOD_MS     100
#define EspSerial Serial1
//SoftwareSerial portTwo(15, 13); //TX,RX

char auth[] = "zfdfML-j0uRZGO2OZMI5H87B1vUS1zSD";    // You should get Auth Token in the Blynk App.
char ssid[] = "Ajay_Home";                       // Your WiFi credentials.
char pass[] = "Alph@##1307";

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
PulseOximeter pox;

uint32_t tsLastReport = 0;
double temp_amb = 0;
double temp_obj = 0;
double calibration = 2.36;
int SpO2 = 0;
int i = 2;
char sbuffer[30], ch;
unsigned char pos;
unsigned char read1, read2, read3;
int Sys, Dys, Puls;

void onBeatDetected()
{
  Serial.println("Beat!");
}

char mygetchar(void)
{
  while (!Serial1.available());
  return Serial1.read();
}

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  Blynk.begin(auth, ssid, pass);


  if (!mlx.begin()) {
    Serial.println("FAILED");
    for (;;);
  } else {
    Serial.println("SUCCESS");
  }

  if (!pox.begin()) {
    Serial.println("FAILED");
    for (;;);
  } else {
    Serial.println("SUCCESS");
  }
  pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

  // Register a callback for the beat detection
  pox.setOnBeatDetectedCallback(onBeatDetected);


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


  while (i == 1) {
    Blynk.run();

    pox.update();
    temp_obj = mlx.readObjectTempF();
    SpO2 = pox.getSpO2();
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
      Serial.print("bpm / SpO2:");
      Serial.print(SpO2);
      Serial.println("%");
      Serial.print(tsLastReport);
      Serial.print("Object temp = ");
      Serial.println(temp_obj);

      Blynk.virtualWrite(V3, temp_obj);
      Blynk.virtualWrite(V4, SpO2);
      if ((0 < SpO2) && (SpO2 < 95)) {
        Serial.print("LOW");

      }
      else {
        break;

        delay(10000);
      }

      tsLastReport = millis();
    }
  }

  while (i == 2) {
    Blynk.run();
    ch = mygetchar();
    if (ch == 0x0A)
    {
      pos = 0; // buffer position reset for next reading
      read1 = ((sbuffer[1] - '0') * 100) + ((sbuffer[2] - '0') * 10) + (sbuffer[3] - '0');
      Sys = read1 - '0';
      read2 = ((sbuffer[6] - '0') * 100) + ((sbuffer[7] - '0') * 10) + (sbuffer[8] - '0');
      Dys = read2 - '0';
      read3 = ((sbuffer[11] - '0') * 100) + ((sbuffer[12] - '0') * 10) + (sbuffer[13] - '0');
      Puls = read3 - '0';

      Serial1.println("*****************");
      Serial1.print("SYSTOLIC:");
      Serial1.print(read1, Sys);
      Serial1.print('\n');
      Serial1.print("DYSTOLIC:");
      Serial1.print(read2, Dys);
      Serial1.print('\n');
      Serial1.print("PULSE");
      Serial1.print(read3, Puls);
      Serial1.print('\n');
      Serial1.println("*****************");

      Blynk.virtualWrite(V1, Sys);
      Blynk.virtualWrite(V2, Dys);
      Blynk.virtualWrite(V3, Puls);


      //    tsLastReport = millis();
    }
    else { //store serial data to buffer
      sbuffer[pos] = ch;
      pos++;

    }

  }

}

the issue is whenever I run this code, in blynk app " device connected" and "device is disconnected " getting this kind of message at the bottom of the app repeatedly
i do not know what to do I googled it I read many topics in community still I’m not getting proper solution if any one want to help please reply or you can contact directly to 1MS18TE400@gmail.com this mail …

Probably the problem is stealing resources from Blynk with your while loop. For my Nextion display I have to read serial similar to what you do here. I use one core of the esp32 for blynk and the other one to listen to the serial port. Theoretically putting a Blynk.run in the while loop should help but I haven’t always found it that way.

1 Like

how can you display both board data in a single blynk application …

in my code what should I change? is there any problem with softwareserial and blynk?

Is this question about the ESP32? If so it is one board with two cores. There is some info about it if you search “esp32 two core” in this forum.

I have never used software serial with Blynk I don’t think but others have. The ESP32 also has more than 1 serial port so that it would not be necessary.

No its not about ESP32 … im using ESP8266 but in mycase serial TX and RX not working, thats why i used softwareserial

Like @daveblynk said, your loop is probably the problem! Read this:

Is this a commercial project?

this is probably blocking. nothing can happen while it’s waiting for some serial input

char mygetchar(void)
{
  while (!Serial1.available());
  return Serial1.read();
}