Skip to content
Snippets Groups Projects
Verified Commit d7358bb8 authored by Jonas Leder's avatar Jonas Leder
Browse files

move bat voltage check to startup

parent a3bc1675
No related branches found
No related tags found
No related merge requests found
Pipeline #9916 passed
...@@ -15,10 +15,22 @@ esp_adc_cal_characteristics_t *adc_chars; ...@@ -15,10 +15,22 @@ esp_adc_cal_characteristics_t *adc_chars;
char DEVEUI[16]; char DEVEUI[16];
float getBatVoltage(); float getBatVoltage();
void sleep();
float batVoltage;
void setup() void setup()
{ {
(String(ESP.getEfuseMac(), HEX) + "0000").toCharArray(DEVEUI, 17); (String(ESP.getEfuseMac(), HEX) + "0000").toCharArray(DEVEUI, 17);
batVoltage = getBatVoltage();
if(BAT_MIN_VOLTAGE > batVoltage)
{
#ifdef SERIAL_OUTPUT
Serial.println("Battery voltage too low, going to sleep again");
Serial.flush();
#endif
sleep();
}
pinMode(Vext, OUTPUT); pinMode(Vext, OUTPUT);
digitalWrite(Vext, LOW); // enable power to DS18B20 digitalWrite(Vext, LOW); // enable power to DS18B20
...@@ -43,7 +55,7 @@ void setup() ...@@ -43,7 +55,7 @@ void setup()
uint8_t txBuffer[14]; uint8_t txBuffer[14];
txBuffer[0] = (rawTemp >> 8) & 0xFF; txBuffer[0] = (rawTemp >> 8) & 0xFF;
txBuffer[1] = rawTemp & 0xFF; txBuffer[1] = rawTemp & 0xFF;
txBuffer[2] = (getBatVoltage() * 100) - 200; txBuffer[2] = (batVoltage * 100) - 200;
#ifdef SERIAL_OUTPUT #ifdef SERIAL_OUTPUT
Serial.print("Raw Temperature: "); Serial.print("Raw Temperature: ");
...@@ -56,25 +68,12 @@ void setup() ...@@ -56,25 +68,12 @@ void setup()
#ifdef SERIAL_OUTPUT #ifdef SERIAL_OUTPUT
Serial.print("Battery voltage: "); Serial.print("Battery voltage: ");
Serial.println(getBatVoltage()); Serial.println(batVoltage);
Serial.println("Going to sleep"); Serial.println("Going to sleep");
Serial.flush(); Serial.flush();
#endif #endif
sleep();
if(BAT_MIN_VOLTAGE < getBatVoltage())
{
uint64_t sleepTime = SLEEP_TIME * uS_TO_S_FACTOR;
esp_sleep_enable_timer_wakeup(sleepTime);
}
#ifdef SERIAL_OUTPUT
else
{
Serial.println("Battery voltage too low, going to permanent deep sleep");
}
#endif
esp_deep_sleep_start();
} }
float getBatVoltage() { float getBatVoltage() {
...@@ -86,6 +85,12 @@ float getBatVoltage() { ...@@ -86,6 +85,12 @@ float getBatVoltage() {
return adcVal / 4095.0 * BAT_FACTOR; return adcVal / 4095.0 * BAT_FACTOR;
} }
void sleep() {
uint64_t sleepTime = SLEEP_TIME * uS_TO_S_FACTOR;
esp_sleep_enable_timer_wakeup(sleepTime);
esp_deep_sleep_start();
}
void loop() void loop()
{ {
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment