This commit is contained in:
@@ -25,7 +25,7 @@ lib_deps =
|
||||
https://github.com/x821938/elog
|
||||
board_build.partitions = default.csv
|
||||
upload_protocol = espota
|
||||
upload_port = 192.168.5.180
|
||||
upload_port = 192.168.5.205
|
||||
build_flags = -Wall -Wextra -DLOGGING_SPIFFS_DISABLE -DLOGGING_SD_DISABLE
|
||||
|
||||
[env:ESP32_INA226]
|
||||
|
||||
@@ -72,20 +72,22 @@ void display_task(void* parameter)
|
||||
// We have no error, refresh status display and wait half a second
|
||||
display_percentage(water_data.percentage);
|
||||
} else {
|
||||
logger.log(0, DEBUG, "Error detected");
|
||||
|
||||
// We have an error, display error code for 3 seconds and then water level for 3 seconds
|
||||
if (active_errors.voltage_low) {
|
||||
display_error_code(1);
|
||||
logger.log(0, WARNING, "Sensor Error - Voltage low");
|
||||
delay(3000);
|
||||
} else if (active_errors.voltage_high) {
|
||||
display_error_code(2);
|
||||
logger.log(0, WARNING, "Sensor Error - Voltage High");
|
||||
delay(3000);
|
||||
} else if (active_errors.current_low) {
|
||||
display_error_code(3);
|
||||
logger.log(0, WARNING, "Sensor Error - Current low");
|
||||
delay(3000);
|
||||
} else if (active_errors.current_high) {
|
||||
display_error_code(4);
|
||||
logger.log(0, WARNING, "Sensor Error - Current high");
|
||||
delay(3000);
|
||||
} else {
|
||||
delay(3000);
|
||||
|
||||
53
src/main.cpp
53
src/main.cpp
@@ -25,6 +25,7 @@
|
||||
#include "networking/responses.h"
|
||||
#include <fetchOTA.h>
|
||||
#include <ESP32Ping.h>
|
||||
#include "time.h"
|
||||
|
||||
#define MYLOG 0
|
||||
|
||||
@@ -47,8 +48,6 @@ AsyncWebSocket webSocket("/webSocket");
|
||||
void setup()
|
||||
{
|
||||
logger.registerSerial(MYLOG, DEBUG, "tst");
|
||||
logger.
|
||||
logger.provideTime(2025, 3, 10, 23, 28, 00);
|
||||
prefs.begin("waterlevel", false);
|
||||
Serial.begin(115200);
|
||||
|
||||
@@ -205,19 +204,55 @@ void setup()
|
||||
display_error_code(26);
|
||||
digitalWrite(LED_RED, 0);
|
||||
|
||||
// Starting bootup sequence
|
||||
|
||||
xTaskCreate(ethernet_task, "EthernetTask", 4096, NULL, 1, NULL);
|
||||
delay(1000);
|
||||
bool started = false;
|
||||
|
||||
// Create Etnernet task and wait a second to see if there is connection
|
||||
logger.log(0, DEBUG, "Started Ethernet, waiting");
|
||||
delay(2000);
|
||||
|
||||
if (ETH.linkUp()){
|
||||
logger.log(0, DEBUG, "Ethernet connected, starting update checker");
|
||||
xTaskCreate(check_update_task, "CheckUpdateTask", 1024 * 8, NULL, 1, NULL);
|
||||
started = true;
|
||||
}
|
||||
xTaskCreate(wifi_task, "WiFiTask", 10000, NULL, 1, NULL);
|
||||
if (!started) {
|
||||
} else {
|
||||
logger.log(0, DEBUG, "Ethernet not connected, starting update checker and WiFi Task");
|
||||
xTaskCreate(wifi_task, "WiFiTask", 10000, NULL, 1, NULL);
|
||||
xTaskCreate(check_update_task, "CheckUpdateTask", 1024 * 8, NULL, 1, NULL);
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
logger.log(0, DEBUG, "Getting time now");
|
||||
// Configure time with a GMT offset and daylight offset in seconds.
|
||||
configTime(3600, 0, "pool.ntp.org");
|
||||
|
||||
// Wait until a valid time is obtained (time > 8 hours in seconds)
|
||||
time_t now = time(NULL);
|
||||
struct tm timeinfo;
|
||||
int retry = 0;
|
||||
while (now < 8 * 3600 && retry < 10) {
|
||||
if(!getLocalTime(&timeinfo)){
|
||||
Serial.println("Failed to obtain time");
|
||||
}
|
||||
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
|
||||
retry++;
|
||||
}
|
||||
|
||||
|
||||
getLocalTime(&timeinfo);
|
||||
|
||||
// Sanity check: Ensure the year is at least 2020.
|
||||
int currentYear = timeinfo.tm_year + 1900; // tm_year is years since 1900
|
||||
if (currentYear < 2020) {
|
||||
logger.log(0, DEBUG, "Time not set properly: ");
|
||||
} else {
|
||||
logger.log(0, DEBUG, "Time is valid: %s", asctime(&timeinfo));
|
||||
}
|
||||
|
||||
// Setup syslog
|
||||
logger.configureSyslog("192.168.6.11", 5514, "esp32");
|
||||
logger.registerSyslog(MYLOG, DEBUG, FAC_LOCAL4, "mylog");
|
||||
logger.registerSyslog(MYLOG, DEBUG, FAC_USER, "waterlevel");
|
||||
logger.log(MYLOG, ERROR, "Here is an error message, error code: %d", 17);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ void read_sensor_task(void* parameter)
|
||||
float bus_voltage = ina_sensor.getBusVoltage();
|
||||
float shunt_voltage = ina_sensor.getShuntVoltage_mV() - zero_value;
|
||||
|
||||
logger.log(0, DEBUG, "RAW Shunt voltage: %F mV", ina_sensor.getShuntVoltage_mV());
|
||||
|
||||
float shunt_current = shunt_voltage / RESISTOR_VALUE;
|
||||
|
||||
// Get values from storage
|
||||
@@ -61,8 +63,8 @@ void read_sensor_task(void* parameter)
|
||||
float min_water_level_mA = 4 + min_water_level_mA_over_zero;
|
||||
float max_water_level_mA = 4 + max_water_level_mA_over_zero;
|
||||
|
||||
// logger.log(0, DEBUG, "max_water_level_mA: %F", max_water_level_mA);
|
||||
// logger.log(0, DEBUG, "min_water_level_mA_over_zero: %F", min_water_level_mA_over_zero);
|
||||
logger.log(0, DEBUG, "max_water_level_mA: %F", max_water_level_mA);
|
||||
logger.log(0, DEBUG, "min_water_level_mA_over_zero: %F", min_water_level_mA_over_zero);
|
||||
|
||||
// Current over the 0 level of the water
|
||||
float shunt_current_over_zero = shunt_current - min_water_level_mA;
|
||||
@@ -82,10 +84,10 @@ void read_sensor_task(void* parameter)
|
||||
active_errors.current_high = shunt_current > 20.2;
|
||||
active_errors.voltage_low = bus_voltage < 23;
|
||||
active_errors.voltage_high = bus_voltage > 25;
|
||||
// logger.log(0, DEBUG, "Shunt current: %F", shunt_current);
|
||||
// logger.log(0, DEBUG, "Shunt voltage: %F", shunt_voltage);
|
||||
// logger.log(0, DEBUG, "Bus voltage: %F", bus_voltage);
|
||||
// logger.log(0, DEBUG, "cm_over_zero: %F", cm_over_zero);
|
||||
logger.log(0, DEBUG, "Shunt current: %F", shunt_current);
|
||||
logger.log(0, DEBUG, "Shunt voltage: %F", shunt_voltage);
|
||||
logger.log(0, DEBUG, "Bus voltage: %F", bus_voltage);
|
||||
logger.log(0, DEBUG, "cm_over_zero: %F", cm_over_zero);
|
||||
|
||||
shunt_data.bus_voltage = bus_voltage;
|
||||
shunt_data.shunt_voltage = shunt_voltage;
|
||||
|
||||
Reference in New Issue
Block a user