added config, added webserver, beautify
This commit is contained in:
parent
1c798a3804
commit
c5ac065d05
4
.vscode/arduino.json
vendored
4
.vscode/arduino.json
vendored
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"board": "esp8266:esp8266:generic",
|
"board": "esp8266:esp8266:generic",
|
||||||
"configuration": "CpuFrequency=80,FlashFreq=40,FlashMode=dio,UploadSpeed=115200,FlashSize=1M512,ResetMethod=ck,Debug=Disabled,DebugLevel=None____",
|
"configuration": "CpuFrequency=160,FlashFreq=80,FlashMode=dio,UploadSpeed=115200,FlashSize=1M512,ResetMethod=ck,Debug=Disabled,DebugLevel=None____",
|
||||||
"port": "/dev/ttyUSB0",
|
"port": "/dev/ttyUSB0",
|
||||||
"sketch": "frontend.ino",
|
"sketch": "frontend.ino",
|
||||||
"output": "../ArduinoOutput"
|
"output": "Output"
|
||||||
}
|
}
|
53
front.svg
53
front.svg
@ -25,9 +25,9 @@
|
|||||||
borderopacity="1.0"
|
borderopacity="1.0"
|
||||||
inkscape:pageopacity="0.0"
|
inkscape:pageopacity="0.0"
|
||||||
inkscape:pageshadow="2"
|
inkscape:pageshadow="2"
|
||||||
inkscape:zoom="1.7148375"
|
inkscape:zoom="0.85741875"
|
||||||
inkscape:cx="653.21436"
|
inkscape:cx="557.99796"
|
||||||
inkscape:cy="527.23476"
|
inkscape:cy="403.15866"
|
||||||
inkscape:document-units="mm"
|
inkscape:document-units="mm"
|
||||||
inkscape:current-layer="layer1"
|
inkscape:current-layer="layer1"
|
||||||
showgrid="true"
|
showgrid="true"
|
||||||
@ -201,7 +201,7 @@
|
|||||||
height="45.456871"
|
height="45.456871"
|
||||||
x="610.63721"
|
x="610.63721"
|
||||||
y="163.87068" /></flowRegion><flowPara
|
y="163.87068" /></flowRegion><flowPara
|
||||||
id="flowPara46">13:37:33</flowPara></flowRoot> <path
|
id="flowPara46">14:00:00</flowPara></flowRoot> <path
|
||||||
style="fill:none;stroke:#000000;stroke-width:0.35974398px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
style="fill:none;stroke:#000000;stroke-width:0.35974398px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||||
d="m 133.61458,166.03793 c 0,0 9.38783,-9.88897 16.55223,0.26727 7.1644,10.15624 14.32878,3.74177 14.32878,3.74177 l 9.88194,-6.81537 c 0,0 9.38781,-6.28083 0.74114,-0.4009"
|
d="m 133.61458,166.03793 c 0,0 9.38783,-9.88897 16.55223,0.26727 7.1644,10.15624 14.32878,3.74177 14.32878,3.74177 l 9.88194,-6.81537 c 0,0 9.38781,-6.28083 0.74114,-0.4009"
|
||||||
id="path54"
|
id="path54"
|
||||||
@ -222,5 +222,50 @@
|
|||||||
x="135.63928"
|
x="135.63928"
|
||||||
y="195.83849"
|
y="195.83849"
|
||||||
style="stroke-width:0.26458332">ONCE PER HOUR</tspan></text>
|
style="stroke-width:0.26458332">ONCE PER HOUR</tspan></text>
|
||||||
|
<rect
|
||||||
|
style="fill:#ffffff;stroke:#000000;stroke-width:0.26458332"
|
||||||
|
id="rect10-36"
|
||||||
|
width="92.977005"
|
||||||
|
height="57.462948"
|
||||||
|
x="15.926025"
|
||||||
|
y="219.94919" />
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:19.9707222px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.49926811"
|
||||||
|
x="17.073996"
|
||||||
|
y="250.2438"
|
||||||
|
id="text29-7"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
x="17.073996"
|
||||||
|
y="250.2438"
|
||||||
|
style="font-size:9.87777805px;stroke-width:0.49926811"
|
||||||
|
id="tspan31-5">NOT CONNECTED!</tspan></text>
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:8.74645424px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.32799202"
|
||||||
|
x="16.702122"
|
||||||
|
y="276.02414"
|
||||||
|
id="text3768-5"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan3766-6"
|
||||||
|
x="16.702122"
|
||||||
|
y="276.02414"
|
||||||
|
style="stroke-width:0.32799202;font-size:4.58611111px">we will die in 10s! :0</tspan></text>
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:25.92646408px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.97224236"
|
||||||
|
x="42.761948"
|
||||||
|
y="215.20143"
|
||||||
|
id="text3803-9"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan3801-3"
|
||||||
|
x="42.761948"
|
||||||
|
y="215.20143"
|
||||||
|
style="stroke-width:0.97224236">die</tspan><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
x="42.761948"
|
||||||
|
y="247.60951"
|
||||||
|
style="stroke-width:0.97224236"
|
||||||
|
id="tspan3805-6" /></text>
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 11 KiB |
344
frontend.ino
344
frontend.ino
@ -1,27 +1,26 @@
|
|||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
|
#include <ESP8266WebServer.h>
|
||||||
#include <ESP8266mDNS.h>
|
#include <ESP8266mDNS.h>
|
||||||
#include <NTPClient.h>
|
#include <NTPClient.h>
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#include "SSD1306Brzo.h"
|
#include "SSD1306Brzo.h"
|
||||||
// #include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
// #include <FS.h>
|
#include <FS.h>
|
||||||
#include "../wifi.h" //not working :/
|
#include "wifi.h" //not working :/
|
||||||
#include "Adafruit_MQTT.h"
|
#include "Adafruit_MQTT.h"
|
||||||
#include "Adafruit_MQTT_Client.h"
|
#include "Adafruit_MQTT_Client.h"
|
||||||
|
|
||||||
double inTemp,outTemp,pressure,humid;
|
double inTemp,outTemp,pressure,humid;
|
||||||
short int onTime = 5, offTime = 23, beepDelay = 1, lastNtp, lastBeep;
|
unsigned short int onTime = 5, offTime = 23, beepDelay = 60, lastNtp, lastBeep;
|
||||||
bool mqttAvail;
|
bool mqttAvail;
|
||||||
|
|
||||||
WiFiUDP ntpUDP;
|
WiFiUDP ntpUDP;
|
||||||
NTPClient timeClient(ntpUDP);
|
NTPClient timeClient(ntpUDP);
|
||||||
SSD1306Brzo display(0x3C, 4, 5); //oled display w/ address 0x3C with SDA on GPIO4 and SCL on GPIO5 //address == offset
|
SSD1306Brzo display(0x3C, 4, 5); //oled display w/ address 0x3C with SDA on GPIO4 and SCL on GPIO5 //address == offset
|
||||||
|
|
||||||
// Ticker dispUpd; //i tried ticker for 91 line but it crashes every time it launch
|
|
||||||
|
|
||||||
WiFiClient client;
|
WiFiClient client;
|
||||||
|
ESP8266WebServer server(80);
|
||||||
Adafruit_MQTT_Client mqtt(&client, "192.168.100.102", 1883);
|
Adafruit_MQTT_Client mqtt(&client, "192.168.100.102", 1883);
|
||||||
|
|
||||||
Adafruit_MQTT_Subscribe pressureFeed = Adafruit_MQTT_Subscribe(&mqtt, "pressure");
|
Adafruit_MQTT_Subscribe pressureFeed = Adafruit_MQTT_Subscribe(&mqtt, "pressure");
|
||||||
@ -43,9 +42,9 @@ void wifiConnect() {
|
|||||||
ESP.reset();
|
ESP.reset();
|
||||||
}
|
}
|
||||||
MDNS.begin("esp8266-frontend");
|
MDNS.begin("esp8266-frontend");
|
||||||
Serial.println("Connected to " + String(ssid) + "; IP address: ");
|
Serial.print("Connected to " + String(ssid) + "; IP address: ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
displayStatus(0);
|
displayStatus(0);
|
||||||
Serial.print(WiFi.localIP());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void setup(){
|
void setup(){
|
||||||
@ -58,10 +57,12 @@ void setup(){
|
|||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
wifiConnect();
|
wifiConnect();
|
||||||
//==READ CONFIG==
|
//==READ CONFIG==
|
||||||
// if (!readConfig()) {
|
if (!SPIFFS.begin())
|
||||||
// Serial.println("can't load config!");
|
SPIFFS.format();
|
||||||
// defConf();
|
|
||||||
// }
|
if (!readConfig())
|
||||||
|
defConfig();
|
||||||
|
|
||||||
//==NTP INIT==
|
//==NTP INIT==
|
||||||
timeClient.begin();
|
timeClient.begin();
|
||||||
timeClient.setTimeOffset(10800);
|
timeClient.setTimeOffset(10800);
|
||||||
@ -74,28 +75,28 @@ void setup(){
|
|||||||
mqtt.subscribe(&outFeed);
|
mqtt.subscribe(&outFeed);
|
||||||
mqtt.subscribe(&inFeed);
|
mqtt.subscribe(&inFeed);
|
||||||
mqtt.subscribe(&humidFeed);
|
mqtt.subscribe(&humidFeed);
|
||||||
|
server.on("/edit", editConfig);
|
||||||
Serial.println(ESP.getFlashChipRealSize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED) { //check wifi status
|
||||||
// displayStatus(1);
|
|
||||||
wifiConnect();
|
wifiConnect();
|
||||||
}
|
}
|
||||||
MQTT_connect();
|
server.handleClient();
|
||||||
|
MQTT_connect();//check connection and get packets for 0.5s
|
||||||
mqtt.processPackets(500);
|
mqtt.processPackets(500);
|
||||||
if(! mqtt.ping()) {
|
|
||||||
mqtt.disconnect();
|
|
||||||
}
|
|
||||||
mainScreen();//it could be cool and smooth if we could update screen independently, in some kind of separate thread or smthn similar
|
mainScreen();//it could be cool and smooth if we could update screen independently, in some kind of separate thread or smthn similar
|
||||||
if (timeClient.getMinutes() == 0 && timeClient.getSeconds() < 5 && !nightMode() && lastBeep != timeClient.getHours()) { //beep
|
|
||||||
|
// if (timeClient.getMinutes() == 0 && timeClient.getSeconds() < 5 && !nightMode() && lastBeep != timeClient.getHours()) {
|
||||||
|
if ((timeClient.getHours()*60 + timeClient.getMinutes() - lastBeep > beepDelay)&&(!nightMode())){ //beep every $lastBeep
|
||||||
tone(15,1000);
|
tone(15,1000);
|
||||||
delay(100);
|
delay(100);
|
||||||
noTone(15);
|
noTone(15);
|
||||||
lastBeep = timeClient.getHours();
|
lastBeep = timeClient.getHours()*60 + timeClient.getMinutes();
|
||||||
}
|
}
|
||||||
updateNtp();
|
|
||||||
|
updateNtp();//update time
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
//TODO
|
||||||
@ -108,12 +109,15 @@ void loop(){
|
|||||||
//check connectivity during work and do actions - DONE
|
//check connectivity during work and do actions - DONE
|
||||||
//beep hourly - DONE
|
//beep hourly - DONE
|
||||||
//github - oh yeahhh
|
//github - oh yeahhh
|
||||||
//second screen
|
|
||||||
//reconfig wifi if not found (start webserver and AP)
|
|
||||||
//load config
|
//load config
|
||||||
//webconfig (?)
|
//webconfig (?) - in progress
|
||||||
//mqtt update interval
|
//mqtt update interval
|
||||||
|
|
||||||
|
//second screen
|
||||||
|
|
||||||
|
//reconfig wifi if not found (start webserver and AP)
|
||||||
|
|
||||||
//GRAPH
|
//GRAPH
|
||||||
/*
|
/*
|
||||||
get json from server
|
get json from server
|
||||||
@ -134,6 +138,155 @@ mqtt update interval
|
|||||||
|
|
||||||
|
|
||||||
//====================IN PROGRESS===================
|
//====================IN PROGRESS===================
|
||||||
|
void editConfig(){
|
||||||
|
if (server.args() > 0 ) {
|
||||||
|
for ( uint8_t i = 0; i < server.args(); i++ ){
|
||||||
|
String Argument_Name = server.argName(i);
|
||||||
|
String client_response = server.arg(i);
|
||||||
|
|
||||||
|
if (Argument_Name == "beepDelay"){
|
||||||
|
beepDelay = client_response.toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Argument_Name == "onTime"){
|
||||||
|
onTime = client_response.toInt();
|
||||||
|
}
|
||||||
|
if (Argument_Name == "offTime"){
|
||||||
|
offTime = client_response.toInt();
|
||||||
|
}
|
||||||
|
updateConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool updateConfig() {
|
||||||
|
StaticJsonBuffer<200> jsonBuffer;
|
||||||
|
JsonObject& json = jsonBuffer.createObject();
|
||||||
|
json["onTime"] = onTime;
|
||||||
|
json["offTime"] = offTime;
|
||||||
|
json["beepDelay"] = beepDelay;
|
||||||
|
File configFile = SPIFFS.open("/config.json", "w");
|
||||||
|
if (!configFile) {
|
||||||
|
Serial.println("Failed to open config file for writing");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
json.printTo(configFile);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool readConfig() {
|
||||||
|
File configFile = SPIFFS.open("/config.json", "r");
|
||||||
|
if (!configFile) {
|
||||||
|
Serial.println("Failed to open config file");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size = configFile.size();
|
||||||
|
if (size > 1024) {
|
||||||
|
Serial.println("Config file size is too large");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate a buffer to store contents of the file.
|
||||||
|
std::unique_ptr<char[]> buf(new char[size]);
|
||||||
|
|
||||||
|
// We don't use String here because ArduinoJson library requires the input buffer to be mutable. If you don't use ArduinoJson, you may as well use configFile.readString instead.
|
||||||
|
configFile.readBytes(buf.get(), size);
|
||||||
|
|
||||||
|
StaticJsonBuffer<200> jsonBuffer;
|
||||||
|
JsonObject& json = jsonBuffer.parseObject(buf.get());
|
||||||
|
|
||||||
|
if (!json.success()) {
|
||||||
|
Serial.println("Failed to parse config file");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
offTime = int(json["offTime"]);
|
||||||
|
onTime = int(json["onTime"]);
|
||||||
|
beepDelay = int(json["beepDelay"]);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
bool defConfig() {
|
||||||
|
StaticJsonBuffer<200> jsonBuffer;
|
||||||
|
JsonObject& json = jsonBuffer.createObject();
|
||||||
|
json["onTime"] = "6";
|
||||||
|
json["offTime"] = "23";
|
||||||
|
json["beepDelay"] = "60";
|
||||||
|
File configFile = SPIFFS.open("/config.json", "w");
|
||||||
|
if (!configFile) {
|
||||||
|
Serial.println("Failed to open config file for writing");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
json.printTo(configFile);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//====================paused===================
|
||||||
|
|
||||||
|
|
||||||
|
// void secondDisplay() {
|
||||||
|
// display.clear();
|
||||||
|
// display.setFont(ArialMT_Plain_16);
|
||||||
|
// display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||||
|
// display.drawString(0, 30, timeClient.getFormattedTime());
|
||||||
|
|
||||||
|
// display.drawRect(0,18,128,53); //frame
|
||||||
|
// /*
|
||||||
|
// 128/12=10px
|
||||||
|
// 128x32 resolution
|
||||||
|
// 32-19=13px for graph
|
||||||
|
// */
|
||||||
|
// int x = 0;
|
||||||
|
// for (int i=0;i<12;++i){
|
||||||
|
// display.drawLine(x+i*10, y[x], x+i*10+10, y[x]);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
//===================WELL DONE=======================
|
||||||
|
void mainScreen() {
|
||||||
|
display.clear();
|
||||||
|
|
||||||
|
if (!nightMode()) { //turn off screen at night
|
||||||
|
int x = (timeClient.getHours()*60+timeClient.getMinutes())/11;
|
||||||
|
//Time
|
||||||
|
display.setFont(ArialMT_Plain_24);
|
||||||
|
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||||
|
display.drawString(64, 22, timeClient.getFormattedTime());
|
||||||
|
//progress bar
|
||||||
|
display.drawLine(0,22,x,22);
|
||||||
|
if (mqttAvail){ //do not show info if mqtt not available
|
||||||
|
//external temp //top left
|
||||||
|
display.setFont(ArialMT_Plain_10);
|
||||||
|
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
|
display.drawString(0, 0, "o:"+String(outTemp));
|
||||||
|
//pressure //top right
|
||||||
|
display.setFont(ArialMT_Plain_10);
|
||||||
|
display.setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||||
|
display.drawString(128, 0, "p:"+String(pressure));
|
||||||
|
//inside temp //bottom left
|
||||||
|
display.setFont(ArialMT_Plain_10);
|
||||||
|
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
|
display.drawString(0, 53, "i:"+String(inTemp));
|
||||||
|
//humid //bottom right
|
||||||
|
display.setFont(ArialMT_Plain_10);
|
||||||
|
display.setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||||
|
display.drawString(128, 53, "h:"+String(humid)+"%");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
display.setFont(ArialMT_Plain_10);
|
||||||
|
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
|
display.drawString(0, 53, "mqtt unavailable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display.display();
|
||||||
|
}
|
||||||
|
|
||||||
void displayStatus(int state){
|
void displayStatus(int state){
|
||||||
display.clear();
|
display.clear();
|
||||||
if (state == 0) {
|
if (state == 0) {
|
||||||
@ -158,132 +311,23 @@ void displayStatus(int state){
|
|||||||
display.display();
|
display.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
void mainScreen() {
|
|
||||||
display.clear();
|
|
||||||
|
|
||||||
if (!nightMode()) { //turn off screen at night
|
|
||||||
int x = (timeClient.getHours()*60+timeClient.getMinutes())/11;
|
|
||||||
//Time
|
|
||||||
display.setFont(ArialMT_Plain_24);
|
|
||||||
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
|
||||||
display.drawString(64, 22, timeClient.getFormattedTime());
|
|
||||||
//progress bar
|
|
||||||
display.drawLine(0,22,x,22);
|
|
||||||
//external temp //top left
|
|
||||||
display.setFont(ArialMT_Plain_10);
|
|
||||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
|
||||||
display.drawString(0, 0, "o:"+String(outTemp));
|
|
||||||
//pressure //top right
|
|
||||||
display.setFont(ArialMT_Plain_10);
|
|
||||||
display.setTextAlignment(TEXT_ALIGN_RIGHT);
|
|
||||||
display.drawString(128, 0, "p:"+String(pressure));
|
|
||||||
//inside temp //bottom left
|
|
||||||
display.setFont(ArialMT_Plain_10);
|
|
||||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
|
||||||
display.drawString(0, 53, "i:"+String(inTemp));
|
|
||||||
//humid //bottom right
|
|
||||||
display.setFont(ArialMT_Plain_10);
|
|
||||||
display.setTextAlignment(TEXT_ALIGN_RIGHT);
|
|
||||||
display.drawString(128, 53, "h:"+String(humid)+"%");
|
|
||||||
|
|
||||||
}
|
|
||||||
display.display();
|
|
||||||
}
|
|
||||||
|
|
||||||
// void secondDisplay() {
|
|
||||||
// display.clear();
|
|
||||||
// display.setFont(ArialMT_Plain_16);
|
|
||||||
// display.setTextAlignment(TEXT_ALIGN_CENTER);
|
|
||||||
// display.drawString(0, 30, timeClient.getFormattedTime());
|
|
||||||
|
|
||||||
// display.drawRect(0,18,128,53); //frame
|
|
||||||
// /*
|
|
||||||
// 128/12=10px
|
|
||||||
// 128x32 resolution
|
|
||||||
// 32-19=13px for graph
|
|
||||||
// */
|
|
||||||
// int x = 0;
|
|
||||||
// for (int i=0;i<12;++i){
|
|
||||||
// display.drawLine(x+i*10, y[x], x+i*10+10, y[x]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
//====================paused===================
|
|
||||||
|
|
||||||
// bool readConfig() {
|
|
||||||
// File configFile = SPIFFS.open("/config.json", "r");
|
|
||||||
// if (!configFile) {
|
|
||||||
// Serial.println("Failed to open config file");
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // size_t size = configFile.size();
|
|
||||||
// // if (size > 1024) {
|
|
||||||
// // Serial.println("Config file size is too large");
|
|
||||||
// // return false;
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // Allocate a buffer to store contents of the file.
|
|
||||||
// std::unique_ptr<char[]> buf(new char[size]);
|
|
||||||
|
|
||||||
// // We don't use String here because ArduinoJson library requires the input buffer to be mutable. If you don't use ArduinoJson, you may as well use configFile.readString instead.
|
|
||||||
// configFile.readBytes(buf.get(), size);
|
|
||||||
|
|
||||||
// StaticJsonBuffer<200> jsonBuffer;
|
|
||||||
// JsonObject& json = jsonBuffer.parseObject(buf.get());
|
|
||||||
|
|
||||||
// if (!json.success()) {
|
|
||||||
// Serial.println("Failed to parse config file");
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// offTime = int(json["offTime"]);
|
|
||||||
// onTime = int(json["onTime"]);
|
|
||||||
// beepDelay = int(json["beepDelay"]);
|
|
||||||
// return true;
|
|
||||||
|
|
||||||
// }
|
|
||||||
// bool defConf() {
|
|
||||||
// StaticJsonBuffer<200> jsonBuffer;
|
|
||||||
// JsonObject& json = jsonBuffer.createObject();
|
|
||||||
// json["onTime"] = "6";
|
|
||||||
// json["offTime"] = "23";
|
|
||||||
// json["beepDelay"] = "60";
|
|
||||||
// File configFile = SPIFFS.open("/config.json", "w");
|
|
||||||
// if (!configFile) {
|
|
||||||
// Serial.println("Failed to open config file for writing");
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// json.printTo(configFile);
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
//===================WELL DONE=======================
|
|
||||||
void MQTT_connect() {
|
void MQTT_connect() {
|
||||||
int8_t ret;
|
|
||||||
|
|
||||||
// Stop if already connected.
|
|
||||||
if (mqtt.connected()) {
|
if (mqtt.connected()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
int8_t ret;
|
||||||
Serial.print("Connecting to MQTT... ");
|
|
||||||
|
|
||||||
uint8_t retries = 3;
|
uint8_t retries = 3;
|
||||||
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
|
while ((ret = mqtt.connect()) != 0) {
|
||||||
Serial.println(mqtt.connectErrorString(ret));
|
displayStatus(3);
|
||||||
Serial.println("Retrying MQTT connection in 10 seconds...");
|
mqtt.disconnect();
|
||||||
mqtt.disconnect();
|
delay(5000);
|
||||||
delay(10000); // wait 10 seconds
|
retries--;
|
||||||
retries--;
|
if (retries == 0) {
|
||||||
if (retries == 0) {
|
mqttAvail = false;
|
||||||
// basically die and wait for WDT to reset me
|
}
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Serial.println("MQTT Connected!");
|
if (mqtt.connected())
|
||||||
|
mqttAvail = true;
|
||||||
}
|
}
|
||||||
void pressureCall(double x) {
|
void pressureCall(double x) {
|
||||||
pressure = x;
|
pressure = x;
|
||||||
@ -297,14 +341,12 @@ void outCall(double x) {
|
|||||||
void humidCall(double x){
|
void humidCall(double x){
|
||||||
humid = x;
|
humid = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateNtp() {
|
void updateNtp() {
|
||||||
if (lastNtp != timeClient.getHours()) {
|
if (lastNtp != timeClient.getHours()) {
|
||||||
timeClient.update();
|
if (timeClient.update())
|
||||||
lastNtp = timeClient.getHours();
|
lastNtp = timeClient.getHours();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nightMode() {
|
bool nightMode() {
|
||||||
if ((timeClient.getHours() > offTime)||(timeClient.getHours() < onTime)) { //turn off screen between loaded time
|
if ((timeClient.getHours() > offTime)||(timeClient.getHours() < onTime)) { //turn off screen between loaded time
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user