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