Errors - OilSlick/coffee_tree_monitor GitHub Wiki

Logging Errors To A File

There is minimal error logging configured in the sensor already but I plan to expand error logging and handling. One of the files saved to the SD card is error.txt. The following errors will be recorded to that file:

  • "WiFi connection failed" after 60 failed attempts to connect (~30 seconds)
  • "Adafruit IO connection failed" after 60 failed attempts to connect (~30 seconds)
  • "BMP180 Sensor Error: Failure to initialize" if BMP180 failed to initialize
  • "TSL2561 is not responding at address: XX (0xXX)" Displays the I2C address attempted
  • "TSL2561 Sensor Error: lux above sensor max threshold" if TSL2561 sensor exceeds its max threshold

Note: I've found that the current code doesn't consistently detect a failure to initialize the TSL2561, even if the sensor is not physically connected to the circuit. Therefore I check the sensor's I2C address using the following code. Depending on the error returned, I can predictably determine up/down status of the sensor.

Wire.beginTransmission(KNOWN-SENSOR-ADDRESS);
I2Cerror = Wire.endTransmission();

Logging Errors To Serial Console

When the Feather is connected serially to a laptop, the following errors can be sent to the console:

  • "No BMP180 detected ... Check your wiring or I2C address" if BMP180 failed to initialize
  • "BMP180 sensor error" if the unit is unable to read data from the sensor (currently only pressure data)
  • "TSL2561 is not responding at address: " if TSL2561 failed to initialize (see note above)
  • "SD card initialization failed" if the SD card adapter failed to initialize
  • "Error opening data log file" if the main data log file fails to open (it will create it gracefully if it doesn't exist, so this error may indicate corruption, a full SD card, etc)
  • "Error opening error log file" if the error log file fails to open (it will create the file gracefully if it doesn't exist, so this error may indicate data corruption, a full SD card, etc)
  • "Could not connect to WiFi" if the connection to WiFi fails

Logging Errors To Adafruit IO

Some errors are also written to Adafruit IO. This becomes very handy as there is an IFTTT applet available).

  • "BMP180 is not responding"
  • "TSL2561 is not responding"

Error Handling

To prevent a permanent hang, the following error conditions are aknowledged (logged) and then avoided. These conditions are volatile — if the unit is reset it will return to default operation for at least one loop.

  • If the BMP180 fails, it will not be polled in the future
  • If the TSL2561 fails, it will not be polled in the future (see note above)
  • If WiFi connection fails, no connection attempt will be made to Adafruit IO
  • If the initial connection to Adafruit IO fails, attempts won't be made to write data online

The following conditions aren't necessarily errors but are deviations that should be documented:

  • If the TSL2561 does not register a value, a "0" will be logged (I've found empty values occur at night)