actually it works, problem was dead ds18b20
This commit is contained in:
parent
44a9d8b079
commit
83331ff0d9
2
.vscode/arduino.json
vendored
2
.vscode/arduino.json
vendored
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"board": "esp8266:esp8266:generic",
|
"board": "esp8266:esp8266:generic",
|
||||||
"configuration": "CpuFrequency=80,FlashFreq=40,FlashMode=dio,UploadSpeed=115200,FlashSize=512K64,ResetMethod=ck,Debug=Disabled,DebugLevel=None____",
|
"configuration": "CpuFrequency=160,FlashFreq=80,FlashMode=dio,UploadSpeed=115200,FlashSize=2M,ResetMethod=ck,Debug=Disabled,DebugLevel=None____",
|
||||||
"sketch": "src/backend.ino",
|
"sketch": "src/backend.ino",
|
||||||
"output": "Output",
|
"output": "Output",
|
||||||
"port": "/dev/ttyUSB0"
|
"port": "/dev/ttyUSB0"
|
||||||
|
13
.vscode/settings.json
vendored
Normal file
13
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"array": "cpp",
|
||||||
|
"hash_map": "cpp",
|
||||||
|
"hash_set": "cpp",
|
||||||
|
"rope": "cpp",
|
||||||
|
"slist": "cpp",
|
||||||
|
"initializer_list": "cpp",
|
||||||
|
"string_view": "cpp",
|
||||||
|
"valarray": "cpp",
|
||||||
|
"*.tcc": "cpp"
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,3 @@
|
|||||||
/*
|
|
||||||
todo
|
|
||||||
|
|
||||||
* sleep
|
|
||||||
*
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <BH1750.h>
|
#include <BH1750.h>
|
||||||
#include <BMP280.h>
|
#include <BMP280.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
@ -24,22 +16,7 @@ todo
|
|||||||
float inTemp,humid,extTemp;
|
float inTemp,humid,extTemp;
|
||||||
double bmpTemp,pressure,altitude,lux;
|
double bmpTemp,pressure,altitude,lux;
|
||||||
|
|
||||||
const short ds18pin = 4, bmpsda = 5, bmpscl = 14, lightSCL = 13, lightSDA = 12, dhtpin = 15;
|
const short ds18pin = 14, bmpsda = 5, bmpscl = 4, dhtpin = 14;
|
||||||
/*
|
|
||||||
light connection:
|
|
||||||
|
|
||||||
VCC -> 3V3 or 5V
|
|
||||||
GND -> GND
|
|
||||||
SCL -> SCL (A5 on Arduino Uno, Leonardo, etc or 21 on Mega and Due, on esp8266 free selectable)
|
|
||||||
SDA -> SDA (A4 on Arduino Uno, Leonardo, etc or 20 on Mega and Due, on esp8266 free selectable)
|
|
||||||
ADD -> (not connected) or GND
|
|
||||||
|
|
||||||
ADD pin is used to set sensor I2C address. If it has voltage greater or equal to
|
|
||||||
0.7VCC voltage (e.g. you've connected it to VCC) the sensor address will be
|
|
||||||
0x5C. In other case (if ADD voltage less than 0.7 * VCC) the sensor address will
|
|
||||||
be 0x23 (by default).
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
BMP280 bmp;
|
BMP280 bmp;
|
||||||
|
|
||||||
@ -56,10 +33,12 @@ Adafruit_MQTT_Publish bmpTempMQTT = Adafruit_MQTT_Publish(&mqtt, "bmpTemp");
|
|||||||
Adafruit_MQTT_Publish pressureMQTT = Adafruit_MQTT_Publish(&mqtt, "pressure");
|
Adafruit_MQTT_Publish pressureMQTT = Adafruit_MQTT_Publish(&mqtt, "pressure");
|
||||||
Adafruit_MQTT_Publish lightMQTT = Adafruit_MQTT_Publish(&mqtt, "light");
|
Adafruit_MQTT_Publish lightMQTT = Adafruit_MQTT_Publish(&mqtt, "light");
|
||||||
|
|
||||||
BH1750 lightMeter;
|
BH1750 lightMeter(0x23);
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
Serial.setTimeout(2000);
|
||||||
|
|
||||||
//==WIFI CONNECT==
|
//==WIFI CONNECT==
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
@ -81,21 +60,26 @@ void setup(){
|
|||||||
bmp.setOversampling(4);
|
bmp.setOversampling(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
Wire.begin(lightSCL, lightSDA);
|
// Wire.begin(lightSCL, lightSDA);
|
||||||
if (!lightMeter.begin())
|
if (!lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE))
|
||||||
Serial.println("lightMeter error!");
|
Serial.println("lightMeter error!");
|
||||||
|
|
||||||
|
// short i = 0;
|
||||||
|
|
||||||
|
// while (i < 1) {
|
||||||
|
// ++i;
|
||||||
|
// }
|
||||||
|
// Serial.println("lets sleep for 30e6 us or 30 seconds");
|
||||||
|
// ESP.deepSleep(30e6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
getAccurateDHT();
|
// getDS18();
|
||||||
serialPrint();
|
getBMP();
|
||||||
// getDS18();
|
getLight();
|
||||||
serialPrint();
|
MQTT_loop();
|
||||||
getBMP();
|
getAccurateDHT();
|
||||||
serialPrint();
|
serialPrint();
|
||||||
getLight();
|
|
||||||
serialPrint();
|
|
||||||
MQTT_loop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -125,21 +109,17 @@ void serialPrint() {
|
|||||||
Serial.println("====");
|
Serial.println("====");
|
||||||
Serial.println("BMP280 Temperature: " + String(bmpTemp) + "degC");
|
Serial.println("BMP280 Temperature: " + String(bmpTemp) + "degC");
|
||||||
Serial.println("Pressure: " + String(pressure) + "mBar");
|
Serial.println("Pressure: " + String(pressure) + "mBar");
|
||||||
Serial.println("Altitude: " + String(altitude) + "m");
|
|
||||||
Serial.println("DS18B20 Temperature: " + String(extTemp) + "degC");
|
Serial.println("DS18B20 Temperature: " + String(extTemp) + "degC");
|
||||||
Serial.println("DHT11 Temperature: " + String(inTemp) + "degC");
|
Serial.println("DHT11 Temperature: " + String(inTemp) + "degC");
|
||||||
Serial.println("Humidity" + String(humid) + "%");
|
Serial.println("Humidity: " + String(humid) + "%");
|
||||||
Serial.println("Light:" + String(lux)+"lux");
|
Serial.println("Light:" + String(lux)+"lux");
|
||||||
}
|
}
|
||||||
|
|
||||||
void getAccurateDHT(){
|
void getAccurateDHT(){
|
||||||
humid = 0.0;
|
// do {
|
||||||
inTemp = 0.0;
|
humid = (dht.getHumidity());
|
||||||
for (int i = 0;i < 3; ++i) { //i dunno why it is incorrect sometimes
|
inTemp = (dht.getTemperature());
|
||||||
delay(dht.getMinimumSamplingPeriod());
|
// } while ((humid == NAN)||(inTemp == NAN));
|
||||||
humid += (dht.getHumidity())/3.0;
|
|
||||||
inTemp += (dht.getTemperature())/3.0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void MQTT_loop() {
|
void MQTT_loop() {
|
||||||
MQTT_connect();
|
MQTT_connect();
|
||||||
@ -170,25 +150,19 @@ void MQTT_loop() {
|
|||||||
|
|
||||||
void MQTT_connect() {
|
void MQTT_connect() {
|
||||||
int8_t ret;
|
int8_t ret;
|
||||||
|
|
||||||
// Stop if already connected.
|
|
||||||
if (mqtt.connected()) {
|
if (mqtt.connected()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serial.print("Connecting to MQTT... ");
|
|
||||||
|
|
||||||
uint8_t retries = 3;
|
uint8_t retries = 3;
|
||||||
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
|
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
|
||||||
Serial.println(mqtt.connectErrorString(ret));
|
Serial.println(mqtt.connectErrorString(ret));
|
||||||
Serial.println("Retrying MQTT connection in 5 seconds...");
|
Serial.println("Retrying MQTT connection in 5 seconds...");
|
||||||
mqtt.disconnect();
|
mqtt.disconnect();
|
||||||
delay(5000); // wait 5 seconds
|
delay(5000); // wait 5 seconds
|
||||||
retries--;
|
retries--;
|
||||||
if (retries == 0) {
|
if (retries == 0) {
|
||||||
// basically die and wait for WDT to reset me
|
while (1);
|
||||||
while (1);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Serial.println("MQTT Connected!");
|
Serial.println("MQTT Connected!");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user