not working
This commit is contained in:
parent
2cbf326c8f
commit
44a9d8b079
3
.vscode/arduino.json
vendored
3
.vscode/arduino.json
vendored
@ -2,5 +2,6 @@
|
||||
"board": "esp8266:esp8266:generic",
|
||||
"configuration": "CpuFrequency=80,FlashFreq=40,FlashMode=dio,UploadSpeed=115200,FlashSize=512K64,ResetMethod=ck,Debug=Disabled,DebugLevel=None____",
|
||||
"sketch": "src/backend.ino",
|
||||
"output": "Output"
|
||||
"output": "Output",
|
||||
"port": "/dev/ttyUSB0"
|
||||
}
|
2
.vscode/c_cpp_properties.json
vendored
2
.vscode/c_cpp_properties.json
vendored
@ -17,5 +17,5 @@
|
||||
"cppStandard": "c++17"
|
||||
}
|
||||
],
|
||||
"version": 3
|
||||
"version": 4
|
||||
}
|
@ -1,4 +1,11 @@
|
||||
//backend
|
||||
/*
|
||||
todo
|
||||
|
||||
* sleep
|
||||
*
|
||||
|
||||
*/
|
||||
|
||||
#include <BH1750.h>
|
||||
#include <BMP280.h>
|
||||
#include <Wire.h>
|
||||
@ -17,7 +24,7 @@
|
||||
float inTemp,humid,extTemp;
|
||||
double bmpTemp,pressure,altitude,lux;
|
||||
|
||||
const short ds18pin = 4, bmpsda = 5, bmpscl = 16, lightSCL = 13, lightSDA = 12, dhtpin = 15;
|
||||
const short ds18pin = 4, bmpsda = 5, bmpscl = 14, lightSCL = 13, lightSDA = 12, dhtpin = 15;
|
||||
/*
|
||||
light connection:
|
||||
|
||||
@ -41,12 +48,13 @@ OneWire oneWire(ds18pin);
|
||||
DallasTemperature DS18B20(&oneWire);
|
||||
|
||||
WiFiClient client;
|
||||
Adafruit_MQTT_Client mqtt(&client, "192.168.100.102", 1883);
|
||||
Adafruit_MQTT_Client mqtt(&client, "192.168.100.100", 1883);
|
||||
Adafruit_MQTT_Publish extTempMQTT = Adafruit_MQTT_Publish(&mqtt, "externalTemp");
|
||||
Adafruit_MQTT_Publish inTempMQTT = Adafruit_MQTT_Publish(&mqtt, "inTemp");
|
||||
Adafruit_MQTT_Publish humidMQTT = Adafruit_MQTT_Publish(&mqtt, "humid");
|
||||
Adafruit_MQTT_Publish bmpTempMQTT = Adafruit_MQTT_Publish(&mqtt, "bmpTemp");
|
||||
Adafruit_MQTT_Publish pressureMQTT = Adafruit_MQTT_Publish(&mqtt, "pressure");
|
||||
Adafruit_MQTT_Publish lightMQTT = Adafruit_MQTT_Publish(&mqtt, "light");
|
||||
|
||||
BH1750 lightMeter;
|
||||
|
||||
@ -74,18 +82,19 @@ void setup(){
|
||||
}
|
||||
|
||||
Wire.begin(lightSCL, lightSDA);
|
||||
if (!lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE))
|
||||
if (!lightMeter.begin())
|
||||
Serial.println("lightMeter error!");
|
||||
}
|
||||
|
||||
void loop(){
|
||||
// Serial.println("DHT");
|
||||
getAccurateDHT();
|
||||
// Serial.println("DS18B20");
|
||||
getDS18();
|
||||
// Serial.println("BMP280");
|
||||
serialPrint();
|
||||
// getDS18();
|
||||
serialPrint();
|
||||
getBMP();
|
||||
// Serial.println("MQTT");
|
||||
serialPrint();
|
||||
getLight();
|
||||
serialPrint();
|
||||
MQTT_loop();
|
||||
}
|
||||
|
||||
@ -113,14 +122,14 @@ void getLight(){
|
||||
}
|
||||
|
||||
void serialPrint() {
|
||||
Serial.println("====");
|
||||
Serial.println("BMP280 Temperature: " + String(bmpTemp) + "degC");
|
||||
Serial.println("Pressure: " + String(pressure) + "mBar");
|
||||
Serial.println("Altitude: " + String(altitude) + "m");
|
||||
|
||||
Serial.println("DS18B20 Temperature: " + String(extTemp) + "degC");
|
||||
|
||||
Serial.println("DHT11 Temperature: " + String(inTemp) + "degC");
|
||||
Serial.println("Humidity" + String(humid) + "%");
|
||||
Serial.println("Light:" + String(lux)+"lux");
|
||||
}
|
||||
|
||||
void getAccurateDHT(){
|
||||
@ -150,6 +159,9 @@ void MQTT_loop() {
|
||||
if (! pressureMQTT.publish(pressure)) {
|
||||
Serial.println(F("Failed"));
|
||||
}
|
||||
if (! lightMQTT.publish(lux)) {
|
||||
Serial.println(F("Failed"));
|
||||
}
|
||||
|
||||
if(! mqtt.ping()) {
|
||||
mqtt.disconnect();
|
||||
|
Loading…
Reference in New Issue
Block a user