measurement of vcc, calculation of battery lifetime
This commit is contained in:
parent
5a962d8835
commit
b577f3992a
BIN
Batterielaufzeit.xlsx
Normal file
BIN
Batterielaufzeit.xlsx
Normal file
Binary file not shown.
@ -1,4 +1,5 @@
|
||||
#define ESP8266
|
||||
#define MQTT_MAX_PACKET_SIZE 256
|
||||
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
@ -8,6 +9,10 @@
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
|
||||
ADC_MODE(ADC_VCC);
|
||||
|
||||
|
||||
|
||||
// #define DEBUG
|
||||
#define SLEEP
|
||||
|
||||
@ -49,6 +54,8 @@ void setup() {
|
||||
Serial.println("Starting ...");
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
setup_wifi();
|
||||
client.setServer(mqttServer, mqttPort);
|
||||
|
||||
@ -143,13 +150,23 @@ void read_thermometer() {
|
||||
int16_t t1 = (int)t;
|
||||
int16_t t2 = (int)((t - t1)*100);
|
||||
|
||||
uint32_t duration = millis() - startTime;
|
||||
|
||||
uint16_t vcc = ESP.getVcc();
|
||||
#ifdef DEBUG
|
||||
Serial.print(vcc);
|
||||
Serial.println();
|
||||
#endif
|
||||
|
||||
|
||||
uint32_t duration = millis() - startTime;
|
||||
|
||||
//char topic[128];
|
||||
//snprintf(topic, 127, "IoT/espThermometer2/%s/measurement", WiFi.macAddress().c_str());
|
||||
char payload[128];
|
||||
snprintf(payload, 127, "%d.%d %ld", t1, t2, duration);
|
||||
snprintf(payload, 127, "%s %d.%d %ld %ld", clientId, t1, t2, vcc, duration);
|
||||
#ifdef DEBUG
|
||||
Serial.println(payload);
|
||||
#endif
|
||||
client.publish(topic, payload, true);
|
||||
|
||||
|
||||
@ -165,10 +182,13 @@ void loop() {
|
||||
|
||||
read_thermometer();
|
||||
|
||||
|
||||
|
||||
#ifdef SLEEP
|
||||
#ifdef DEBUG
|
||||
Serial.println("Sleeping");
|
||||
#endif
|
||||
client.disconnect();
|
||||
ESP.deepSleep(sleepTime * 1000000);
|
||||
#endif
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user