bathroom content

This commit is contained in:
coelner 2019-03-29 20:41:00 +01:00
parent d52001a408
commit 1796882154
4 changed files with 64 additions and 8 deletions

View File

@ -16,6 +16,10 @@ const bool metric = true;
#include <Wire.h>
#include <MQTTClient.h>
#include <IPAddress.h>
#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];

View File

@ -58,6 +58,7 @@ SHTSensor sht(SHTSensor::SHT3X_ALT);
#ifdef VEML_USE
//https://github.com/schizobovine/VEML6075
#include <VEML6075.h>
//#include <SparkFun_VEML6075_Arduino_Library.h>
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();

View File

@ -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

View File

@ -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 ) {