weatherstation/firmware/firmware.ino

70 lines
1.8 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>
#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
*
* - Auto-Reconnect for WIFI
* - Buffer sensor values if there is no WIFI connection
* - Configure weather station over http webinterface
* - If there are now WiFi credentials, open up an access point to configure it
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
void connectToWiFi() {
}
bool checkWiFiConnection() {
return true;
}
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 21:37:55 +01:00
pinMode(STATUS_LED_PIN, OUTPUT);
pinMode(ANEMOMETER_PIN, INPUT_PULLUP);
2017-11-07 22:20:14 +01:00
connectToWiFi();
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
while (!checkWiFiConnection()) {
connectToWiFi();
delay(5000);
}
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
}