Data Gator
Hardware and software documentation for the Data Gator project.
Loading...
Searching...
No Matches
main.cpp File Reference

Initializes device and calls routines. More...

#include <Arduino.h>
#include <cstring>
#include "SDReader.hpp"
#include <version.hpp>
#include <pinout.hpp>
#include <config.hpp>
#include <firebeetle_sleep.hpp>
#include <update.cpp>
#include <logging_util.cpp>
#include <mqtt_util.hpp>
#include <setup_util.hpp>
#include <scheduler.hpp>
#include <logger.hpp>
#include <SPI.h>
#include <HttpsOTAUpdate.h>
#include <Preferences.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
Include dependency graph for main.cpp:

Functions

PubSubClient mqtt_client (wifi_client)
 MQTT client object.
 
void setup ()
 Setup initializes sensor interfaces, NVS, wireless protocols, and logging options.
 
void loop ()
 Read sensors, log data, and hibernate.
 

Variables

Adafruit_ADS1115 ads
 Analog to digital converter object (I2C)
 
Adafruit_MAX17048 maxlipo
 MAX17048 battery Fuel Gauge.
 
bool maxlipo_attached
 Fuel Gauge successfully initialized?
 
int reset_count
 number of resets retrieved for NVS
 
const bool USB_DEBUG = DEBUG
 USB serial debugging enabled.
 
WiFiClient wifi_client
 WiFi stack object.
 
Preferences gator_prefs
 NVS memory object.
 

Detailed Description

Initializes device and calls routines.

Uses the Arduino framework to initialize devices and call routines to collect data and manage power. This file is required for compilation in the Arduino framework. Furthermore it contains implementations of the Arduino required functions setup() and loop().

The Arduino model of execution has been adapted to fit a different executional model which prioritizes intermittent, low power data collection. Arduino defaults to running the code within loop an infinite number of times until the device is stopped or runs out of a resource such as power.

In many precision agriculture scenarios the rate of change of any monitored variable such as temperature likely needs to be polled no more than once a minute. Any more than this degree of resolution is probably a waste of energy. To accomodate this norm, the Data Gator (DG) firmware is configured to run the code in loop once and then shutdown (enter low power mode) to conserve battery life.

This file implements main.

Author
Garrett Wells
Date
2022

Function Documentation

◆ loop()

void loop ( void  )

Read sensors, log data, and hibernate.

Although specified to loop infinitely by the Arduino API, this function does the following in one iteration:

  1. reads sensors,
  2. logs data,
  3. and finishes by putting the system into hibernation to conserve energy.

◆ setup()

void setup ( void  )

Setup initializes sensor interfaces, NVS, wireless protocols, and logging options.

This function initializes all global resources and bus based protocols. A list (non-exhaustive but pretty complete) can be found below:

  1. initializes gpio pins,
  2. initializes i2c sensors,
  3. starts serial debug interface and waits 1 sec (defaults to 115200 baud),
  4. initializes the non-volatile memory system (specific to ESP32, adapt for other uC),
  5. initializes wireless connections,
  6. initializes logging systems and configures flags based on what logging interfaces are available.

Variable Documentation

◆ ads

Adafruit_ADS1115 ads
extern

Analog to digital converter object (I2C)

Interface for the analog to digital converter.

◆ gator_prefs

Preferences gator_prefs

NVS memory object.

Reference to non-volatile-storage on ESP32.

NVS memory access interface.

◆ maxlipo

Adafruit_MAX17048 maxlipo
extern

MAX17048 battery Fuel Gauge.

Interface for the battery fuel gauge.

◆ maxlipo_attached

bool maxlipo_attached
extern

Fuel Gauge successfully initialized?

External flag indicating whether maxlipo was initialized successfully.

◆ reset_count

int reset_count
extern

number of resets retrieved for NVS

External variable holding the number of resets recorded by the system. Stored and loaded from non-volatile storage.

◆ USB_DEBUG

const bool USB_DEBUG = DEBUG

USB serial debugging enabled.

Serial debug enable flag, set in config.h