3 device connected to 1 blynk app, need to read the 3 value for average

hi, i need help, currently im doing my project for my university course, device 1,2 and 3 are identical device, they are connected to the blynk app. i need to retrieve the data send to the blynk app and find the average between the 3. do i need to do the calculation in the coding or is there any features in the blynk app? thank you. sorry the code is messy, still in prototyping.

if using BLYNK_WRITE, can i use it to retrieve data from other devices?



//blynk
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>


//ph
#include "DFRobot_ESP_PH.h"
#include "EEPROM.h"
DFRobot_ESP_PH ph;
#define ESPADC 4096.0   //the esp Analog Digital Convertion value
#define ESPVOLTAGE 3300 //the esp voltage supply value
#define PH_PIN 35    //the esp gpio data pin number
float voltage, phValue, temperature = 25;

//temp
#include <OneWire.h>
#include <DallasTemperature.h>
// GPIO where the DS18B20 is connected to
const int oneWireBus = 32;     
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(oneWireBus);
// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

//led
const byte led_gpio = 34;  // The pin the LED is connected to

//turb
#include <Wire.h> 
int sensorPin = 33;
float volt;
float ntu;
int turbidity;
int Vclear = 5;


//blynk
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";
SimpleTimer timer;
int Time_S = 1;


void setup()
{
  // Debug console
  Serial.begin(9600);
  EEPROM.begin(32);
  ph.begin();
  sensors.begin();
  delay(5000);
  Blynk.begin(auth, ssid, pass);
  //timer.setInterval(1000L, getSendData);
}

void loop()
{
  
  get_ph();
  turb();
  Blynk.run();
  delay(1000);
  delay(1000*Time_S);

  
}


void get_ph() {
  static unsigned long timepoint = millis();
  if (millis() - timepoint > 1000U) //time interval: 1s
  {
    timepoint = millis();
    //voltage = rawPinValue / esp32ADC * esp32Vin
    voltage = analogRead(PH_PIN) / ESPADC * ESPVOLTAGE; // read the voltage
    Serial.print("voltage:");
    Serial.println(voltage, 4); 

    sensors.requestTemperatures(); 
    float temperature = sensors.getTempCByIndex(0);
    Serial.print(temperature);
    Serial.println("ºC");
    Blynk.virtualWrite(V2, temperature);

    phValue = ph.readPH(voltage, temperature); // convert voltage to pH with temperature compensation
    Serial.print("pH:");
    Serial.println(phValue, 4);
    Blynk.virtualWrite(V1, phValue);
  }
  ph.calibration(voltage, temperature); // calibration process by Serail CMD
  
  if (phValue < 5) {
  Blynk.notify("WARNING! PH VALUE LOWER THAN 5!");
  Blynk.email("@gmail.com", "LOW PH WARNING", "WARNING! PH VALUE LOWER THAN 5! REQUIRE IMMEDIATE ATTENTION!");
  //ON LED
    
  }
  if ((phValue > 5) && (phValue < 9)) {
  //Blynk.notify("WARNING! PH VALUE LOW THAN 5!");
  //TURN OFF LED

  }
  if (phValue > 9) {
  Blynk.notify("WARNING! PH VALUE HIGHER THAN 9!");
  Blynk.email("@gmail.com", "HIGH PH WARNING", "WARNING! PH VALUE HIGHER THAN 5! REQUIRE IMMEDIATE ATTENTION!");
  //ON LED
    
  }

  if (temperature < 39) {
  //Blynk.notify("WARNING! PH VALUE LOW THAN 5!");
  //OFF LED
  }
   if (temperature > 40) {
  Blynk.notify("WARNING! TEMPERATURE OF WATER HIGHER THAN 40'C");
  Blynk.email("@gmail.com", "HIGH WATER TEMPERATURE WARNING", "WARNING! WATER TEMPTERATURE HIGHER THAN 5! REQUIRE IMMEDIATE ATTENTION!");
  //ON LED
}

}

void turb() {
  
      volt = 0;
    for(int i=0; i<800; i++)
    {
        volt += ((float)analogRead(sensorPin)/4095)*5;
    }
    volt = volt/800;
    volt = round_to_dp(volt,2);
    if(volt < 2.5){
      ntu = 3000;
    }else{
      ntu = ((-1120.4*(sq(volt)))+(5742.3*volt)-4352.9); 
    }
    
    Serial.print(volt);
    Serial.println(" V");
 
    Serial.print(ntu);
    Serial.println(" NTU");

    
    turbidity = 100.00 - (volt / Vclear) * 100.00; 
    Serial.print("Turbidity: ");
    Serial.print(turbidity);
    Serial.println(" %");
    Blynk.virtualWrite(V3, ntu);
    Blynk.virtualWrite(V4, turbidity);

   if (turbidity > 80) {
  Blynk.notify("WARNING! WATER TOO DIRTY");
  Blynk.email("@gmail.com", "DIRTY WATER WARNING", "WARNING! WATER TURBIDITY HIGHER THAN 80%! REQUIRE IMMEDIATE ATTENTION!");
  //ON LED
   } 
    delay(1000);
}


float round_to_dp( float in_value, int decimal_place )
{
  float multiplier = powf( 10.0f, decimal_place );
  in_value = roundf( in_value * multiplier ) / multiplier;
  return in_value;
}

I’m surprised to see your void loop with delay , and other blocking functions in your code.
Are you sure this sketch works well with Blynk ?:thinking:

Why?
Wouldn’t it be simpler to average the values that were sent to Blynk within your sketch, rather then sending them, then getting them back again to do further processing on them?

Pete.

how to do i retrieve values from other device to average them in the sketch? there are 3 esp32 with temperature sensor, with same sensors, temp a from device 1, temp b from device 2 and temp c from device 3, i need to display average value of these 3 sensors and display in the blynk app.

im sorry im still beginner about coding, i does work with blynk 1.0

1 Like

i just found out about bridge function in blynk app, i will try that, thank you for all your responses.

@Danial_Ghazali bridge widget has been replaced with automation

He is using Blynk legacy

Ohh, sorry :sweat_smile:

1 Like