Add the sensor readings #1
This commit is contained in:
parent
f6d8abc723
commit
11c8c9a587
4 changed files with 30 additions and 3 deletions
|
@ -4,6 +4,7 @@
|
|||
#define SENSOR_HUMIDITY 1
|
||||
#define SENSOR_LIGHT 2
|
||||
#define SENSOR_WINDSPEED 3
|
||||
#define SENSOR_PRESSURE 4
|
||||
|
||||
#define UPDATE_INTERVAL 4
|
||||
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <ESP8266Influxdb.h>
|
||||
#include <Adafruit_Sensor.h> // Adafruit Unified Sensor
|
||||
#include <Adafruit_APDS9960.h> // https://github.com/adafruit/Adafruit_APDS9960
|
||||
#include <Adafruit_BME280.h> // https://github.com/adafruit/Adafruit_BME280_Library
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
@ -28,6 +31,8 @@ float currentSensorData[4] = {0.0, 0.0, 0.0, 0.0};
|
|||
|
||||
WiFiManager wifiManager;
|
||||
Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
|
||||
Adafruit_APDS9960 apds;
|
||||
Adafruit_BME280 bme;
|
||||
|
||||
void setup() {
|
||||
#ifdef DEBUG
|
||||
|
@ -55,6 +60,13 @@ void setup() {
|
|||
// Open the InfluxDB session
|
||||
influxdb.opendb(INFLUXDB_DB, INFLUXDB_USER, INFLUXDB_PASS);
|
||||
delay(2000);
|
||||
|
||||
// Initialize and configure the sensors
|
||||
apds.begin();
|
||||
apds.enableColor(true);
|
||||
bme.begin();
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -64,6 +76,7 @@ void loop() {
|
|||
currentSensorData[SENSOR_HUMIDITY] = fetchHumidity();
|
||||
currentSensorData[SENSOR_LIGHT] = fetchLight();
|
||||
currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed();
|
||||
currentSensorData[SENSOR_PRESSURE] = fetchPressure();
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.println("");
|
||||
|
@ -72,6 +85,7 @@ void loop() {
|
|||
Serial.println("Humidity: " + String(currentSensorData[SENSOR_HUMIDITY]) + "%");
|
||||
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");
|
||||
#endif
|
||||
|
||||
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
||||
|
|
|
@ -3,4 +3,5 @@ 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]));
|
||||
influxdb.write("weather,device=" + device + " pressure=" + String(sensorValues[SENSOR_PRESSURE]));
|
||||
}
|
||||
|
|
|
@ -2,15 +2,26 @@ int anemometerRotations = 0;
|
|||
unsigned long currentTime = 0;
|
||||
|
||||
float fetchTemperature() {
|
||||
return 22.5; // XXX: Dummy value
|
||||
return bme.readTemperature();
|
||||
}
|
||||
|
||||
float fetchPressure() {
|
||||
return bme.readPressure() / 100.0F;
|
||||
}
|
||||
|
||||
float fetchHumidity() {
|
||||
return 60.0; // XXX: Dummy value
|
||||
return bme.readHumidity();
|
||||
}
|
||||
|
||||
float fetchLight() {
|
||||
return 2000.4; // XXX: Dummy value
|
||||
uint16_t red, green, blue, white;
|
||||
|
||||
while(!apds.colorDataReady()){
|
||||
delay(5);
|
||||
}
|
||||
|
||||
apds.getColorData(&red, &green, &blue, &white);
|
||||
return white;
|
||||
}
|
||||
|
||||
void anemometerInterrupt() {
|
||||
|
|
Loading…
Reference in a new issue