Skip to content

Commit

Permalink
v2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
s60sc authored May 19, 2024
1 parent 6cc24d1 commit 470a7e0
Show file tree
Hide file tree
Showing 13 changed files with 2,596 additions and 1,255 deletions.
8 changes: 3 additions & 5 deletions ESP32_SpecificGravity.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ static bool startedUp = false;

void setup() {
logSetup();
startStorage();
loadConfig();
// prep SD card storage & load saved user configuration
if (startStorage()) loadConfig();

#ifdef DEV_ONLY
devSetup();
Expand All @@ -44,9 +44,7 @@ void setup() {
if (strlen(startupFailure)) LOG_ERR("%s", startupFailure);
else {
// start rest of services
SGsetup();
LOG_INF(APP_NAME " v" APP_VER " ready ...");
startedUp = true;
if (SGsetup()) startedUp = true;
checkMemory();
}
}
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ The generated data is packaged into a json string, this data can be viewed:
On power up, ESP32 will remain awake for calibration purposes (see below) until user presses the __Start__ button on the web page.
The ESP32 will then periodically wakeup to collect data and send this to the remote host, then return to deep sleep.

## Installation

Download github files into the Arduino IDE sketch folder, removing `-main` from the application folder name.

Compile with PSRAM enabled and the following Partition scheme:
* ESP32-S3 - `8M with spiffs (...)`
* ESP32 - `Minimal SPIFFS (...)`

On first installation, the application will start in wifi AP mode - connect to SSID: **ESP32_SG_...**, to allow router and password details to be entered via the web page on `192.168.4.1`. The configuration data file (except passwords) is automatically created, and the application web pages automatically downloaded from GitHub to the SD card **/data** folder when an internet connection is available.

Subsequent updates to the application, or to the **/data** folder files, can be made using the **OTA Upload** tab. The **/data** folder can also be reloaded from GitHub using the **Reload /data** button on the **Edit Config** tab, or by using a WebDAV client.

## Setup and Calibration

The ESP32 and GY-521 modules fit snugly into a 33mm width x 120mm height PETling:
Expand Down
112 changes: 78 additions & 34 deletions appGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,75 +8,120 @@
#define ALLOW_SPACES false // set true to allow whitespace in configs.txt key values

// web server ports
#define WEB_PORT 80 // app control
#define OTA_PORT (WEB_PORT + 1) // OTA update
#define HTTP_PORT 80 // app access
#define HTTPS_PORT 443 // secure app access

/*********************** Fixed defines leave as is ***********************/
/** Do not change anything below here unless you know what you are doing **/

//#define DEV_ONLY // leave commented out
#define STATIC_IP_OCTAL "123" // dev only
#define CHECK_MEM false // leave as false
#define FLUSH_DELAY 200 // for debugging crashes

#define DEBUG_MEM false // leave as false
#define FLUSH_DELAY 0 // for debugging crashes
#define DBG_ON false // esp debug output
#define DOT_MAX 50
#define HOSTNAME_GRP 0

#define APP_NAME "ESP32_SG" // max 15 chars
#define APP_VER "1.2"
#define APP_VER "2.2"

#define MAX_CLIENTS 2 // allowing too many concurrent web clients can cause errors
#define HTTP_CLIENTS 2 // http, ws
#define MAX_STREAMS 0
#define INDEX_PAGE_PATH DATA_DIR "/SG" HTML_EXT
#define FILE_NAME_LEN 64
#define JSON_BUFF_LEN (1024 * 4)
#define IN_FILE_NAME_LEN 128
#define JSON_BUFF_LEN (1024 * 4) // set big enough to hold json string
#define MAX_CONFIGS 100 // > number of entries in configs.txt
#define GITHUB_URL "https://raw.githubusercontent.com/s60sc/ESP32_SpecificGravity/master"
#define GITHUB_PATH "/s60sc/ESP32_SpecificGravity/master"

#define STORAGE LittleFS // One of LittleFS or SD_MMC
#define RAMSIZE (1024 * 8)
#define CHUNKSIZE (1024 * 4)
#define RAM_LOG_LEN 5000 // size of ram stored system message log in bytes
//#define INCLUDE_FTP
//#define INCLUDE_SMTP
//#define INCLUDE_SD
//#define INCLUDE_MQTT
#define MIN_RAM 8 // min object size stored in ram instead of PSRAM default is 4096
#define MAX_RAM 4096 // max object size stored in ram instead of PSRAM default is 4096
#define TLS_HEAP (64 * 1024) // min free heap for TLS session
#define WARN_HEAP (32 * 1024) // low free heap warning
#define WARN_ALLOC (16 * 1024) // low free max allocatable free heap block
#define MAX_ALERT 1024

#define INCLUDE_FTP_HFS false // ftp.cpp (file upload)
#define INCLUDE_SMTP false // smtp.cpp (email)
#define INCLUDE_MQTT false // mqtt.cpp
#define INCLUDE_TGRAM false // telegram.cpp
#define INCLUDE_CERTS false // certificates.cpp (https and server certificate checking)
#define INCLUDE_WEBDAV true // webDav.cpp (WebDAV protocol)

#define IS_IO_EXTENDER false // must be false except for IO_Extender
#define EXTPIN 100

// to determine if newer data files need to be loaded
#define HTM_VER "1"
#define JS_VER "0"
#define CFG_VER "1"

#define NULL_TEMP -127.0
#define FILE_EXT ""

// I2C devices requiring separate libraries
#define CFG_VER 2

#ifdef CONFIG_IDF_TARGET_ESP32S3
#define SERVER_STACK_SIZE (1024 * 8)
#define DS18B20_STACK_SIZE (1024 * 2)
#define STICK_STACK_SIZE (1024 * 4)
#else
#define SERVER_STACK_SIZE (1024 * 4)
#define DS18B20_STACK_SIZE (1024)
#define STICK_STACK_SIZE (1024 * 2)
#endif
#define BATT_STACK_SIZE (1024 * 2)
#define EMAIL_STACK_SIZE (1024 * 6)
#define FS_STACK_SIZE (1024 * 4)
#define LOG_STACK_SIZE (1024 * 3)
#define MQTT_STACK_SIZE (1024 * 4)
#define PING_STACK_SIZE (1024 * 5)
#define SERVO_STACK_SIZE (1024)
#define SUSTAIN_STACK_SIZE (1024 * 4)
#define TGRAM_STACK_SIZE (1024 * 6)
#define TELEM_STACK_SIZE (1024 * 4)
#define UART_STACK_SIZE (1024 * 2)

// task priorities
#define HTTP_PRI 5
#define STICK_PRI 5
#define TGRAM_PRI 1
#define EMAIL_PRI 1
#define FTP_PRI 1
#define LOG_PRI 1
#define SERVO_PRI 1
#define UART_PRI 1
#define BATT_PRI 1
#define IDLEMON_PRI 5

// devices requiring separate libraries
#define USE_BMP280 false
#define USE DS3231 false
#define USE_SSD1306 false
#define USE_MPU6050 true
#define USE_DS18B20 false

// LCD 1602
enum onoffType {OFF, ON};
enum lfType {LEFT, RIGHT};
enum customChar {CELSIUS, CC1, CC2, CC3, CC4, CC5, CC6, CC7};
// devices not requiring separate libraries
#define USE_LCD1602 false
#define USE_PCF8591 false
#define USE_MPU6050 true

#define NULL_TEMP -127.0
#define FILE_EXT ""


/******************** Function declarations *******************/

// global app specific functions
void SGsetup();
bool SGsetup();
void SGloop();
bool checkMPU6050();
double* readMPU6050();
float* readMPU6050();
bool sleepMPU6050(bool doSleep = true);
void checkI2C();
bool getI2Cdata (uint8_t clientAddr, uint8_t controlByte, uint8_t numBytes);
bool sendI2Cdata(int clientAddr, uint8_t controlByte, uint8_t numBytes);
float* getBMP280();
bool checkI2Cdevices(bool showWarn = false);
bool startI2C();
void displayValuesOled(int inDispIndex, bool dispChanged);
void setLamp(uint8_t lampVal);

/******************** Global app declarations *******************/

// status & control fields
extern const char* appConfig;

// batt monitoring
extern int voltPin;
Expand All @@ -87,4 +132,3 @@ extern int voltInterval;

extern int I2C_SDA;
extern int I2C_SCL;
extern int MPU6050addr;
Loading

0 comments on commit 470a7e0

Please sign in to comment.