New Text Document
New Text Document
h>
#include <SoftwareSerial.h>
#include <ESP32Time.h>
#include <Wire.h>
#include <Protocentral_FDC1004.h>
#include "SPIFFS.h"
#include <cstring>
#include "BluetoothSerial.h"
#include <cmath>
#define LED_BUILTIN 2 // turn on in_built LED when receive commands via Bluetooth
TinyGPSPlus gps;
SoftwareSerial SerialGPS(rxPin, txPin);
ESP32Time rtc(3600);
BluetoothSerial SerialBT;
int capdac = 0;
float sum = 0;
float capacitance2 = 0;
int i = 0;
float average = 0;
float water_level = 0;
float water_capacity = 0;
int minute_slst;
int hour_slst;
bool isRTCUpdated = false;
FDC1004 FDC;
void setup() {
Serial.begin(115200); // serial baud rate
Wire.begin(); // i2c begin
SerialGPS.begin(9600);
pinMode(GPS_PIN, OUTPUT);
pinMode(CAP_PIN, OUTPUT);
// Turn On GPS and FDC1004
digitalWrite(GPS_PIN, HIGH);
digitalWrite(CAP_PIN, HIGH);
delay(3000);
}
void loop() {
readDataForm_FDC1004();
if (SerialBT.available() > 0) {
char c = SerialBT.read();
if (c == 'r') {
//SerialBT.print(c);
readFile(SPIFFS, "/log.txt");
//SerialBT.print('\n');
// deleteFile(SPIFFS, "/log.txt");
delay(10);
// Only for testing, trun on in_built LED when receive commands via
bluetooth
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
}
}
}
void readDataForm_FDC1004(){
FDC.configureMeasurementSingle(MEASURMENT, CHANNEL, capdac);
FDC.triggerSingleMeasurement(MEASURMENT, FDC1004_100HZ);
capacitance2 = ((float)capacitance/1000);
//Serial.println(capacitance2, 4);
void processAndShowData(){
sum = sum + capacitance2;
i++;
if(i == 50){
if (gps.location.isValid()){
// Display Info ----------------------
displayInfo();
}else{
Serial.println(F("searching for satellites..."));
}
i = 0;
average = 0;
sum = 0;
}
}
void setDateAnDTime(){
// Convert UTC to SLST
minute_slst = gps.time.minute();
hour_slst = gps.time.hour();
/*
* To convert UTC to SLST need to add 5.30 to UTC.
* But Here NEO6 give BST.
* BST to SLST, need to add 4.30.
*/
hour_slst = (hour_slst + 4);
if (hour_slst > 23){
hour_slst = hour_slst - 24;
}
// Set time For RTC (second, minute, hour, day, month, year);
rtc.setTime(gps.time.second(), minute_slst, hour_slst, gps.date.day(),
gps.date.month(), gps.date.year());
}
void displayInfo(){
// // Water Level info ------------------------
average = sum / 50;
// Serial.print("Avg:");
// Serial.print(average, 4);
// Serial.print("pf");
// Serial.print("\t");
//
water_level = ((average - 45.743) / 0.7061); // add 64.78 to error correction
// Serial.print("Liq.Lvl:");
// Serial.print(water_level, 4);
// Serial.print("cm");
// Serial.print("\t");
//
water_capacity = water_level * 94.724;
// Serial.print("Liq.Cap:");
// Serial.print(water_capacity, 4);
// Serial.print("ml");
// Serial.print("\t");
//
// //GPS Info --------------------------------
// Serial.print("Lat:");
// Serial.print(gps.location.lat(), 6);
// Serial.print(F("\t"));
// Serial.print("Lng:");
// Serial.print(gps.location.lng(), 6);
// Serial.print(F("\t"));
// Serial.print(rtc.getTime("%A %B %d %Y %H:%M:%S"));
// Serial.println();
Serial.println(char_array);
// SPIFFS methods
---------------------------------------------------------------------