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",
|
"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",
|
"sketch": "src/backend.ino",
|
||||||
"output": "Output",
|
"output": "Output",
|
||||||
"port": "/dev/ttyUSB0"
|
"port": "/dev/ttyUSB0"
|
||||||
|
8
.vscode/settings.json
vendored
8
.vscode/settings.json
vendored
@ -8,6 +8,12 @@
|
|||||||
"initializer_list": "cpp",
|
"initializer_list": "cpp",
|
||||||
"string_view": "cpp",
|
"string_view": "cpp",
|
||||||
"valarray": "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 <WiFiUdp.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
#include <ESP8266mDNS.h>
|
// #include <ESP8266mDNS.h>
|
||||||
#include "DHTesp.h"
|
#include "DHTesp.h"
|
||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
#include <OneWire.h>
|
#include <OneWire.h>
|
||||||
@ -16,7 +16,7 @@
|
|||||||
float inTemp,humid,extTemp;
|
float inTemp,humid,extTemp;
|
||||||
double bmpTemp,pressure,altitude,lux;
|
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;
|
BMP280 bmp;
|
||||||
|
|
||||||
@ -47,9 +47,10 @@ void setup(){
|
|||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
}
|
}
|
||||||
Serial.println("Connected to " + String(ssid) + "; IP address: " + WiFi.localIP());
|
Serial.println("Connected to " + String(ssid) + "; IP address: " + WiFi.localIP());
|
||||||
MDNS.begin("esp8266-backend");
|
// MDNS.begin("esp8266-backend");
|
||||||
dht.setup(dhtpin);
|
//Sensors init
|
||||||
//==BMP 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)){
|
if(!bmp.begin(bmpsda, bmpscl)){
|
||||||
Serial.println("BMP init failed!\n Reset in 10 seconds");
|
Serial.println("BMP init failed!\n Reset in 10 seconds");
|
||||||
delay(10000);
|
delay(10000);
|
||||||
@ -60,32 +61,24 @@ void setup(){
|
|||||||
bmp.setOversampling(4);
|
bmp.setOversampling(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wire.begin(lightSCL, lightSDA);
|
|
||||||
if (!lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE))
|
if (!lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE))
|
||||||
Serial.println("lightMeter error!");
|
Serial.println("lightMeter error!");
|
||||||
|
|
||||||
// short i = 0;
|
dht.setup(dhtpin);
|
||||||
|
|
||||||
// while (i < 1) {
|
|
||||||
// ++i;
|
|
||||||
// }
|
|
||||||
// Serial.println("lets sleep for 30e6 us or 30 seconds");
|
// Serial.println("lets sleep for 30e6 us or 30 seconds");
|
||||||
// ESP.deepSleep(30e6);
|
// ESP.deepSleep(30e6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
// getDS18();
|
getDS18();
|
||||||
getBMP();
|
getBMP();
|
||||||
getLight();
|
getLight();
|
||||||
MQTT_loop();
|
|
||||||
getAccurateDHT();
|
getAccurateDHT();
|
||||||
|
MQTT_loop();
|
||||||
serialPrint();
|
serialPrint();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//====================IN PROGRESS===================
|
|
||||||
|
|
||||||
//===================WELL DONE=======================
|
|
||||||
void getBMP(){
|
void getBMP(){
|
||||||
char result = bmp.startMeasurment();
|
char result = bmp.startMeasurment();
|
||||||
if(result!=0){
|
if(result!=0){
|
||||||
@ -116,37 +109,33 @@ void serialPrint() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void getAccurateDHT(){
|
void getAccurateDHT(){
|
||||||
// do {
|
|
||||||
humid = (dht.getHumidity());
|
humid = (dht.getHumidity());
|
||||||
inTemp = (dht.getTemperature());
|
inTemp = (dht.getTemperature());
|
||||||
// } while ((humid == NAN)||(inTemp == NAN));
|
|
||||||
}
|
}
|
||||||
void MQTT_loop() {
|
void MQTT_loop() {
|
||||||
MQTT_connect();
|
MQTT_connect();
|
||||||
|
|
||||||
if (! extTempMQTT.publish(extTemp)) {
|
if (! extTempMQTT.publish(extTemp))
|
||||||
Serial.println(F("Failed"));
|
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();
|
mqtt.disconnect();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void MQTT_connect() {
|
void MQTT_connect() {
|
||||||
int8_t ret;
|
int8_t ret;
|
||||||
@ -160,9 +149,8 @@ void MQTT_connect() {
|
|||||||
mqtt.disconnect();
|
mqtt.disconnect();
|
||||||
delay(5000); // wait 5 seconds
|
delay(5000); // wait 5 seconds
|
||||||
retries--;
|
retries--;
|
||||||
if (retries == 0) {
|
if (retries == 0)
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Serial.println("MQTT Connected!");
|
Serial.println("MQTT Connected!");
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user