delta transfer
This commit is contained in:
parent
5be6af0285
commit
32009b2564
2
.vscode/arduino.json
vendored
Normal file → Executable file
2
.vscode/arduino.json
vendored
Normal file → Executable file
@ -1,6 +1,6 @@
|
||||
{
|
||||
"board": "esp8266:esp8266:generic",
|
||||
"configuration": "CpuFrequency=80,FlashFreq=40,FlashMode=qio,UploadSpeed=115200,FlashSize=2M,ResetMethod=ck,Debug=Disabled,DebugLevel=None____",
|
||||
"configuration": "CpuFrequency=80,FlashFreq=40,FlashMode=qio,UploadSpeed=921600,FlashSize=512K0,ResetMethod=ck,Debug=Disabled,DebugLevel=None____",
|
||||
"sketch": "src/backend.ino",
|
||||
"output": "Output",
|
||||
"port": "/dev/ttyUSB0"
|
||||
|
7
.vscode/c_cpp_properties.json
vendored
Normal file → Executable file
7
.vscode/c_cpp_properties.json
vendored
Normal file → Executable file
@ -3,6 +3,10 @@
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"/home/losted/.arduino15/packages/esp8266/tools/**",
|
||||
"/home/losted/.arduino15/packages/esp8266/hardware/esp8266/2.3.0-rc2/**",
|
||||
"/home/losted/.arduino15/packages/esp32/tools/**",
|
||||
"/home/losted/.arduino15/packages/esp32/hardware/esp32/1.0.0/**",
|
||||
"/home/losted/.arduino15/packages/esp8266/hardware/esp8266/2.3.0-rc2/cores/esp8266"
|
||||
],
|
||||
"browse": {
|
||||
@ -14,7 +18,8 @@
|
||||
"intelliSenseMode": "clang-x64",
|
||||
"compilerPath": "/usr/bin/clang",
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++17"
|
||||
"cppStandard": "c++17",
|
||||
"forcedInclude": []
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
|
BIN
.vscode/ipch/84aba349c1d567bb/backend.ipch
vendored
Normal file
BIN
.vscode/ipch/84aba349c1d567bb/backend.ipch
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/84aba349c1d567bb/mmap_address.bin
vendored
Normal file
BIN
.vscode/ipch/84aba349c1d567bb/mmap_address.bin
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/e91f3e5ccba25717/ds18.ipch
vendored
Normal file
BIN
.vscode/ipch/e91f3e5ccba25717/ds18.ipch
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/e91f3e5ccba25717/mmap_address.bin
vendored
Normal file
BIN
.vscode/ipch/e91f3e5ccba25717/mmap_address.bin
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/f46be69a509b72d6/bmp_dht.ipch
vendored
Normal file
BIN
.vscode/ipch/f46be69a509b72d6/bmp_dht.ipch
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/f46be69a509b72d6/mmap_address.bin
vendored
Normal file
BIN
.vscode/ipch/f46be69a509b72d6/mmap_address.bin
vendored
Normal file
Binary file not shown.
0
.vscode/settings.json
vendored
Normal file → Executable file
0
.vscode/settings.json
vendored
Normal file → Executable file
0
Schematic.svg
Normal file → Executable file
0
Schematic.svg
Normal file → Executable file
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
0
backend.code-workspace
Normal file → Executable file
0
backend.code-workspace
Normal file → Executable file
119
src/backend.ino
Normal file → Executable file
119
src/backend.ino
Normal file → Executable file
@ -1,44 +1,41 @@
|
||||
#include <BH1750.h>
|
||||
//dht+bme+mqtt
|
||||
|
||||
#include <BMP280.h>
|
||||
#include <Wire.h>
|
||||
#include <NTPClient.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
// #include <ESP8266mDNS.h>
|
||||
#include "DHTesp.h"
|
||||
#include <DallasTemperature.h>
|
||||
#include <Wire.h>
|
||||
// #include <WiFiUdp.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <OneWire.h>
|
||||
#include "wifi.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Adafruit_MQTT_Client.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
|
||||
float inTemp,humid,extTemp;
|
||||
double bmpTemp,pressure,altitude,lux;
|
||||
double inTemp,outTemp, pressure;
|
||||
const short ds18pin = 12, bmpsda = 4, bmpscl = 5;
|
||||
|
||||
const short ds18pin = 12, bmpsda = 5, bmpscl = 4, dhtpin = 14;
|
||||
/*
|
||||
black - GND
|
||||
red - +5V
|
||||
white - DHT11/DHT22
|
||||
yellow - DS18B20
|
||||
grey - SCL
|
||||
brown - SDA
|
||||
*/
|
||||
|
||||
BMP280 bmp;
|
||||
|
||||
DHTesp dht;
|
||||
OneWire oneWire(ds18pin);
|
||||
DallasTemperature DS18B20(&oneWire);
|
||||
|
||||
WiFiClient client;
|
||||
Adafruit_MQTT_Client mqtt(&client, "192.168.100.100", 1883);
|
||||
Adafruit_MQTT_Publish extTempMQTT = Adafruit_MQTT_Publish(&mqtt, "externalTemp");
|
||||
Adafruit_MQTT_Publish extTempMQTT = Adafruit_MQTT_Publish(&mqtt, "outTemp");
|
||||
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(0x23);
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
Serial.setTimeout(2000);
|
||||
|
||||
//==WIFI CONNECT==
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
@ -47,110 +44,70 @@ void setup(){
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println("Connected to " + String(ssid) + "; IP address: " + WiFi.localIP());
|
||||
// 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);
|
||||
Serial.println("BMP init failed!\n Reset in 3 seconds");
|
||||
delay(3000);
|
||||
ESP.reset();
|
||||
}
|
||||
else {
|
||||
Serial.println("BMP init success!");
|
||||
bmp.setOversampling(4);
|
||||
}
|
||||
|
||||
if (!lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE))
|
||||
Serial.println("lightMeter error!");
|
||||
|
||||
dht.setup(dhtpin);
|
||||
// Serial.println("lets sleep for 30e6 us or 30 seconds");
|
||||
// ESP.deepSleep(30e6);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
getDS18();
|
||||
getBMP();
|
||||
getLight();
|
||||
getAccurateDHT();
|
||||
MQTT_loop();
|
||||
serialPrint();
|
||||
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
void getBMP(){
|
||||
char result = bmp.startMeasurment();
|
||||
if(result!=0){
|
||||
delay(result);
|
||||
bmp.getTemperatureAndPressure(bmpTemp,pressure);
|
||||
bmp.getTemperatureAndPressure(inTemp,pressure);
|
||||
}
|
||||
}
|
||||
|
||||
void getDS18(){
|
||||
do {
|
||||
DS18B20.requestTemperatures();
|
||||
extTemp = DS18B20.getTempCByIndex(0);
|
||||
} while (extTemp == 85.0 || extTemp == (-127.0));
|
||||
outTemp = DS18B20.getTempCByIndex(0);
|
||||
} while (outTemp == 85.0 || outTemp == (-127.0));
|
||||
}
|
||||
|
||||
void getLight(){
|
||||
lux = lightMeter.readLightLevel();
|
||||
}
|
||||
|
||||
void serialPrint() {
|
||||
Serial.println("====");
|
||||
Serial.println("BMP280 Temperature: " + String(bmpTemp) + "degC");
|
||||
Serial.println("Pressure: " + String(pressure) + "mBar");
|
||||
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(){
|
||||
humid = (dht.getHumidity());
|
||||
inTemp = (dht.getTemperature());
|
||||
}
|
||||
void MQTT_loop() {
|
||||
MQTT_connect();
|
||||
|
||||
if (! extTempMQTT.publish(extTemp))
|
||||
if (! extTempMQTT.publish(outTemp))
|
||||
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())
|
||||
mqtt.disconnect();
|
||||
}
|
||||
|
||||
void MQTT_connect() {
|
||||
int8_t ret;
|
||||
if (mqtt.connected()) {
|
||||
return;
|
||||
if (!mqtt.connected()) {
|
||||
while (mqtt.connect() != 0) {
|
||||
WiFi.disconnect();
|
||||
WiFi.begin(ssid, password);
|
||||
mqtt.disconnect();
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
uint8_t retries = 3;
|
||||
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
|
||||
Serial.println(mqtt.connectErrorString(ret));
|
||||
Serial.println("Retrying MQTT connection in 5 seconds...");
|
||||
mqtt.disconnect();
|
||||
delay(5000); // wait 5 seconds
|
||||
retries--;
|
||||
if (retries == 0)
|
||||
while (1);
|
||||
}
|
||||
Serial.println("MQTT Connected!");
|
||||
}
|
||||
void serialPrint() {
|
||||
Serial.println("====");
|
||||
Serial.println("BMP280 Temperature: " + String(inTemp) + "degC");
|
||||
Serial.println("Pressure: " + String(pressure) + "mBar");
|
||||
Serial.println("DS18B20 Temperature: " + String(outTemp) + "degC");
|
||||
}
|
Loading…
Reference in New Issue
Block a user