L-36.com

DIY Boat Monitoring Software

Arduino code


esp32/arduino.png

I have posted the setup function that controls the entire monitor below. You can see from the image above that there are many modules called by this main thread. The code executes once and then sleeps. Each module has a function, for example reading the voltage. I believe I have given enough information in the course of this article for you to write the modules that will do the things you want to do for your boat. The important thing is to have a structure to put the modules in and I am posting that, without any warranty etc etc. This project is your responsibility and you will have to make it work. I am happy to answer questions. Just use the CONTACT form.

The two significant modules are the WiFi send module which you can basically get from the link I gave in the WiFi section and the Voltage Measurement HERE. If you want to send email with a G2 netwrok please read the article on Sending email with ESP32-SIM800 HERE.


#include "ESP32_MailClient.h"
#include 
#include 
#include 
#include "definitions.h"
//#define DEBUG
#define  MOREEMAIL
#define VERSION "11"
#define UNIT 2
// note, time goal was changed. 2 changes

/*********************************************************
 * HERE is the program
 *********************************************************/
void setup(){
  setupModes(); 
  delay(100);  // wait for serial to process
  digitalWrite(LED_BUILTIN, ON);
  // measure time and check if just powered up
  time(&now);// the timer count for now in seconds
  if( now < 100) delay(2000); //let things settle when power first applied

  
  //Print the wakeup reason for ESP32
  wakeup_reason = esp_sleep_get_wakeup_cause();
  print_wakeup_reason(wakeup_reason);

  readInputs();

  if( checkMainPower() == ON){// basically turn unit off if going sailing
     sleepTime();
  }
  
  checkFan();
 
  //Test for problems. A problem will send an email on the next half hour or sooner if it was from an interrupt

  checkShorePower();

  checkBattery();

  if( checkPumps()== ON){
    Serial.println("Large Pump went on");
  }


  // test if time of day to send status
  Serial.println("time is " + String(now));
  Serial.println("target time is " + String(targetTime));

  
  if (now >= targetTime){ //this is the once a day message, clear problem sent flats
    clearFlags = TRUE;
  }


  if(now >= targetTime || problem){
    targetTime = sendEmail(voltageBat1,voltageBat2,pumpRunTime,message);
   
    Serial.print("Send this many hours from now: ");
    Serial.println( (double)(targetTime - now) / (60*60));
  }
  else Serial.println("not time to send email yet");

  /* The unit will sleep for half an hour (typically) if the email was sent.
  If the email was not sent, it will wait 5 minutes. It will retry MAX_RETRY 
  times and then give up. When the unit wakes up past the target email time, 
  and email will be sent. If the email was not sent, the target time will 
  cause an emial to be sent.
  */
  sleepTime();
}

void loop() {
  //nothing in here as sketch never gets here. It goes to sleep.
}


Beginning⇦


NOTICE: Some pages have affiliate links to Amazon. As an Amazon Associate, I earn from qualifying purchases. Please read website Cookie, Privacy, and Disclamers by clicking HERE. To contact me click HERE. For my YouTube page click HERE