diff --git a/doc/wemos-d1-mini-shematics.jpg b/doc/wemos-d1-mini-shematics.jpg new file mode 100644 index 0000000..983de10 Binary files /dev/null and b/doc/wemos-d1-mini-shematics.jpg differ diff --git a/doc/wemos_esp8266_pinout.png b/doc/wemos_esp8266_pinout.png new file mode 100644 index 0000000..7d29576 Binary files /dev/null and b/doc/wemos_esp8266_pinout.png differ diff --git a/firmware/config.h b/firmware/config.h index 55ebd3d..fc7d436 100755 --- a/firmware/config.h +++ b/firmware/config.h @@ -1,4 +1,4 @@ -#define DEBUG +#define DEBUG 1 #define SENSOR_TEMPERATURE 0 #define SENSOR_HUMIDITY 1 @@ -9,22 +9,22 @@ #define UPDATE_INTERVAL 4 #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_MOSI 11 -#define BME_CS 10 +#define BME_CS 10 #define SEALEVELPRESSURE_HPA (1013.25) #define BME280_ADDRESS 0x76 -const char *INFLUXDB_HOST = "influxdb.okoyono.de"; -const uint16_t INFLUXDB_PORT = 80; -const char *INFLUXDB_DB = "weatherstation"; -const char *INFLUXDB_USER = "oko"; -const char *INFLUXDB_PASS = "de1873a0d2f8f21f17cf4d8db4f65c59"; - -String DEVICE_NAME = "aaron"; +const char *INFLUXDB_HOST = "influxdb.okoyono.de"; +const uint16_t INFLUXDB_PORT = 80; +const char *INFLUXDB_DB = "weatherstation"; +const char *INFLUXDB_USER = "oko"; +const char *INFLUXDB_PASS = "de1873a0d2f8f21f17cf4d8db4f65c59"; +String DEVICE_NAME = "klaute"; + diff --git a/firmware/firmware.ino b/firmware/firmware.ino index 07976d6..404234e 100755 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -2,31 +2,31 @@ #include #include #include -#include -#include // https://github.com/hwwong/ESP8266Influxdb auchecken und code+header in das firmware verzeichnis kopieren -#include // Adafruit Unified Sensor -#include // https://github.com/adafruit/Adafruit_APDS9960 -#include // https://github.com/adafruit/Adafruit_BME280_Library +#include // WiFiManager +#include // https://github.com/hwwong/ESP8266Influxdb auchecken und den ordner in das arduino\library verzeichnis kopieren +#include // PAckage Adafruit Unified Sensor +#include // Adafruit APDS9960 - https://www.makerfabs.com/index.php?route=product/product&product_id=281 +#include // BME280 - https://www.roboter-bausatz.de/1704/bmp280-barometer-luftdrucksensor?gclid=EAIaIQobChMIlpumj8Hp2wIVFWYbCh01PgmFEAQYAyABEgIwBvD_BwE #include "config.h" /** - * Whishlist: - * - Webserver for /metrics endpoint (Prometheus) - * - Show current sensor values over simple webpage - * - Push sensor values to various 3rd party services (https://openweathermap.org/) - * - 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 - */ + Whishlist: + - Webserver for /metrics endpoint (Prometheus) + - Show current sensor values over simple webpage + - Push sensor values to various 3rd party services (https://openweathermap.org/) + - MQTT? -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; @@ -34,10 +34,13 @@ Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT); Adafruit_APDS9960 apds; Adafruit_BME280 bme; -void setup() { - #ifdef DEBUG - Serial.begin(115200); - #endif +void setup() { + +#ifdef DEBUG + Serial.begin(115200); +#endif + + //WiFi.disconnect(); // enable to remove the wifi credentials // Pin settings pinMode(STATUS_LED_PIN, OUTPUT); @@ -47,15 +50,16 @@ void setup() { String wifiName = "oko-weather-" + String(ESP.getChipId()); wifiManager.setMinimumSignalQuality(15); if (!wifiManager.autoConnect(wifiName.c_str(), "DEADBEEF")) { - #ifdef DEBUG - Serial.println("WiFi connection failed, we reboot ..."); - #endif - ESP.reset(); - delay(1000); +#ifdef DEBUG + Serial.println("WiFi connection failed, we reboot ..."); +#endif + ESP.reset(); + delay(1000); } - #ifdef DEBUG - Serial.println("Connected!"); - #endif + +#ifdef DEBUG + Serial.println("Connected!"); +#endif // Open the InfluxDB session influxdb.opendb(INFLUXDB_DB, INFLUXDB_USER, INFLUXDB_PASS); @@ -65,44 +69,40 @@ void setup() { apds.enableColor(true); bool status = bme.begin(0x76); - if (!status) { - Serial.println("Could not find a valid BME280 sensor, check wiring!"); - while (1); - } + if (!status) { + Serial.println("Could not find a valid BME280 sensor, check wiring!"); + while (1); + } delay(100); } void loop() { + digitalWrite(STATUS_LED_PIN, LOW); - - #ifdef DEBUG - Serial.println("---"); - digitalWrite(STATUS_LED_PIN, HIGH); - #endif +#ifdef DEBUG + Serial.println("---"); + digitalWrite(STATUS_LED_PIN, HIGH); +#endif currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature(); - Serial.print("*"); - currentSensorData[SENSOR_HUMIDITY] = fetchHumidity(); - Serial.print("*"); - //currentSensorData[SENSOR_LIGHT] = fetchLight(); - Serial.print("*"); - currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed(); - Serial.print("*"); - currentSensorData[SENSOR_PRESSURE] = fetchPressure(); - Serial.println("*"); + currentSensorData[SENSOR_HUMIDITY] = fetchHumidity(); + currentSensorData[SENSOR_LIGHT] = fetchLight(); + currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed(); + currentSensorData[SENSOR_PRESSURE] = fetchPressure(); - #ifdef DEBUG - Serial.println(""); - Serial.println("Current readings:"); - 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"); - Serial.println("Pressure: " + String(currentSensorData[SENSOR_PRESSURE]) + " hPa"); - #endif +#ifdef DEBUG + Serial.println(""); + Serial.println("Current readings:"); + 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"); + Serial.println("Pressure: " + String(currentSensorData[SENSOR_PRESSURE]) + " hPa"); +#endif pushToInfluxDB(DEVICE_NAME, currentSensorData); - - delay(UPDATE_INTERVAL*1000); -} + + delay(UPDATE_INTERVAL * 1000); +} + diff --git a/firmware/influxdb.ino b/firmware/influxdb.ino index c96d1a6..0c70db0 100755 --- a/firmware/influxdb.ino +++ b/firmware/influxdb.ino @@ -1,10 +1,14 @@ + void pushToInfluxDB(String device, float sensorValues[]) { + 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 + " light=" + String(sensorValues[SENSOR_LIGHT])); influxdb.write("weather,device=" + device + " windspeed=" + String(sensorValues[SENSOR_WINDSPEED])); + int tmp = influxdb.write("weather,device=" + device + " pressure=" + String(sensorValues[SENSOR_PRESSURE])); Serial.println("Opendb status: " + String(tmp)); -} +} + diff --git a/firmware/sensors.ino b/firmware/sensors.ino old mode 100644 new mode 100755 index 3d5e93b..770a19e --- a/firmware/sensors.ino +++ b/firmware/sensors.ino @@ -1,11 +1,14 @@ + int anemometerRotations = 0; unsigned long currentTime = 0; float fetchTemperature() { + //return 10; return bme.readTemperature(); } float fetchPressure() { + //return 10; return bme.readPressure() / 100.0F; } @@ -24,8 +27,11 @@ float fetchLight() { return white; } -void anemometerInterrupt() { +void _anemometerInterrupt() { anemometerRotations++; +#ifdef DEBUG + Serial.print("*"); +#endif } float fetchWindspeed() { @@ -33,10 +39,10 @@ float fetchWindspeed() { currentTime = millis(); int interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN); - attachInterrupt(interruptNumber, anemometerInterrupt, RISING); + attachInterrupt(interruptNumber, _anemometerInterrupt, RISING); delay(1000 * 5); detachInterrupt(interruptNumber); return (float)anemometerRotations / 5.0 * 2.4; } - +