Getting Daily Max Reading From Sensor

Hey all, I am hoping someone can help me out. In order to move forward on my project, I need a daily max of pressureDelta sent to my email. I am using Blynk to monitor the system. I have been searching the forums for something like this, and all I have found is folks saying they want a max of a certain amount of readings, where I just want to say at a certain time, send an email with the max pressureDelta reading seen by the board. Anyone willing to help me out? Thanks in advance for any help.

#include <Smoothed.h>
#include <Blynk.h>
#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>


char ssid[] = "-----";
char pass[] = "-----";
int status = WL_IDLE_STATUS;



char auth[] = "-----";
BlynkTimer timer;
boolean beenNotified;

Smoothed <float> sensorData;
Smoothed <float> sensorData2;
float currentPreSensorValue;
float currentPostSensorValue;
float smoothedPreSensorValueExp;
float smoothedPostSensorValueExp;

float preVoltage;
float postVoltage;
float prePsi;
float postPsi;
float pressureDelta;
float preVoltageTotal;
float postVoltageTotal;

float orderThreshold = 2.75;
float changeThreshold = 3.25;

enum FilterStatus {FilterOk, OrderFilter, ChangeFilter};

FilterStatus FilterCondition = FilterOk;

int i;

WidgetLED ledGood(V1);
WidgetLED ledOrder(V2);
WidgetLED ledChange(V3);

byte preSensorPin = A1;
byte postSensorPin = A2;
const byte yellowLEDPin = 7;
const byte redLEDPin = 6;

void setup() {

  SerialUSB.begin(9600);

  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, myTimerEvent);
  
  sensorData.begin(SMOOTHED_EXPONENTIAL, 10);
  sensorData2.begin(SMOOTHED_EXPONENTIAL, 10);

  pinMode(preSensorPin, INPUT);
  pinMode(postSensorPin, INPUT);
  pinMode(yellowLEDPin, OUTPUT);
  pinMode(redLEDPin, OUTPUT);

}

void loop() {

  Blynk.run();
  timer.run();

  // Read the value from the sensor
  currentPreSensorValue = analogRead(preSensorPin);
  currentPostSensorValue = analogRead(postSensorPin);

  //Add the new value to both sensor value stores
  sensorData.add(currentPreSensorValue);
  sensorData2.add(currentPostSensorValue);

  // Get the smoothed values
  smoothedPreSensorValueExp = sensorData.get();
  smoothedPostSensorValueExp = sensorData2.get();

  Serial.print("  Pre-filter psi: ");
  Serial.println(prePsi);

  Serial.print("  Post-filter psi: ");
  Serial.println(postPsi);

  CheckFilter();
  ManageFilterNotify();
  ManageFilterLeds();
}

void myTimerEvent()
{

  preVoltage =  (5.0 / 1023.0) * smoothedPreSensorValueExp;
  prePsi = (preVoltage - 0.5) * (100.0) / (4.5 - 0.5);
  Blynk.virtualWrite(V5, prePsi);


  postVoltage =  (5.0 / 1023.0) * smoothedPostSensorValueExp;
  postPsi = (postVoltage - 0.5) * (100.0) / (4.5 - 0.5);
  Blynk.virtualWrite(V6, postPsi);

  pressureDelta = (prePsi - postPsi);
  Blynk.virtualWrite(V7, pressureDelta);

}

void CheckFilter()  // Filter condition state machine
{
  // All we can do is go from OK to order or from Order to change
  switch (FilterCondition)
  {
    case FilterOk:
      if (prePsi - postPsi > orderThreshold)      //  if the pressure drop is greater than Order threshold
      {
        FilterCondition = OrderFilter;
      }
      break;
    case OrderFilter:
      if (prePsi - postPsi > changeThreshold)        //if the pressure drop is greater than replace threshold
      {
        FilterCondition = ChangeFilter;
      }
      break;
    case ChangeFilter:  // Once we're in this state, only a reset will change it.
      break;
  }
}

void ManageFilterNotify()
{
  switch (FilterCondition)
  {
    case FilterOk:
      Serial.println("Filter ok");
      ledGood.on();
      ledOrder.off();
      ledChange.off();
      break;
    case OrderFilter:
      Serial.println("Order filter");
      if(beenNotified == 0){
      Blynk.email("-----", "FilterLynk Condition", "It is time to order a filter");
      beenNotified++;
      }
      ledGood.off();
      ledOrder.on();
      break;
    case ChangeFilter:
      Serial.println("Replace filter");
      ledOrder.off();
      ledChange.on();
      break;
  }
}

void ManageFilterLeds()
{
  switch (FilterCondition)
  {
    case FilterOk:
      Serial.println("Leds off - filter ok");
      digitalWrite(redLEDPin, LOW);
      digitalWrite(yellowLEDPin, LOW);
      break;
    case OrderFilter:
      Serial.println("Show yellow - order filter");
      digitalWrite(redLEDPin, LOW);
      digitalWrite(yellowLEDPin, HIGH);
      break;
    case ChangeFilter:
      Serial.println("Show red - replace filter");
      digitalWrite(redLEDPin, HIGH);
      digitalWrite(yellowLEDPin, LOW);
      break;
  }
}

I just want to say at a certain time, send an email with the max pressureDelta reading seen by the board. Anyone willing to help me out? Thanks in advance for any help.

It would appear that there are three issues

  1. Determining the maximum pressure delta reading which is basically
if (currentValue > maximumValue)
 maximumValue = currentValue;
  1. Determining the time.

  2. Sending an email with blynk.

What are you having problems with?

Thanks for the reply. I have added the global variable pressureDeltaMax, and the simple code below.

if (pressureDelta > pressureDeltaMax)
      pressureDeltaMax = pressureDelta;

I have also added two libraries

#include <Time.h>
#include <TimeLib.h>

I have been able to get blynk to send an email when a condition is met.

So, really I need help with getting the board to accomplish a task at a certain time, the task of sending out pressureDeltaMax at certain time, everyday. So maybe all I need is an if statement in the loop? Checking to see if the current time is x? Then of course performing the action.

So maybe all I need is an if statement in the loop? Checking to see if the current time is x? Then of course performing the action.

Sounds about right. There may be some coding detail to only perform the action once, if the condition is true for a period of time where the action could happen multiple times.

It would also be good to synchronize the Time library time with an external source of time, as the processor clock may fast or slow. I don't know if blynk can supply a time, or if you will have to use wifi to synchronize with a time server. The time library has several examples of how to synchronize the time to an external source a periodic intervals.

If you are concerned with the max value in a time period, you will want to reset the pressureDeltaMax to some minimum value so that you begin to accumulate a new max after sending.