Implement the anemometer sensor
This commit is contained in:
parent
def78c8f92
commit
f5042a3ec4
3 changed files with 35 additions and 15 deletions
|
@ -1,13 +1,11 @@
|
|||
#define DEBUG
|
||||
|
||||
#define WIFI_PASSWORD "xxx"
|
||||
#define WIFI_SSID "xxx"
|
||||
|
||||
#define SENSOR_TEMPERATURE 0
|
||||
#define SENSOR_HUMIDITY 1
|
||||
#define SENSOR_LIGHT 2
|
||||
#define SENSOR_WINDSPEED 3
|
||||
|
||||
#define UPDATE_INTERVAL 4
|
||||
#define STATUS_LED BUILTIN_LED
|
||||
|
||||
|
||||
#define STATUS_LED_PIN BUILTIN_LED
|
||||
#define ANEMOMETER_PIN D4
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
* - https://github.com/marvinroger/homie-esp8266
|
||||
*/
|
||||
|
||||
float currentSensorData[3] = {0.0, 0.0, 0.0};
|
||||
float currentSensorData[4] = {0.0, 0.0, 0.0, 0.0};
|
||||
|
||||
void connectToWiFi() {
|
||||
}
|
||||
|
@ -29,17 +29,19 @@ bool checkWiFiConnection() {
|
|||
return true;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
void setup() {
|
||||
#ifdef DEBUG
|
||||
Serial.begin(115200);
|
||||
#endif
|
||||
|
||||
pinMode(STATUS_LED, OUTPUT);
|
||||
pinMode(STATUS_LED_PIN, OUTPUT);
|
||||
pinMode(ANEMOMETER_PIN, INPUT_PULLUP);
|
||||
|
||||
connectToWiFi();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
digitalWrite(STATUS_LED, LOW);
|
||||
digitalWrite(STATUS_LED_PIN, LOW);
|
||||
|
||||
while (!checkWiFiConnection()) {
|
||||
connectToWiFi();
|
||||
|
@ -49,13 +51,15 @@ void loop() {
|
|||
currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature();
|
||||
currentSensorData[SENSOR_HUMIDITY] = fetchHumidity();
|
||||
currentSensorData[SENSOR_LIGHT] = fetchLight();
|
||||
currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed();
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.println("");
|
||||
Serial.println("Current readings:");
|
||||
Serial.println("Temperature: " + String(currentSensorData[SENSOR_TEMPERATURE]));
|
||||
Serial.println("Humidity: " + String(currentSensorData[SENSOR_HUMIDITY]));
|
||||
Serial.println("Light: " + String(currentSensorData[SENSOR_LIGHT]));
|
||||
Serial.println("Temperature: " + String(currentSensorData[SENSOR_TEMPERATURE]) + " °C");
|
||||
Serial.println("Humidity: " + String(currentSensorData[SENSOR_HUMIDITY]) + "%");
|
||||
Serial.println("Light: " + String(currentSensorData[SENSOR_LIGHT]) + " Lumen");
|
||||
Serial.println("Windspeed: " + String(currentSensorData[SENSOR_WINDSPEED]) + " Km/h");
|
||||
#endif
|
||||
|
||||
pushToInfluxDB(currentSensorData);
|
||||
|
|
|
@ -1,13 +1,31 @@
|
|||
int anemometerRotations = 0;
|
||||
unsigned long currentTime = 0;
|
||||
|
||||
float fetchTemperature() {
|
||||
return 22.5;
|
||||
return 22.5; // XXX: Dummy value
|
||||
}
|
||||
|
||||
float fetchHumidity() {
|
||||
return 60.0;
|
||||
return 60.0; // XXX: Dummy value
|
||||
}
|
||||
|
||||
float fetchLight() {
|
||||
return 2000.4;
|
||||
return 2000.4; // XXX: Dummy value
|
||||
}
|
||||
|
||||
void anemometerInterrupt() {
|
||||
anemometerRotations++;
|
||||
}
|
||||
|
||||
float fetchWindspeed() {
|
||||
anemometerRotations = 0;
|
||||
currentTime = millis();
|
||||
int interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN);
|
||||
|
||||
attachInterrupt(interruptNumber, anemometerInterrupt, RISING);
|
||||
delay(1000 * 5);
|
||||
detachInterrupt(interruptNumber);
|
||||
|
||||
return (float)anemometerRotations / 5.0 * 2.4;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue