working without light sensor

This commit is contained in:
Thomas Kopp 2019-03-31 17:01:04 +02:00
parent b0ec86890d
commit 449654c250
2 changed files with 14 additions and 6 deletions

View File

@ -63,6 +63,8 @@ Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
Adafruit_APDS9960 apds;
Adafruit_BME280 bme;
bool apds_connected = false;
#ifdef WEBUPDATER_FEATURE
String localIP = "127.0.0.1";
#endif
@ -116,9 +118,13 @@ void setup() {
// Initialize and configure the sensors
//Light Sensor
apds.begin();
apds.enableColor(true);
if (apds.begin()) {
apds_connected = true;
apds.enableColor(true);
}
#ifdef DEBUG2
Serial.println("Connected!");
#endif
//Temperature + pressure
bool status = bme.begin(BME_ADDRESS);
if (!status) {
@ -229,7 +235,9 @@ void _loop() {
#endif
currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature();
currentSensorData[SENSOR_HUMIDITY] = fetchHumidity();
currentSensorData[SENSOR_LIGHT] = fetchLight();
if (apds_connected) {
currentSensorData[SENSOR_LIGHT] = fetchLight();
}
currentSensorData[SENSOR_PRESSURE] = fetchPressure();
#ifdef BATTERY_POWERED
currentSensorData[SENSOR_BAT_VOLTAGE] = getBatteryVoltage();

View File

@ -24,7 +24,7 @@ float fetchLight() {
while(!apds.colorDataReady()) {
delay(5);
}
apds.getColorData(&red, &green, &blue, &white);
//calculate lux
lux = apds.calculateLux(red, green, blue);
@ -75,4 +75,4 @@ float isBatCharging() {
}
#endif