From 4c174fda5ef32c800c00c53fc75e7ac34031d57d Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Tue, 7 Nov 2017 22:20:14 +0100 Subject: [PATCH] Lets start ... --- firmware/config.h | 13 ++++++++++ firmware/firmware.ino | 56 ++++++++++++++++++++++++++++++++++++++++--- firmware/influxdb.ino | 4 ++++ firmware/sensors.ino | 13 ++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 firmware/config.h create mode 100644 firmware/influxdb.ino create mode 100644 firmware/sensors.ino diff --git a/firmware/config.h b/firmware/config.h new file mode 100644 index 0000000..0b5b161 --- /dev/null +++ b/firmware/config.h @@ -0,0 +1,13 @@ +#define DEBUG + +#define WIFI_PASSWORD "xxx" +#define WIFI_SSID "xxx" + +#define SENSOR_TEMPERATURE 0 +#define SENSOR_HUMIDITY 1 +#define SENSOR_LIGHT 2 + +#define UPDATE_INTERVAL 4 +#define STATUS_LED BUILTIN_LED + + diff --git a/firmware/firmware.ino b/firmware/firmware.ino index 95c2b6e..ab10637 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -1,9 +1,59 @@ -void setup() { - // put your setup code here, to run once: +#include +#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 + * + * - 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 + */ + +float currentSensorData[3] = {0.0, 0.0, 0.0}; + +void connectToWiFi() { +} +bool checkWiFiConnection() { + return true; +} + +void setup() { + #ifdef DEBUG + Serial.begin(115200); + #endif + + pinMode(STATUS_LED, OUTPUT); + connectToWiFi(); } void loop() { - // put your main code here, to run repeatedly: + digitalWrite(STATUS_LED, LOW); + while (!checkWiFiConnection()) { + connectToWiFi(); + delay(5000); + } + + currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature(); + currentSensorData[SENSOR_HUMIDITY] = fetchHumidity(); + currentSensorData[SENSOR_LIGHT] = fetchLight(); + + #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])); + #endif + + pushToInfluxDB(currentSensorData); + + + delay(UPDATE_INTERVAL*1000); } diff --git a/firmware/influxdb.ino b/firmware/influxdb.ino new file mode 100644 index 0000000..c1aa461 --- /dev/null +++ b/firmware/influxdb.ino @@ -0,0 +1,4 @@ +void pushToInfluxDB(float sensorValues[]) { + +} + diff --git a/firmware/sensors.ino b/firmware/sensors.ino new file mode 100644 index 0000000..ff201ba --- /dev/null +++ b/firmware/sensors.ino @@ -0,0 +1,13 @@ + +float fetchTemperature() { + return 22.5; +} + +float fetchHumidity() { + return 60.0; +} + +float fetchLight() { + return 2000.4; +} +