First fully working implementation. But the measured wind speed has to be verified. Added some links for documentation.
This commit is contained in:
commit
60561224d4
6 changed files with 87 additions and 77 deletions
BIN
doc/wemos-d1-mini-shematics.jpg
Normal file
BIN
doc/wemos-d1-mini-shematics.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 120 KiB |
BIN
doc/wemos_esp8266_pinout.png
Normal file
BIN
doc/wemos_esp8266_pinout.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 121 KiB |
|
@ -1,4 +1,4 @@
|
||||||
#define DEBUG
|
#define DEBUG 1
|
||||||
|
|
||||||
#define SENSOR_TEMPERATURE 0
|
#define SENSOR_TEMPERATURE 0
|
||||||
#define SENSOR_HUMIDITY 1
|
#define SENSOR_HUMIDITY 1
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
#define UPDATE_INTERVAL 4
|
#define UPDATE_INTERVAL 4
|
||||||
|
|
||||||
#define STATUS_LED_PIN BUILTIN_LED
|
#define STATUS_LED_PIN BUILTIN_LED
|
||||||
#define ANEMOMETER_PIN D4
|
#define ANEMOMETER_PIN D6
|
||||||
|
|
||||||
#define BME_SCK 13
|
#define BME_SCK 13
|
||||||
#define BME_MISO 12
|
#define BME_MISO 12
|
||||||
|
@ -26,5 +26,5 @@ const char *INFLUXDB_DB = "weatherstation";
|
||||||
const char *INFLUXDB_USER = "oko";
|
const char *INFLUXDB_USER = "oko";
|
||||||
const char *INFLUXDB_PASS = "de1873a0d2f8f21f17cf4d8db4f65c59";
|
const char *INFLUXDB_PASS = "de1873a0d2f8f21f17cf4d8db4f65c59";
|
||||||
|
|
||||||
String DEVICE_NAME = "aaron";
|
String DEVICE_NAME = "klaute";
|
||||||
|
|
||||||
|
|
|
@ -2,31 +2,31 @@
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <DNSServer.h>
|
#include <DNSServer.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
#include <WiFiManager.h>
|
#include <WiFiManager.h> // WiFiManager
|
||||||
#include <ESP8266Influxdb.h> // https://github.com/hwwong/ESP8266Influxdb auchecken und code+header in das firmware verzeichnis kopieren
|
#include <ESP8266Influxdb.h> // https://github.com/hwwong/ESP8266Influxdb auchecken und den ordner in das arduino\library verzeichnis kopieren
|
||||||
#include <Adafruit_Sensor.h> // Adafruit Unified Sensor
|
#include <Adafruit_Sensor.h> // PAckage Adafruit Unified Sensor
|
||||||
#include <Adafruit_APDS9960.h> // https://github.com/adafruit/Adafruit_APDS9960
|
#include <Adafruit_APDS9960.h> // Adafruit APDS9960 - https://www.makerfabs.com/index.php?route=product/product&product_id=281
|
||||||
#include <Adafruit_BME280.h> // https://github.com/adafruit/Adafruit_BME280_Library
|
#include <Adafruit_BME280.h> // BME280 - https://www.roboter-bausatz.de/1704/bmp280-barometer-luftdrucksensor?gclid=EAIaIQobChMIlpumj8Hp2wIVFWYbCh01PgmFEAQYAyABEgIwBvD_BwE
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whishlist:
|
Whishlist:
|
||||||
* - Webserver for /metrics endpoint (Prometheus)
|
- Webserver for /metrics endpoint (Prometheus)
|
||||||
* - Show current sensor values over simple webpage
|
- Show current sensor values over simple webpage
|
||||||
* - Push sensor values to various 3rd party services (https://openweathermap.org/)
|
- Push sensor values to various 3rd party services (https://openweathermap.org/)
|
||||||
* - MQTT?
|
- MQTT?
|
||||||
*
|
|
||||||
* - Buffer sensor values if there is no WIFI connection
|
|
||||||
* - Configure weather station over http webinterface
|
|
||||||
* - OTA firmware update
|
|
||||||
*
|
|
||||||
* TODO:
|
|
||||||
* - https://sminghub.github.io/Sming/about/
|
|
||||||
* - https://github.com/marvinroger/homie-esp8266
|
|
||||||
*/
|
|
||||||
|
|
||||||
float currentSensorData[4] = {0.0, 0.0, 0.0, 0.0};
|
- Buffer sensor values if there is no WIFI connection
|
||||||
|
- Configure weather station over http webinterface
|
||||||
|
- OTA firmware update
|
||||||
|
|
||||||
|
TODO:
|
||||||
|
- https://sminghub.github.io/Sming/about/
|
||||||
|
- https://github.com/marvinroger/homie-esp8266
|
||||||
|
*/
|
||||||
|
|
||||||
|
float currentSensorData[5] = {0.0, 0.0, 0.0, 0.0, 0.0};
|
||||||
|
|
||||||
|
|
||||||
WiFiManager wifiManager;
|
WiFiManager wifiManager;
|
||||||
|
@ -35,9 +35,12 @@ Adafruit_APDS9960 apds;
|
||||||
Adafruit_BME280 bme;
|
Adafruit_BME280 bme;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
#ifdef DEBUG
|
|
||||||
|
#ifdef DEBUG
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//WiFi.disconnect(); // enable to remove the wifi credentials
|
||||||
|
|
||||||
// Pin settings
|
// Pin settings
|
||||||
pinMode(STATUS_LED_PIN, OUTPUT);
|
pinMode(STATUS_LED_PIN, OUTPUT);
|
||||||
|
@ -47,15 +50,16 @@ void setup() {
|
||||||
String wifiName = "oko-weather-" + String(ESP.getChipId());
|
String wifiName = "oko-weather-" + String(ESP.getChipId());
|
||||||
wifiManager.setMinimumSignalQuality(15);
|
wifiManager.setMinimumSignalQuality(15);
|
||||||
if (!wifiManager.autoConnect(wifiName.c_str(), "DEADBEEF")) {
|
if (!wifiManager.autoConnect(wifiName.c_str(), "DEADBEEF")) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.println("WiFi connection failed, we reboot ...");
|
Serial.println("WiFi connection failed, we reboot ...");
|
||||||
#endif
|
#endif
|
||||||
ESP.reset();
|
ESP.reset();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
|
||||||
|
#ifdef DEBUG
|
||||||
Serial.println("Connected!");
|
Serial.println("Connected!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Open the InfluxDB session
|
// Open the InfluxDB session
|
||||||
influxdb.opendb(INFLUXDB_DB, INFLUXDB_USER, INFLUXDB_PASS);
|
influxdb.opendb(INFLUXDB_DB, INFLUXDB_USER, INFLUXDB_PASS);
|
||||||
|
@ -74,35 +78,31 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
digitalWrite(STATUS_LED_PIN, LOW);
|
digitalWrite(STATUS_LED_PIN, LOW);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.println("---");
|
Serial.println("---");
|
||||||
digitalWrite(STATUS_LED_PIN, HIGH);
|
digitalWrite(STATUS_LED_PIN, HIGH);
|
||||||
#endif
|
#endif
|
||||||
currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature();
|
currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature();
|
||||||
Serial.print("*");
|
|
||||||
currentSensorData[SENSOR_HUMIDITY] = fetchHumidity();
|
currentSensorData[SENSOR_HUMIDITY] = fetchHumidity();
|
||||||
Serial.print("*");
|
currentSensorData[SENSOR_LIGHT] = fetchLight();
|
||||||
//currentSensorData[SENSOR_LIGHT] = fetchLight();
|
|
||||||
Serial.print("*");
|
|
||||||
currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed();
|
currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed();
|
||||||
Serial.print("*");
|
|
||||||
currentSensorData[SENSOR_PRESSURE] = fetchPressure();
|
currentSensorData[SENSOR_PRESSURE] = fetchPressure();
|
||||||
Serial.println("*");
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
Serial.println("Current readings:");
|
Serial.println("Current readings:");
|
||||||
Serial.println("Temperature: " + String(currentSensorData[SENSOR_TEMPERATURE]) + " °C");
|
Serial.println("Temperature: " + String(currentSensorData[SENSOR_TEMPERATURE]) + " °C");
|
||||||
Serial.println("Humidity: " + String(currentSensorData[SENSOR_HUMIDITY]) + " %");
|
Serial.println("Humidity: " + String(currentSensorData[SENSOR_HUMIDITY]) + " %");
|
||||||
Serial.println("Light: " + String(currentSensorData[SENSOR_LIGHT]) + " Lumen");
|
Serial.println("Light: " + String(currentSensorData[SENSOR_LIGHT]) + " Lumen");
|
||||||
Serial.println("Windspeed: " + String(currentSensorData[SENSOR_WINDSPEED]) + " Km/h");
|
Serial.println("Windspeed: " + String(currentSensorData[SENSOR_WINDSPEED]) + " km/h");
|
||||||
Serial.println("Pressure: " + String(currentSensorData[SENSOR_PRESSURE]) + " hPa");
|
Serial.println("Pressure: " + String(currentSensorData[SENSOR_PRESSURE]) + " hPa");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
||||||
|
|
||||||
delay(UPDATE_INTERVAL*1000);
|
delay(UPDATE_INTERVAL * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
|
|
||||||
void pushToInfluxDB(String device, float sensorValues[]) {
|
void pushToInfluxDB(String device, float sensorValues[]) {
|
||||||
|
|
||||||
influxdb.write("weather,device=" + device + " temperature=" + String(sensorValues[SENSOR_TEMPERATURE]));
|
influxdb.write("weather,device=" + device + " temperature=" + String(sensorValues[SENSOR_TEMPERATURE]));
|
||||||
influxdb.write("weather,device=" + device + " humidity=" + String(sensorValues[SENSOR_HUMIDITY]));
|
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 + " light=" + String(sensorValues[SENSOR_LIGHT]));
|
||||||
influxdb.write("weather,device=" + device + " windspeed=" + String(sensorValues[SENSOR_WINDSPEED]));
|
influxdb.write("weather,device=" + device + " windspeed=" + String(sensorValues[SENSOR_WINDSPEED]));
|
||||||
|
|
||||||
int tmp = influxdb.write("weather,device=" + device + " pressure=" + String(sensorValues[SENSOR_PRESSURE]));
|
int tmp = influxdb.write("weather,device=" + device + " pressure=" + String(sensorValues[SENSOR_PRESSURE]));
|
||||||
|
|
||||||
Serial.println("Opendb status: " + String(tmp));
|
Serial.println("Opendb status: " + String(tmp));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
firmware/sensors.ino
Normal file → Executable file
10
firmware/sensors.ino
Normal file → Executable file
|
@ -1,11 +1,14 @@
|
||||||
|
|
||||||
int anemometerRotations = 0;
|
int anemometerRotations = 0;
|
||||||
unsigned long currentTime = 0;
|
unsigned long currentTime = 0;
|
||||||
|
|
||||||
float fetchTemperature() {
|
float fetchTemperature() {
|
||||||
|
//return 10;
|
||||||
return bme.readTemperature();
|
return bme.readTemperature();
|
||||||
}
|
}
|
||||||
|
|
||||||
float fetchPressure() {
|
float fetchPressure() {
|
||||||
|
//return 10;
|
||||||
return bme.readPressure() / 100.0F;
|
return bme.readPressure() / 100.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +27,11 @@ float fetchLight() {
|
||||||
return white;
|
return white;
|
||||||
}
|
}
|
||||||
|
|
||||||
void anemometerInterrupt() {
|
void _anemometerInterrupt() {
|
||||||
anemometerRotations++;
|
anemometerRotations++;
|
||||||
|
#ifdef DEBUG
|
||||||
|
Serial.print("*");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
float fetchWindspeed() {
|
float fetchWindspeed() {
|
||||||
|
@ -33,7 +39,7 @@ float fetchWindspeed() {
|
||||||
currentTime = millis();
|
currentTime = millis();
|
||||||
int interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN);
|
int interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN);
|
||||||
|
|
||||||
attachInterrupt(interruptNumber, anemometerInterrupt, RISING);
|
attachInterrupt(interruptNumber, _anemometerInterrupt, RISING);
|
||||||
delay(1000 * 5);
|
delay(1000 * 5);
|
||||||
detachInterrupt(interruptNumber);
|
detachInterrupt(interruptNumber);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue