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",
|
"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",
|
"sketch": "src/backend.ino",
|
||||||
"output": "Output",
|
"output": "Output",
|
||||||
"port": "/dev/ttyUSB0"
|
"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",
|
"name": "Linux",
|
||||||
"includePath": [
|
"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"
|
"/home/losted/.arduino15/packages/esp8266/hardware/esp8266/2.3.0-rc2/cores/esp8266"
|
||||||
],
|
],
|
||||||
"browse": {
|
"browse": {
|
||||||
@ -14,7 +18,8 @@
|
|||||||
"intelliSenseMode": "clang-x64",
|
"intelliSenseMode": "clang-x64",
|
||||||
"compilerPath": "/usr/bin/clang",
|
"compilerPath": "/usr/bin/clang",
|
||||||
"cStandard": "c11",
|
"cStandard": "c11",
|
||||||
"cppStandard": "c++17"
|
"cppStandard": "c++17",
|
||||||
|
"forcedInclude": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version": 4
|
"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
117
src/backend.ino
Normal file → Executable file
117
src/backend.ino
Normal file → Executable file
@ -1,44 +1,41 @@
|
|||||||
#include <BH1750.h>
|
//dht+bme+mqtt
|
||||||
|
|
||||||
#include <BMP280.h>
|
#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 <DallasTemperature.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
// #include <WiFiUdp.h>
|
||||||
|
#include <WiFiClient.h>
|
||||||
#include <OneWire.h>
|
#include <OneWire.h>
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
#include "Adafruit_MQTT.h"
|
#include "Adafruit_MQTT.h"
|
||||||
#include "Adafruit_MQTT_Client.h"
|
#include "Adafruit_MQTT_Client.h"
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <ESP8266mDNS.h>
|
||||||
|
|
||||||
float inTemp,humid,extTemp;
|
double inTemp,outTemp, pressure;
|
||||||
double bmpTemp,pressure,altitude,lux;
|
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;
|
BMP280 bmp;
|
||||||
|
|
||||||
DHTesp dht;
|
|
||||||
OneWire oneWire(ds18pin);
|
OneWire oneWire(ds18pin);
|
||||||
DallasTemperature DS18B20(&oneWire);
|
DallasTemperature DS18B20(&oneWire);
|
||||||
|
|
||||||
WiFiClient client;
|
WiFiClient client;
|
||||||
Adafruit_MQTT_Client mqtt(&client, "192.168.100.100", 1883);
|
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 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 pressureMQTT = Adafruit_MQTT_Publish(&mqtt, "pressure");
|
||||||
Adafruit_MQTT_Publish lightMQTT = Adafruit_MQTT_Publish(&mqtt, "light");
|
|
||||||
|
|
||||||
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);
|
||||||
@ -47,110 +44,70 @@ 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");
|
|
||||||
//Sensors init
|
//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)){
|
if(!bmp.begin(bmpsda, bmpscl)){
|
||||||
Serial.println("BMP init failed!\n Reset in 10 seconds");
|
Serial.println("BMP init failed!\n Reset in 3 seconds");
|
||||||
delay(10000);
|
delay(3000);
|
||||||
ESP.reset();
|
ESP.reset();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Serial.println("BMP init success!");
|
Serial.println("BMP init success!");
|
||||||
bmp.setOversampling(4);
|
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(){
|
void loop(){
|
||||||
getDS18();
|
getDS18();
|
||||||
getBMP();
|
getBMP();
|
||||||
getLight();
|
|
||||||
getAccurateDHT();
|
|
||||||
MQTT_loop();
|
MQTT_loop();
|
||||||
serialPrint();
|
serialPrint();
|
||||||
|
delay(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void getBMP(){
|
void getBMP(){
|
||||||
char result = bmp.startMeasurment();
|
char result = bmp.startMeasurment();
|
||||||
if(result!=0){
|
if(result!=0){
|
||||||
delay(result);
|
delay(result);
|
||||||
bmp.getTemperatureAndPressure(bmpTemp,pressure);
|
bmp.getTemperatureAndPressure(inTemp,pressure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void getDS18(){
|
void getDS18(){
|
||||||
do {
|
do {
|
||||||
DS18B20.requestTemperatures();
|
DS18B20.requestTemperatures();
|
||||||
extTemp = DS18B20.getTempCByIndex(0);
|
outTemp = DS18B20.getTempCByIndex(0);
|
||||||
} while (extTemp == 85.0 || extTemp == (-127.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() {
|
void MQTT_loop() {
|
||||||
MQTT_connect();
|
MQTT_connect();
|
||||||
|
|
||||||
if (! extTempMQTT.publish(extTemp))
|
if (! extTempMQTT.publish(outTemp))
|
||||||
Serial.println(F("Failed"));
|
Serial.println(F("Failed"));
|
||||||
|
|
||||||
if (! inTempMQTT.publish(inTemp))
|
if (! inTempMQTT.publish(inTemp))
|
||||||
Serial.println(F("Failed"));
|
Serial.println(F("Failed"));
|
||||||
|
|
||||||
if (! humidMQTT.publish(humid))
|
|
||||||
Serial.println(F("Failed"));
|
|
||||||
|
|
||||||
if (! bmpTempMQTT.publish(bmpTemp))
|
|
||||||
Serial.println(F("Failed"));
|
|
||||||
|
|
||||||
if (! pressureMQTT.publish(pressure))
|
if (! pressureMQTT.publish(pressure))
|
||||||
Serial.println(F("Failed"));
|
Serial.println(F("Failed"));
|
||||||
|
|
||||||
if (! lightMQTT.publish(lux))
|
|
||||||
Serial.println(F("Failed"));
|
|
||||||
|
|
||||||
if(! mqtt.ping())
|
if(! mqtt.ping())
|
||||||
mqtt.disconnect();
|
mqtt.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MQTT_connect() {
|
void MQTT_connect() {
|
||||||
int8_t ret;
|
if (!mqtt.connected()) {
|
||||||
if (mqtt.connected()) {
|
while (mqtt.connect() != 0) {
|
||||||
return;
|
WiFi.disconnect();
|
||||||
}
|
WiFi.begin(ssid, password);
|
||||||
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();
|
mqtt.disconnect();
|
||||||
delay(5000); // wait 5 seconds
|
delay(1000);
|
||||||
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