diff --git a/sec.h b/sec.h index f4a7e58..4de11b2 100644 --- a/sec.h +++ b/sec.h @@ -50,6 +50,13 @@ const char mainTopic[20] = "MainTopic/"; //=========================================== //#define USE_EEPROM +//=========================================== +//BME280 altitude offsets (set by user) +//=========================================== +#define ALTITUDE_OFFSET_IMPERIAL 5.58 +#define ALTITUDE_OFFSET_METRIC 142.6 + + //=========================================== //BH1750 Enable //=========================================== @@ -77,6 +84,7 @@ const int UpdateIntervalSeconds = 5 * 60; //Sleep timer (60s) testing //=========================================== //batteryCalFactor = measured battery voltage/ADC reading #define batteryCalFactor .0011804 +#define batteryLowVoltage 3.3 //=========================================== //Timezone information diff --git a/sensors.ino b/sensors.ino index 79c46be..7b6f215 100644 --- a/sensors.ino +++ b/sensors.ino @@ -55,7 +55,7 @@ void readBattery (struct sensorData *environment) environment->batteryVoltage = environment->batteryADC * batteryCalFactor; MonPrintf("Battery digital ADC :%i voltage: %6.2f\n", environment->batteryADC, environment->batteryVoltage); //check for low battery situation - if (environment->batteryVoltage < 3.78) + if (environment->batteryVoltage < batteryLowVoltage) { lowBattery = true; } @@ -74,9 +74,8 @@ void checkBatteryVoltage (void) float voltage; adc = analogRead(VOLT_PIN); voltage = adc * batteryCalFactor; - //MonPrintf("Battery digital ADC :%i voltage: %6.2f\n", environment->batteryADC, environment->batteryVoltage); //check for low battery situation - if (voltage < 3.78) + if (voltage < batteryLowVoltage) { lowBattery = true; } @@ -126,8 +125,10 @@ void readBME(struct sensorData *environment) { #ifndef METRIC bme.read(environment->barometricPressure, environment->BMEtemperature, environment->humidity, BME280::TempUnit_Fahrenheit, BME280::PresUnit_inHg); + environment->barometricPressure += ALTITUDE_OFFSET_IMPERIAL; #else bme.read(environment->barometricPressure, environment->BMEtemperature, environment->humidity, BME280::TempUnit_Celsius, BME280::PresUnit_Pa); + environment->barometricPressure += ALTITUDE_OFFSET_METRIC; #endif } @@ -168,4 +169,12 @@ void readESPCoreTemp(struct sensorData *environment) environment->coreF = coreF; environment->coreC = coreC; -} \ No newline at end of file +} + + +void printADCLCD( void) +{ + int adc; + adc = analogRead(VOLT_PIN); + display.printf("ADC: %i\n", adc); +} diff --git a/time.ino b/time.ino index f1dc557..0359f0e 100644 --- a/time.ino +++ b/time.ino @@ -5,7 +5,7 @@ struct tm timeinfo; //======================================================================= void printLocalTime() { - if (!getLocalTime(&timeinfo)) + if (!getLocalTime(&timeinfo)) { MonPrintf("Failed to obtain time\n"); return; @@ -13,6 +13,16 @@ void printLocalTime() Serial.printf("Date:%02i %02i %i Time: %02i:%02i:%02i\n", timeinfo.tm_mday, timeinfo.tm_mon + 1, timeinfo.tm_year + 1900, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec); } +void printLocalTimeLCD(void) +{ + if (!getLocalTime(&timeinfo)) + { + MonPrintf("Failed to obtain time\n"); + return; + } + display.printf("Date:%02i %02i %i\nTime: %02i:%02i:%02i\n", timeinfo.tm_mday, timeinfo.tm_mon + 1, timeinfo.tm_year + 1900, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec); +} + //======================================================================= // printTimeNextWake: diagnostic routine to print next wake time //======================================================================= diff --git a/weather.ino b/weather.ino index c3c1ae7..55d4257 100644 --- a/weather.ino +++ b/weather.ino @@ -4,19 +4,21 @@ // //Supporting the following project: https://www.instructables.com/Solar-Powered-WiFi-Weather-Station-V30/ -//version 1.3.1 -#define VERSION "1.3.1" +#define VERSION "1.3.2" //============================================= // Changelog //============================================= -/* - * v1.3.1 - * 1. Corrects missing quotes on #define VERSION statement - * 2. max retry if 15 connect attempts added and then we bail on WiFi connect. This prevents us from hitting the WDT limit and rebooting - * - * - * v1.3 supports 24h rainfall data, not 23h +/* + * v1.3.2 + * 1. I2C OLED diagnostics added (if needed) + * 2. + v1.3.1 + 1. Corrects missing quotes on #define VERSION statement + 2. max retry if 15 connect attempts added and then we bail on WiFi connect. This prevents us from hitting the WDT limit and rebooting + + + v1.3 supports 24h rainfall data, not 23h supports current 60 min rainfall, not current "hour" that looses data at top of the hour. @@ -70,6 +72,12 @@ #include #include #include +//OLED diagnostics board +#include +#include + +#define OLED_RESET 4 +Adafruit_SSD1306 display(OLED_RESET); //=========================================== // Defines @@ -201,12 +209,26 @@ void setup() Serial.begin(115200); delay(25); + + + //Title message MonPrintf("\nWeather station - Deep sleep version.\n"); MonPrintf("Version %s\n\n", VERSION); BlinkLED(1); bootCount++; + display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64) + display.clearDisplay(); + display.setTextSize(1); + display.setTextColor(WHITE); + printLocalTimeLCD(); + printADCLCD(); + display.printf("SSID: %s\n", ssid); + display.print("BOOT: "); + display.println(bootCount); + display.display(); + updateWake(); wakeup_reason(); if (WiFiEnable) @@ -220,7 +242,7 @@ void setup() configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); printLocalTime(); printTimeNextWake(); - processSensorUpdates(); + processSensorUpdates(); WiFi.disconnect(); esp_wifi_stop(); } @@ -233,6 +255,7 @@ void setup() } //pet the dog! esp_task_wdt_reset(); + BlinkLED(2); sleepyTime(UpdateIntervalModified); } @@ -278,6 +301,9 @@ void processSensorUpdates(void) { SendDataMQTT(&environment); } + display.printf("Temp: %4.1f F\n", environment.temperatureF); + display.printf("Pressure: %4.1f inHg\n", environment.barometricPressure); + display.display(); } //=========================================================== @@ -370,7 +396,7 @@ void BlinkLED(int count) delay(150); //LED OFF digitalWrite(LED_BUILTIN, LOW); - delay(500); + delay(350); } }