Added the battery voltage code.
This commit is contained in:
parent
0f89167450
commit
c16d431c89
4 changed files with 16 additions and 6 deletions
|
@ -6,6 +6,7 @@
|
|||
#define SENSOR_LIGHT 2
|
||||
#define SENSOR_WINDSPEED 3
|
||||
#define SENSOR_PRESSURE 4
|
||||
#define SENSOR_BAT_VOLTAGE 5
|
||||
|
||||
#define UPDATE_SENSOR_INTERVAL_S 10
|
||||
#define UPDATE_WEBSERVER_INTVERVAL_S 1
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
//*************************************************************************//
|
||||
|
||||
float currentSensorData[5] = {0.0, 0.0, 0.0, 0.0, 0.0};
|
||||
float currentSensorData[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
||||
|
||||
uint16_t update_sensor_cnt = 0;
|
||||
uint16_t update_webserver_cnt = 0;
|
||||
|
@ -56,6 +56,7 @@ void setup() {
|
|||
// Pin settings
|
||||
pinMode(STATUS_LED_PIN, OUTPUT);
|
||||
pinMode(ANEMOMETER_PIN, INPUT_PULLUP);
|
||||
pinMode(A0, INPUT);
|
||||
|
||||
// Establish WiFi connection
|
||||
String wifiName = "oko-weather-" + String(ESP.getChipId());
|
||||
|
@ -113,6 +114,7 @@ void loop() {
|
|||
currentSensorData[SENSOR_LIGHT] = fetchLight();
|
||||
currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed();
|
||||
currentSensorData[SENSOR_PRESSURE] = fetchPressure();
|
||||
currentSensorData[SENSOR_BAT_VOLTAGE] = getBatteryVoltage();
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.println("");
|
||||
|
@ -122,6 +124,7 @@ void loop() {
|
|||
Serial.println("Light: " + String(currentSensorData[SENSOR_LIGHT]) + " Lumen");
|
||||
Serial.println("Windspeed: " + String(currentSensorData[SENSOR_WINDSPEED]) + " km/h");
|
||||
Serial.println("Pressure: " + String(currentSensorData[SENSOR_PRESSURE]) + " hPa");
|
||||
Serial.println("Bat Voltage: " + String(currentSensorData[SENSOR_BAT_VOLTAGE]) + " V");
|
||||
#endif
|
||||
|
||||
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
||||
|
@ -136,4 +139,4 @@ void loop() {
|
|||
}
|
||||
|
||||
//*************************************************************************//
|
||||
|
||||
|
||||
|
|
|
@ -5,10 +5,8 @@ void pushToInfluxDB(String device, float sensorValues[]) {
|
|||
influxdb.write("weather,device=" + device + " humidity=" + String(sensorValues[SENSOR_HUMIDITY]));
|
||||
influxdb.write("weather,device=" + device + " light=" + String(sensorValues[SENSOR_LIGHT]));
|
||||
influxdb.write("weather,device=" + device + " windspeed=" + String(sensorValues[SENSOR_WINDSPEED]));
|
||||
|
||||
int tmp = influxdb.write("weather,device=" + device + " pressure=" + String(sensorValues[SENSOR_PRESSURE]));
|
||||
|
||||
Serial.println("Opendb status: " + String(tmp));
|
||||
influxdb.write("weather,device=" + device + " pressure=" + String(sensorValues[SENSOR_PRESSURE]));
|
||||
influxdb.write("weather,device=" + device + " batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE]));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -45,4 +45,12 @@ float fetchWindspeed() {
|
|||
|
||||
return (float)anemometerRotations / 5.0 * 2.4;
|
||||
}
|
||||
|
||||
// Copied from https://arduinodiy.wordpress.com/2016/12/25/monitoring-lipo-battery-voltage-with-wemos-d1-minibattery-shield-and-thingspeak/
|
||||
float getBatteryVoltage() {
|
||||
uint16_t raw = analogRead(A0);
|
||||
float volt = raw / 1023.0;
|
||||
volt = volt * 4.2;
|
||||
return volt;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue