bathroom content
This commit is contained in:
parent
d52001a408
commit
1796882154
@ -16,6 +16,10 @@ const bool metric = true;
|
|||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <MQTTClient.h>
|
#include <MQTTClient.h>
|
||||||
#include <IPAddress.h>
|
#include <IPAddress.h>
|
||||||
|
|
||||||
|
#include "EnvironmentCalculations.h"
|
||||||
|
|
||||||
|
#include "secrets.h"
|
||||||
/*
|
/*
|
||||||
reset causes:
|
reset causes:
|
||||||
0:
|
0:
|
||||||
@ -90,6 +94,7 @@ IPAddress mqttBroker(10, 0, 4, 1); //failsafe
|
|||||||
const int FW_VERSION = 10;
|
const int FW_VERSION = 10;
|
||||||
const char* fwUrlBase = "http://10.0.4.2/fota/";
|
const char* fwUrlBase = "http://10.0.4.2/fota/";
|
||||||
/************************* MQTT Broker Setup *********************************/
|
/************************* MQTT Broker Setup *********************************/
|
||||||
|
#define name "bathroom"
|
||||||
const int MQTT_PORT = 1883;
|
const int MQTT_PORT = 1883;
|
||||||
const char MQTT_SERVER[] = "mqtt.koelner.dynvpn.de";
|
const char MQTT_SERVER[] = "mqtt.koelner.dynvpn.de";
|
||||||
char MQTT_CLIENTID[10];
|
char MQTT_CLIENTID[10];
|
||||||
|
23
main.ino
23
main.ino
@ -58,6 +58,7 @@ SHTSensor sht(SHTSensor::SHT3X_ALT);
|
|||||||
#ifdef VEML_USE
|
#ifdef VEML_USE
|
||||||
//https://github.com/schizobovine/VEML6075
|
//https://github.com/schizobovine/VEML6075
|
||||||
#include <VEML6075.h>
|
#include <VEML6075.h>
|
||||||
|
//#include <SparkFun_VEML6075_Arduino_Library.h>
|
||||||
VEML6075 uvMeter;
|
VEML6075 uvMeter;
|
||||||
#endif
|
#endif
|
||||||
/************************* BH1750 I2C *********************************/
|
/************************* BH1750 I2C *********************************/
|
||||||
@ -137,19 +138,24 @@ uint32_t calculateCRC32( const uint8_t *data, size_t length ) {
|
|||||||
|
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
uint32_t voltageDivCorrelation(uint32_t u3) {
|
|
||||||
#ifdef BATTERY_USE
|
#ifdef BATTERY_USE
|
||||||
|
uint32_t voltageDivCorrelation(uint32_t u3) {
|
||||||
|
|
||||||
const unsigned int offset = 8;
|
const unsigned int offset = 8;
|
||||||
|
|
||||||
if (u3 < offset) {
|
if (u3 < offset) {
|
||||||
return BATT_MEASUREMENT_OFFSET;
|
return BATT_MEASUREMENT_OFFSET;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
//translate the 10bit value to reference voltage
|
//translate the 10bit value to reference voltage of 1.0V
|
||||||
//uint32_t adc = map (u3-offset, 0, 1023, 0 , 110);
|
//Resistors are usually in kOhm
|
||||||
uint32_t r1 = 390;
|
|
||||||
uint32_t r2 = 220;
|
//ToDo: Not working! adc contains millivoltage at native adc port
|
||||||
uint32_t r3 = 100;
|
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 rges = r1 + r2 + r3;
|
||||||
uint32_t uges = u3 * rges / r3;
|
uint32_t uges = u3 * rges / r3;
|
||||||
//TODO why?!
|
//TODO why?!
|
||||||
@ -158,6 +164,7 @@ uint32_t voltageDivCorrelation(uint32_t u3) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t adc = 0;
|
uint32_t adc = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(BME2_USE) || defined (BME6_USE)
|
#if defined(BME2_USE) || defined (BME6_USE)
|
||||||
float temperature(NAN);
|
float temperature(NAN);
|
||||||
@ -318,6 +325,7 @@ void initSensors() {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
veml6075Check = true;
|
veml6075Check = true;
|
||||||
|
//set one time measurementw
|
||||||
#ifdef SERIAL_DEBUG
|
#ifdef SERIAL_DEBUG
|
||||||
Serial.println(F("VEML6075 ready."));
|
Serial.println(F("VEML6075 ready."));
|
||||||
#endif
|
#endif
|
||||||
@ -544,6 +552,7 @@ Serial.print(F("\tSHT30 init...\t"));
|
|||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
pinMode(D0, WAKEUP_PULLUP);
|
||||||
// if serial is not initialized all following calls to serial end dead.
|
// if serial is not initialized all following calls to serial end dead.
|
||||||
#ifdef SERIAL_DEBUG
|
#ifdef SERIAL_DEBUG
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
|
@ -597,6 +597,48 @@ void measurement() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/********************* Absolute Humidity **************************************/
|
/********************* 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
|
#ifdef SI7021_USE
|
||||||
if (si7021Check) {
|
if (si7021Check) {
|
||||||
absHumidity = EnvironmentCalculations::AbsoluteHumidity(temperature, humidity, EnvironmentCalculations::TempUnit_Celsius);
|
absHumidity = EnvironmentCalculations::AbsoluteHumidity(temperature, humidity, EnvironmentCalculations::TempUnit_Celsius);
|
||||||
|
2
wifi.ino
2
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.
|
// 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
|
// http://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-class.html#persistent
|
||||||
WiFi.persistent (false);
|
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);
|
WiFi.config(ip, gateway, subnet, dns);
|
||||||
// Connect to WiFi access point.
|
// Connect to WiFi access point.
|
||||||
if( rtcValid ) {
|
if( rtcValid ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user