weatherstation/firmware/firmware.ino

76 lines
2 KiB
Arduino
Raw Normal View History

2017-10-20 00:13:40 +02:00
2017-11-07 22:20:14 +01:00
#include <ESP8266WiFi.h>
2017-11-12 22:34:08 +01:00
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
2017-11-07 22:20:14 +01:00
#include "config.h"
/**
* Whishlist:
* - Push sensor values to influxdb
* - Webserver for /metrics endpoint (Prometheus)
* - Show current sensor values over simple webpage
* - Push sensor values to various 3rd party services
2017-11-07 22:36:18 +01:00
* - MQTT?
2017-11-07 22:20:14 +01:00
*
* - Buffer sensor values if there is no WIFI connection
* - Configure weather station over http webinterface
2017-11-07 22:36:18 +01:00
* - OTA firmware update
*
* TODO:
* - https://sminghub.github.io/Sming/about/
* - https://github.com/marvinroger/homie-esp8266
2017-11-07 22:20:14 +01:00
*/
2017-11-12 21:37:55 +01:00
float currentSensorData[4] = {0.0, 0.0, 0.0, 0.0};
2017-11-07 22:20:14 +01:00
2017-11-12 22:34:08 +01:00
WiFiManager wifiManager;
2017-11-07 22:20:14 +01:00
2017-11-12 21:37:55 +01:00
void setup() {
2017-11-07 22:20:14 +01:00
#ifdef DEBUG
Serial.begin(115200);
#endif
2017-11-12 22:34:08 +01:00
// Pin settings
2017-11-12 21:37:55 +01:00
pinMode(STATUS_LED_PIN, OUTPUT);
pinMode(ANEMOMETER_PIN, INPUT_PULLUP);
2017-11-12 22:34:08 +01:00
// Establish wifi connection
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("Connected!");
#endif
2017-10-20 00:13:40 +02:00
}
void loop() {
2017-11-12 21:37:55 +01:00
digitalWrite(STATUS_LED_PIN, LOW);
2017-11-07 22:20:14 +01:00
currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature();
currentSensorData[SENSOR_HUMIDITY] = fetchHumidity();
currentSensorData[SENSOR_LIGHT] = fetchLight();
2017-11-12 21:37:55 +01:00
currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed();
2017-11-07 22:20:14 +01:00
#ifdef DEBUG
Serial.println("");
Serial.println("Current readings:");
2017-11-12 21:37:55 +01:00
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");
2017-11-07 22:20:14 +01:00
#endif
2017-10-20 00:13:40 +02:00
2017-11-07 22:20:14 +01:00
pushToInfluxDB(currentSensorData);
delay(UPDATE_INTERVAL*1000);
2017-10-20 00:13:40 +02:00
}