From 17968821544647d3521a4a9ee289a579e80a729c Mon Sep 17 00:00:00 2001 From: coelner Date: Fri, 29 Mar 2019 20:41:00 +0100 Subject: [PATCH] bathroom content --- esp8266-sensor.ino | 5 +++++ main.ino | 23 ++++++++++++++++------- measurement.ino | 42 ++++++++++++++++++++++++++++++++++++++++++ wifi.ino | 2 +- 4 files changed, 64 insertions(+), 8 deletions(-) diff --git a/esp8266-sensor.ino b/esp8266-sensor.ino index 57562f4..2f70af7 100644 --- a/esp8266-sensor.ino +++ b/esp8266-sensor.ino @@ -16,6 +16,10 @@ const bool metric = true; #include #include #include + +#include "EnvironmentCalculations.h" + +#include "secrets.h" /* reset causes: 0: @@ -90,6 +94,7 @@ IPAddress mqttBroker(10, 0, 4, 1); //failsafe const int FW_VERSION = 10; const char* fwUrlBase = "http://10.0.4.2/fota/"; /************************* MQTT Broker Setup *********************************/ +#define name "bathroom" const int MQTT_PORT = 1883; const char MQTT_SERVER[] = "mqtt.koelner.dynvpn.de"; char MQTT_CLIENTID[10]; diff --git a/main.ino b/main.ino index 39c6721..5d83270 100644 --- a/main.ino +++ b/main.ino @@ -58,6 +58,7 @@ SHTSensor sht(SHTSensor::SHT3X_ALT); #ifdef VEML_USE //https://github.com/schizobovine/VEML6075 #include +//#include VEML6075 uvMeter; #endif /************************* BH1750 I2C *********************************/ @@ -137,19 +138,24 @@ uint32_t calculateCRC32( const uint8_t *data, size_t length ) { return crc; } -uint32_t voltageDivCorrelation(uint32_t u3) { + #ifdef BATTERY_USE +uint32_t voltageDivCorrelation(uint32_t u3) { + const unsigned int offset = 8; if (u3 < offset) { return BATT_MEASUREMENT_OFFSET; } -#endif - //translate the 10bit value to reference voltage - //uint32_t adc = map (u3-offset, 0, 1023, 0 , 110); - uint32_t r1 = 390; - uint32_t r2 = 220; - uint32_t r3 = 100; + + //translate the 10bit value to reference voltage of 1.0V + //Resistors are usually in kOhm + + //ToDo: Not working! adc contains millivoltage at native adc port + uint32_t adc = map (u3 - offset, 0, 1023, 0 , 1000); + const uint32_t r1 = 390; + const uint32_t r2 = 220; + const uint32_t r3 = 100; uint32_t rges = r1 + r2 + r3; uint32_t uges = u3 * rges / r3; //TODO why?! @@ -158,6 +164,7 @@ uint32_t voltageDivCorrelation(uint32_t u3) { } uint32_t adc = 0; +#endif #if defined(BME2_USE) || defined (BME6_USE) float temperature(NAN); @@ -318,6 +325,7 @@ void initSensors() { } else { veml6075Check = true; + //set one time measurementw #ifdef SERIAL_DEBUG Serial.println(F("VEML6075 ready.")); #endif @@ -544,6 +552,7 @@ Serial.print(F("\tSHT30 init...\t")); void setup() { + pinMode(D0, WAKEUP_PULLUP); // if serial is not initialized all following calls to serial end dead. #ifdef SERIAL_DEBUG Serial.flush(); diff --git a/measurement.ino b/measurement.ino index 414cc0b..4928b7c 100644 --- a/measurement.ino +++ b/measurement.ino @@ -595,6 +595,48 @@ void measurement() { mqttClient.loop(); delay(10); } +#endif + /********************* Absolute Humidity **************************************/ +#ifdef SHT_USE + if (sht30Check) { + absHumidity = EnvironmentCalculations::AbsoluteHumidity(temperature, humidity, EnvironmentCalculations::TempUnit_Celsius); +#ifdef SERIAL_DEBUG + Serial.print("abs Humidity:\t"); + Serial.print(absHumidity); + Serial.print(" g/m^3"); + Serial.print("\t\t"); +#endif + absHum_str = String(absHumidity); + absHum_str.toCharArray(absHum, absHum_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 0, 128, " " + absHum_str + "g/m^3" ); +#endif + +#ifdef SERIAL_DEBUG + Serial.print("Publish abs Humidity: \t"); +#endif + if (! mqttClient.publish(ABSHUMIDITY_FEED, absHum, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "x"); +#endif + + } else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "o"); +#endif + } + mqttClient.loop(); + yield(); + delay(10); + } #endif /********************* Absolute Humidity **************************************/ #ifdef SI7021_USE diff --git a/wifi.ino b/wifi.ino index 74850b2..1d64587 100644 --- a/wifi.ino +++ b/wifi.ino @@ -49,7 +49,7 @@ bool wifi_connect() { // Disable the WiFi persistence. The ESP8266 will not load and save WiFi settings in the flash memory. // http://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-class.html#persistent WiFi.persistent (false); - WiFi.hostname("bathroom"); //ToDo Change to correct value + WiFi.hostname(name); //ToDo Change to correct value WiFi.config(ip, gateway, subnet, dns); // Connect to WiFi access point. if( rtcValid ) {