iot:aussenthermometer:programmversion_1.0
no way to compare when less than two revisions
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Letzte Überarbeitung | |||
— | iot:aussenthermometer:programmversion_1.0 [28.07.2019 14:03] – angelegt Frickelpiet | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== Außenthermometer - Programmversion 1.0 ====== | ||
+ | Nachdem die [[iot: | ||
+ | < | ||
+ | // Außenthermometer | ||
+ | // Läuft auf einem Lolin D32 | ||
+ | // Misst Temperatur, Luftfeuchtigkeit und Luftdruck | ||
+ | // Berechnet den Taupunkt und den Hitzeindex | ||
+ | // Sendet die Daten iot.frickelpiet.de | ||
+ | |||
+ | // Bibliotheken | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | // Debug on/off | ||
+ | // #define DEBUG | ||
+ | |||
+ | // Sensor Objekt | ||
+ | Adafruit_BME280 bme; // I2C | ||
+ | |||
+ | // WLAN SSDI und Passwort | ||
+ | const char* ssid = " | ||
+ | const char* password | ||
+ | |||
+ | // Webserver iot.frickelpiet.de | ||
+ | char server[] = " | ||
+ | const int port = 80; | ||
+ | |||
+ | WiFiClient client; | ||
+ | |||
+ | const int sensorbox = 1; // Eindeutige ID des Außenthermometers. Wird von adddata.php ausgewertet | ||
+ | float temperature; | ||
+ | float humidity; | ||
+ | float pressure; | ||
+ | float dewpoint; | ||
+ | float heatindex; | ||
+ | float voltage; | ||
+ | int rssi; // Signalqualität des WiFi | ||
+ | int wifiCounter = 0; // Zählt die Verbindungsversuche zum WiFi | ||
+ | String data; // String, der an den Webserver übertragen wird | ||
+ | |||
+ | #define uS_TO_S_FACTOR 1000000 | ||
+ | #define TIME_TO_SLEEP | ||
+ | |||
+ | |||
+ | void setup () { | ||
+ | // Serielle Schnittstelle | ||
+ | #ifdef DEBUG | ||
+ | Serial.begin(115200); | ||
+ | delay(1000); | ||
+ | #endif | ||
+ | | ||
+ | esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); | ||
+ | #ifdef DEBUG | ||
+ | Serial.println(" | ||
+ | #endif | ||
+ | | ||
+ | // Initialisiert Wire | ||
+ | Wire.begin(25, | ||
+ | | ||
+ | // Verbindung zum WLAN Router aufbauen | ||
+ | #ifdef DEBUG | ||
+ | Serial.printf(" | ||
+ | #endif | ||
+ | | ||
+ | WiFi.begin(ssid, | ||
+ | |||
+ | while (WiFi.status() != WL_CONNECTED) { // Es wird 5 Sekunden eine Verbingung gesucht, danach wird abgebrochen | ||
+ | if (wifiCounter <= 19) { | ||
+ | wifiCounter ++; | ||
+ | delay(500); | ||
+ | #ifdef DEBUG | ||
+ | Serial.print(" | ||
+ | #endif | ||
+ | } | ||
+ | else { | ||
+ | #ifdef DEBUG | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | delay(100); | ||
+ | #endif | ||
+ | esp_deep_sleep_start(); | ||
+ | } | ||
+ | } | ||
+ | #ifdef DEBUG | ||
+ | Serial.println(" | ||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | #endif | ||
+ | |||
+ | // BME280 initialisieren | ||
+ | bool status; | ||
+ | status = bme.begin(); | ||
+ | if (!status) { | ||
+ | #ifdef DEBUG | ||
+ | Serial.println(" | ||
+ | #endif | ||
+ | while (1); | ||
+ | } | ||
+ | bme.setSampling(Adafruit_BME280:: | ||
+ | Adafruit_BME280:: | ||
+ | Adafruit_BME280:: | ||
+ | Adafruit_BME280:: | ||
+ | Adafruit_BME280:: | ||
+ | | ||
+ | // BME 280 abfragen | ||
+ | temperature = bme.readTemperature(); | ||
+ | humidity = bme.readHumidity(); | ||
+ | pressure = bme.readPressure() / 100.0F; | ||
+ | |||
+ | // Taupunkt berechnen | ||
+ | float a = 17.271; | ||
+ | float b = 237.7; | ||
+ | float dewpointTmp = (a * temperature) / (b + temperature) + log(humidity/ | ||
+ | dewpoint = (b * dewpointTmp) / (a - dewpointTmp); | ||
+ | #ifdef DEBUG | ||
+ | Serial.print(" | ||
+ | Serial.print(dewpoint); | ||
+ | Serial.println(" | ||
+ | #endif | ||
+ | |||
+ | // Hitzeindex berechnen | ||
+ | float c1 = -8.784695; | ||
+ | float c2 = 1.61139411; | ||
+ | float c3 = 2.338549; | ||
+ | float c4 = -0.14611605; | ||
+ | float c5 = -1.2308094e-2; | ||
+ | float c6 = -1.6424828e-2; | ||
+ | float c7 = 2.211732e-3; | ||
+ | float c8 = 7.2546e-4; | ||
+ | float c9 = -3.582e-6; | ||
+ | heatindex = c1 + c2 * temperature + c3 * humidity + c4 * temperature * humidity + c5 * sq(temperature) + c6 * sq(humidity) + c7 * sq(temperature) * humidity + c8 * temperature * sq(humidity) + c9 * sq(temperature) * sq(humidity); | ||
+ | #ifdef DEBUG | ||
+ | Serial.print(" | ||
+ | Serial.print(heatindex); | ||
+ | Serial.println(" | ||
+ | #endif | ||
+ | | ||
+ | // Batteriespannung lesen | ||
+ | voltage = analogRead(35) / 4096.0 * 7.445; | ||
+ | #ifdef DEBUG | ||
+ | Serial.print(" | ||
+ | Serial.print(voltage); | ||
+ | Serial.println(" | ||
+ | #endif | ||
+ | |||
+ | // Signalqualität WiFi | ||
+ | rssi = (WiFi.RSSI() + 100) * 2; | ||
+ | #ifdef DEBUG | ||
+ | Serial.print(" | ||
+ | Serial.print(rssi); | ||
+ | Serial.println(" | ||
+ | #endif | ||
+ | |||
+ | // String erzeugen | ||
+ | data = " | ||
+ | + "& | ||
+ | + "& | ||
+ | + "& | ||
+ | + "& | ||
+ | + "& | ||
+ | + "& | ||
+ | + "& | ||
+ | | ||
+ | #ifdef DEBUG | ||
+ | Serial.print(" | ||
+ | #endif | ||
+ | | ||
+ | // Daten an den Webserver iot.frickelpiet.de senden | ||
+ | #ifdef DEBUG | ||
+ | Serial.print(" | ||
+ | Serial.println(server); | ||
+ | #endif | ||
+ | | ||
+ | if (client.connect(server, | ||
+ | #ifdef DEBUG | ||
+ | Serial.print(" | ||
+ | Serial.println(server); | ||
+ | #endif | ||
+ | client.print(" | ||
+ | client.print(data); | ||
+ | client.println(" | ||
+ | client.print(" | ||
+ | client.println(server); | ||
+ | client.println(" | ||
+ | client.println(); | ||
+ | client.stop(); | ||
+ | } | ||
+ | else { | ||
+ | #ifdef DEBUG | ||
+ | Serial.println(" | ||
+ | #endif | ||
+ | } | ||
+ | | ||
+ | // Schickt den ESP32 in den Tiefschlaf | ||
+ | #ifdef DEBUG | ||
+ | Serial.println(" | ||
+ | delay(100); | ||
+ | #endif | ||
+ | esp_deep_sleep_start(); | ||
+ | } | ||
+ | |||
+ | |||
+ | void loop() { | ||
+ | |||
+ | } | ||
+ | </ |
iot/aussenthermometer/programmversion_1.0.txt · Zuletzt geändert: 18.05.2023 12:34 von 127.0.0.1