changed consts, some logical fixes, ofc beautify
This commit is contained in:
parent
83331ff0d9
commit
5be6af0285
2
.vscode/arduino.json
vendored
2
.vscode/arduino.json
vendored
@ -1,6 +1,6 @@
|
||||
{
|
||||
"board": "esp8266:esp8266:generic",
|
||||
"configuration": "CpuFrequency=160,FlashFreq=80,FlashMode=dio,UploadSpeed=115200,FlashSize=2M,ResetMethod=ck,Debug=Disabled,DebugLevel=None____",
|
||||
"configuration": "CpuFrequency=80,FlashFreq=40,FlashMode=qio,UploadSpeed=115200,FlashSize=2M,ResetMethod=ck,Debug=Disabled,DebugLevel=None____",
|
||||
"sketch": "src/backend.ino",
|
||||
"output": "Output",
|
||||
"port": "/dev/ttyUSB0"
|
||||
|
8
.vscode/settings.json
vendored
8
.vscode/settings.json
vendored
@ -8,6 +8,12 @@
|
||||
"initializer_list": "cpp",
|
||||
"string_view": "cpp",
|
||||
"valarray": "cpp",
|
||||
"*.tcc": "cpp"
|
||||
"*.tcc": "cpp",
|
||||
"deque": "cpp",
|
||||
"forward_list": "cpp",
|
||||
"list": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"unordered_set": "cpp",
|
||||
"vector": "cpp"
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
#include <WiFiUdp.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
// #include <ESP8266mDNS.h>
|
||||
#include "DHTesp.h"
|
||||
#include <DallasTemperature.h>
|
||||
#include <OneWire.h>
|
||||
@ -16,7 +16,7 @@
|
||||
float inTemp,humid,extTemp;
|
||||
double bmpTemp,pressure,altitude,lux;
|
||||
|
||||
const short ds18pin = 14, bmpsda = 5, bmpscl = 4, dhtpin = 14;
|
||||
const short ds18pin = 12, bmpsda = 5, bmpscl = 4, dhtpin = 14;
|
||||
|
||||
BMP280 bmp;
|
||||
|
||||
@ -47,9 +47,10 @@ void setup(){
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println("Connected to " + String(ssid) + "; IP address: " + WiFi.localIP());
|
||||
MDNS.begin("esp8266-backend");
|
||||
dht.setup(dhtpin);
|
||||
//==BMP INIT==
|
||||
// MDNS.begin("esp8266-backend");
|
||||
//Sensors init
|
||||
|
||||
//we need remember that bmp and bh1750 are on one i2c line, bmp does wire.begin, bh1750 seems not
|
||||
if(!bmp.begin(bmpsda, bmpscl)){
|
||||
Serial.println("BMP init failed!\n Reset in 10 seconds");
|
||||
delay(10000);
|
||||
@ -60,32 +61,24 @@ void setup(){
|
||||
bmp.setOversampling(4);
|
||||
}
|
||||
|
||||
// Wire.begin(lightSCL, lightSDA);
|
||||
if (!lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE))
|
||||
Serial.println("lightMeter error!");
|
||||
|
||||
// short i = 0;
|
||||
|
||||
// while (i < 1) {
|
||||
// ++i;
|
||||
// }
|
||||
dht.setup(dhtpin);
|
||||
// Serial.println("lets sleep for 30e6 us or 30 seconds");
|
||||
// ESP.deepSleep(30e6);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
// getDS18();
|
||||
getDS18();
|
||||
getBMP();
|
||||
getLight();
|
||||
MQTT_loop();
|
||||
getAccurateDHT();
|
||||
MQTT_loop();
|
||||
serialPrint();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//====================IN PROGRESS===================
|
||||
|
||||
//===================WELL DONE=======================
|
||||
void getBMP(){
|
||||
char result = bmp.startMeasurment();
|
||||
if(result!=0){
|
||||
@ -116,37 +109,33 @@ void serialPrint() {
|
||||
}
|
||||
|
||||
void getAccurateDHT(){
|
||||
// do {
|
||||
humid = (dht.getHumidity());
|
||||
inTemp = (dht.getTemperature());
|
||||
// } while ((humid == NAN)||(inTemp == NAN));
|
||||
}
|
||||
void MQTT_loop() {
|
||||
MQTT_connect();
|
||||
|
||||
if (! extTempMQTT.publish(extTemp)) {
|
||||
if (! extTempMQTT.publish(extTemp))
|
||||
Serial.println(F("Failed"));
|
||||
}
|
||||
if (! inTempMQTT.publish(inTemp)) {
|
||||
Serial.println(F("Failed"));
|
||||
}
|
||||
if (! humidMQTT.publish(humid)) {
|
||||
Serial.println(F("Failed"));
|
||||
}
|
||||
if (! bmpTempMQTT.publish(bmpTemp)) {
|
||||
Serial.println(F("Failed"));
|
||||
}
|
||||
if (! pressureMQTT.publish(pressure)) {
|
||||
Serial.println(F("Failed"));
|
||||
}
|
||||
if (! lightMQTT.publish(lux)) {
|
||||
Serial.println(F("Failed"));
|
||||
}
|
||||
|
||||
if(! mqtt.ping()) {
|
||||
if (! inTempMQTT.publish(inTemp))
|
||||
Serial.println(F("Failed"));
|
||||
|
||||
if (! humidMQTT.publish(humid))
|
||||
Serial.println(F("Failed"));
|
||||
|
||||
if (! bmpTempMQTT.publish(bmpTemp))
|
||||
Serial.println(F("Failed"));
|
||||
|
||||
if (! pressureMQTT.publish(pressure))
|
||||
Serial.println(F("Failed"));
|
||||
|
||||
if (! lightMQTT.publish(lux))
|
||||
Serial.println(F("Failed"));
|
||||
|
||||
if(! mqtt.ping())
|
||||
mqtt.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void MQTT_connect() {
|
||||
int8_t ret;
|
||||
@ -160,9 +149,8 @@ void MQTT_connect() {
|
||||
mqtt.disconnect();
|
||||
delay(5000); // wait 5 seconds
|
||||
retries--;
|
||||
if (retries == 0) {
|
||||
if (retries == 0)
|
||||
while (1);
|
||||
}
|
||||
}
|
||||
Serial.println("MQTT Connected!");
|
||||
}
|
Loading…
Reference in New Issue
Block a user