Browse Source

working without light sensor

Thomas Kopp 1 year ago
parent
commit
449654c250
2 changed files with 14 additions and 6 deletions
  1. 12
    4
      firmware/firmware.ino
  2. 2
    2
      firmware/sensors.ino

+ 12
- 4
firmware/firmware.ino View File

@@ -63,6 +63,8 @@ Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
63 63
 Adafruit_APDS9960 apds;
64 64
 Adafruit_BME280 bme;
65 65
 
66
+bool apds_connected = false;
67
+
66 68
 #ifdef WEBUPDATER_FEATURE
67 69
 String localIP = "127.0.0.1";
68 70
 #endif
@@ -116,9 +118,13 @@ void setup() {
116 118
 
117 119
   // Initialize and configure the sensors
118 120
   //Light Sensor
119
-  apds.begin();
120
-  apds.enableColor(true);
121
-
121
+  if (apds.begin()) {
122
+    apds_connected = true;
123
+    apds.enableColor(true);
124
+  }
125
+#ifdef DEBUG2
126
+  Serial.println("Connected!");
127
+#endif
122 128
   //Temperature + pressure
123 129
   bool status = bme.begin(BME_ADDRESS);
124 130
   if (!status) {
@@ -229,7 +235,9 @@ void _loop() {
229 235
 #endif
230 236
     currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature();
231 237
     currentSensorData[SENSOR_HUMIDITY]    = fetchHumidity();
232
-    currentSensorData[SENSOR_LIGHT]       = fetchLight();
238
+    if (apds_connected) {
239
+      currentSensorData[SENSOR_LIGHT]       = fetchLight();
240
+    }
233 241
     currentSensorData[SENSOR_PRESSURE]    = fetchPressure();
234 242
 #ifdef BATTERY_POWERED
235 243
     currentSensorData[SENSOR_BAT_VOLTAGE]    = getBatteryVoltage();

+ 2
- 2
firmware/sensors.ino View File

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

Loading…
Cancel
Save