Browse Source

measure battery voltage

main
Hendrik Langer 5 years ago
parent
commit
acecb46a20
  1. 17
      src/main.cpp

17
src/main.cpp

@ -69,6 +69,7 @@ struct __attribute__((packed)) sensor_readings_t {
float uvb = NAN;
float temperature_max = NAN; // °C
float temperature_min = NAN; // °C
int battery = 0;
uint32_t lastUpdate = 0;
} sensor_readings;
@ -180,6 +181,8 @@ void getSensorMeasurements() {
}
}
sensor_readings.battery = analogRead(_VBAT);
sensor_readings.lastUpdate = millis();
}
@ -458,6 +461,8 @@ void printValues() {
Serial.println(sensor_readings.pm10);
}
Serial.print("Battery: "); Serial.println(sensor_readings.battery);
Serial.print("Free HEAP: "); Serial.println(ESP.getFreeHeap());
}
@ -512,6 +517,12 @@ void sendValues() {
delay(10);
}
{
String topic_battery = String("thomas/sensor/") + ota.getMAC() + String("/battery");
mqtt.publish(topic_battery.c_str(), (sensor_readings.battery/4096.0)*2*3.42, "%.2f");
delay(10);
}
}
/**
@ -529,6 +540,12 @@ void setup()
// initialize LED digital pin as an output.
pinMode(LED_BUILTIN, OUTPUT);
pinMode(_VBAT, INPUT);
analogReadResolution(12);
analogSetAttenuation(ADC_11db);
adcAttachPin(_VBAT);
adcStart(_VBAT);
// initialize e-paper display
SPI.begin(18, 19, 23, TFT_CS);
display.init();

Loading…
Cancel
Save