Browse Source

battery voltage

main
Hendrik Langer 7 years ago
parent
commit
a9d8fbc466
  1. 1
      src/hardware.h
  2. 30
      src/main.cpp

1
src/hardware.h

@ -17,6 +17,7 @@ static constexpr uint8_t ext_wakeup_pin_1 = 0;
static constexpr uint8_t ext_wakeup_pin_2 = 0;
static constexpr uint32_t secondsToSleep = 30*60;
static constexpr int batteryLimit = 2800;
/* Wiring (Heltec OLED Lora)

30
src/main.cpp

@ -34,6 +34,10 @@
#include "screen.h"
#include "led.h"
extern "C" {
int rom_phy_get_vdd33();
}
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 15, /* data=*/ 4);
@ -42,6 +46,7 @@ char weatherStr[32];
RTC_DATA_ATTR static int boot_count = 0;
RTC_DATA_ATTR struct tm alarmTime;
RTC_DATA_ATTR bool alarmArmed = false;
RTC_DATA_ATTR bool displaySleep = true;
//Create a new Basecamp instance called iot
Basecamp iot;
@ -107,6 +112,9 @@ void setup() {
if (timeinfo.tm_year < (2016 - 1900)) {
// time not set
}
strftime(timeStr, sizeof(timeStr), "%H:%M", &timeinfo);
char strftime_buf[64];
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
Serial.print("Current time: "); Serial.println(strftime_buf);
@ -117,7 +125,7 @@ void setup() {
strftime(strftime_buf, sizeof(strftime_buf), "%c", &alarmTime);
Serial.print(" Alarm time: "); Serial.println(strftime_buf);
if (-seconds > secondsToSleep) suspend();
if (!alarmArmed || -seconds > secondsToSleep) suspend();
else if (-seconds > 5*60) suspend(5*60);
}
@ -227,6 +235,16 @@ void suspend(uint32_t secondsToSleep) {
//
////esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); // power down all peripherals
if (!displaySleep) {
u8g2.begin();
u8g2.clearBuffer();
u8g2.sendBuffer();
u8g2.setFont(u8g2_font_inb19_mf);
u8g2.drawStr(0, 20, timeStr);
// ToDo: set rtc gpio resistors
esp_sleep_enable_timer_wakeup(1000000LL * 60);
}
//send the ESP into deep sleep
esp_deep_sleep_start();
}
@ -235,8 +253,8 @@ void suspend() {
time_t now;
time(&now);
double seconds = difftime(now, mktime(&alarmTime));
if (-seconds > secondsToSleep) suspend(secondsToSleep);
else if (-seconds > 5*60) suspend(5*60);
if (-seconds > secondsToSleep || !alarmArmed) suspend(secondsToSleep);
else suspend(5*60);
}
void setAlarmTime(struct tm time) {
@ -309,8 +327,12 @@ void loop()
if (alarmArmed && seconds >= -2*5*60) stayAwake = true;
if (!mp3.playing && millis() - lastButtonPress >= 60*1000 && !stayAwake) suspend();
int voltage = rom_phy_get_vdd33();
Serial.printf("voltage: %d\n", voltage);
strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &timeinfo);
sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure());
sprintf(weatherStr, "%.1f°C %.1f%% %dmV", bme280.readTemperature(), bme280.readHumidity(), voltage);
// sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure());
Serial.print("Free Heap: ");
Serial.println(ESP.getFreeHeap());

Loading…
Cancel
Save