init
This commit is contained in:
commit
b719769775
226
front.svg
Normal file
226
front.svg
Normal file
@ -0,0 +1,226 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="297mm"
|
||||
height="210mm"
|
||||
viewBox="0 0 297 210"
|
||||
version="1.1"
|
||||
id="svg8"
|
||||
inkscape:version="0.92.2 2405546, 2018-03-11"
|
||||
sodipodi:docname="front.svg">
|
||||
<defs
|
||||
id="defs2" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="1.7148375"
|
||||
inkscape:cx="653.21436"
|
||||
inkscape:cy="527.23476"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="true"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1029"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="27"
|
||||
inkscape:window-maximized="1"
|
||||
showguides="false">
|
||||
<inkscape:grid
|
||||
type="xygrid"
|
||||
id="grid39" />
|
||||
</sodipodi:namedview>
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-87)">
|
||||
<rect
|
||||
style="fill:#ffffff;stroke:#000000;stroke-width:0.26458332"
|
||||
id="rect10"
|
||||
width="92.977005"
|
||||
height="57.462948"
|
||||
x="15.768902"
|
||||
y="126.48205" />
|
||||
<rect
|
||||
style="fill:#ffffff;stroke:#000000;stroke-width:0.26458332"
|
||||
id="rect10-3"
|
||||
width="92.977005"
|
||||
height="57.462948"
|
||||
x="133.3839"
|
||||
y="126.3484" />
|
||||
<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="16.839727"
|
||||
y="162.63971"
|
||||
id="text29"><tspan
|
||||
sodipodi:role="line"
|
||||
x="16.839727"
|
||||
y="162.63971"
|
||||
style="stroke-width:0.49926811"
|
||||
id="tspan31">13:37:33</tspan></text>
|
||||
<path
|
||||
style="fill:none;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 15.768902,142.6787 H 63.342877"
|
||||
id="path3756"
|
||||
inkscape:connector-curvature="0" />
|
||||
<flowRoot
|
||||
xml:space="preserve"
|
||||
id="flowRoot3758"
|
||||
style="font-style:normal;font-weight:normal;font-size:26.66666603px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
|
||||
transform="matrix(0.26458333,0,0,0.26458333,0,87)"><flowRegion
|
||||
id="flowRegion3760"><rect
|
||||
id="rect3762"
|
||||
width="33.335033"
|
||||
height="29.294416"
|
||||
x="59.598999"
|
||||
y="149.2235" /></flowRegion><flowPara
|
||||
id="flowPara3764">штin</flowPara></flowRoot> <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.544998"
|
||||
y="182.55699"
|
||||
id="text3768"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan3766"
|
||||
x="16.544998"
|
||||
y="182.55699"
|
||||
style="stroke-width:0.32799202">i:21.00</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-weight:normal;font-size:8.21431255px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.30803671"
|
||||
x="17.308584"
|
||||
y="133.48927"
|
||||
id="text3772"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan3770"
|
||||
x="17.308584"
|
||||
y="133.48927"
|
||||
style="stroke-width:0.30803671">o:14.88</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-weight:normal;font-size:7.50780106px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.28154254"
|
||||
x="70.250824"
|
||||
y="132.9649"
|
||||
id="text3776"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan3774"
|
||||
x="70.250824"
|
||||
y="132.9649"
|
||||
style="stroke-width:0.28154254">p:1000.21</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-weight:normal;font-size:8.6021862px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.32258195"
|
||||
x="86.394981"
|
||||
y="171.81735"
|
||||
id="text3780"
|
||||
transform="scale(0.94243565,1.0610804)"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan3778"
|
||||
x="86.394981"
|
||||
y="171.81735"
|
||||
style="stroke-width:0.32258195">h:21%</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="29.952995"
|
||||
y="121.7343"
|
||||
id="text3803"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan3801"
|
||||
x="29.952995"
|
||||
y="121.7343"
|
||||
style="stroke-width:0.97224236">MAIN</tspan><tspan
|
||||
sodipodi:role="line"
|
||||
x="29.952995"
|
||||
y="154.14238"
|
||||
style="stroke-width:0.97224236"
|
||||
id="tspan3805" /></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-weight:normal;font-size:25.71569824px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.64289242"
|
||||
x="135.11842"
|
||||
y="120.09695"
|
||||
id="text30"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan27"
|
||||
x="135.11842"
|
||||
y="120.09695"
|
||||
style="stroke-width:0.64289242">GRAPH</tspan></text>
|
||||
<rect
|
||||
style="fill:#ffffff;stroke:#000000;stroke-width:0.29995367"
|
||||
id="rect34"
|
||||
width="92.746307"
|
||||
height="36.081387"
|
||||
x="133.61458"
|
||||
y="147.72995" />
|
||||
<path
|
||||
sodipodi:type="spiral"
|
||||
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.26458332"
|
||||
id="path38"
|
||||
sodipodi:cx="144.99371"
|
||||
sodipodi:cy="138.91006"
|
||||
sodipodi:expansion="1"
|
||||
sodipodi:revolution="3.0965056"
|
||||
sodipodi:radius="11.341615"
|
||||
sodipodi:argument="-20.187172"
|
||||
sodipodi:t0="0"
|
||||
d="m 144.99371,138.91006 c 0.12731,-0.53601 0.78535,-0.0928 0.8909,0.21159 0.28603,0.82501 -0.57165,1.51443 -1.31407,1.57021 -1.32803,0.0998 -2.2793,-1.1799 -2.24952,-2.41656 0.0437,-1.81485 1.7936,-3.05908 3.51905,-2.92882 2.29975,0.17361 3.84476,2.40887 3.60813,4.62153 -0.29777,2.78441 -3.0248,4.63339 -5.72402,4.28744 -3.26911,-0.419 -5.42371,-3.64108 -4.96675,-6.8265 0.53853,-3.75392 4.25758,-6.21511 7.92899,-5.64606 4.23879,0.65698 7.0072,4.87422 6.32537,9.03147 -0.77474,4.72374 -5.49097,7.79978 -10.13396,7.00467 -5.20874,-0.89199 -8.59273,-6.10778 -7.68398,-11.23644 1.00888,-5.69378 6.72466,-9.38595 12.33893,-8.36329 2.22975,0.40616 4.30581,1.51073 5.90293,3.1168" />
|
||||
<flowRoot
|
||||
xml:space="preserve"
|
||||
id="flowRoot40"
|
||||
style="font-style:normal;font-weight:normal;font-size:40px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
|
||||
transform="matrix(0.26458333,0,0,0.26458333,0,87)"><flowRegion
|
||||
id="flowRegion42"><rect
|
||||
id="rect44"
|
||||
width="187.88835"
|
||||
height="45.456871"
|
||||
x="610.63721"
|
||||
y="163.87068" /></flowRegion><flowPara
|
||||
id="flowPara46">13:37:33</flowPara></flowRoot> <path
|
||||
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"
|
||||
id="path54"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;stroke:#000000;stroke-width:0.26274464px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 178.53604,160.42527 h 47.57398"
|
||||
id="path58"
|
||||
inkscape:connector-curvature="0" />
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
|
||||
x="135.63928"
|
||||
y="195.83849"
|
||||
id="text62"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan60"
|
||||
x="135.63928"
|
||||
y="195.83849"
|
||||
style="stroke-width:0.26458332">ONCE PER HOUR</tspan></text>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 9.2 KiB |
315
frontend.ino
Normal file
315
frontend.ino
Normal file
@ -0,0 +1,315 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <NTPClient.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include "SSD1306Brzo.h"
|
||||
// #include <ArduinoJson.h>
|
||||
// #include <FS.h>
|
||||
#include "wifi.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Adafruit_MQTT_Client.h"
|
||||
|
||||
double inTemp,outTemp,pressure,humid;
|
||||
short int onTime = 5, offTime = 23, beepDelay = 1, lastNtp, lastBeep;
|
||||
bool mqttAvail;
|
||||
|
||||
WiFiUDP ntpUDP;
|
||||
NTPClient timeClient(ntpUDP);
|
||||
SSD1306Brzo display(0x3C, 4, 5); //oled display w/ address 0x3C with SDA on GPIO4 and SCL on GPIO5 //address == offset
|
||||
// Ticker dispUpd;
|
||||
// Ticker timeUpd;
|
||||
|
||||
WiFiClient client;
|
||||
|
||||
Adafruit_MQTT_Client mqtt(&client, "192.168.100.102", 1883);
|
||||
|
||||
Adafruit_MQTT_Subscribe pressureFeed = Adafruit_MQTT_Subscribe(&mqtt, "pressure");
|
||||
Adafruit_MQTT_Subscribe inFeed = Adafruit_MQTT_Subscribe(&mqtt, "bmpTemp");
|
||||
Adafruit_MQTT_Subscribe outFeed = Adafruit_MQTT_Subscribe(&mqtt, "externalTemp");
|
||||
Adafruit_MQTT_Subscribe humidFeed = Adafruit_MQTT_Subscribe(&mqtt, "humid");
|
||||
|
||||
void wifiConnect() {
|
||||
int beginMillis = millis();
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED && millis() - beginMillis < 30000) {
|
||||
delay(250);
|
||||
displayStatus(1);
|
||||
Serial.print(".");
|
||||
}
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
displayStatus(2);
|
||||
delay(10000);
|
||||
ESP.reset();
|
||||
}
|
||||
MDNS.begin("esp8266-frontend");
|
||||
Serial.println("Connected to " + String(ssid) + "; IP address: ");
|
||||
displayStatus(0);
|
||||
Serial.print(WiFi.localIP());
|
||||
|
||||
}
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
//==DISPLAY INIT==
|
||||
display.init();
|
||||
display.flipScreenVertically();
|
||||
display.setContrast(255);
|
||||
//==WIFI CONNECT==
|
||||
WiFi.mode(WIFI_STA);
|
||||
wifiConnect();
|
||||
//==READ CONFIG==
|
||||
// if (!readConfig()) {
|
||||
// Serial.println("can't load config!");
|
||||
// defConf();
|
||||
// }
|
||||
//==NTP INIT==
|
||||
timeClient.begin();
|
||||
timeClient.setTimeOffset(10800);
|
||||
//MQTT
|
||||
pressureFeed.setCallback(pressureCall);
|
||||
inFeed.setCallback(inCall);
|
||||
outFeed.setCallback(outCall);
|
||||
humidFeed.setCallback(humidCall);
|
||||
mqtt.subscribe(&pressureFeed);
|
||||
mqtt.subscribe(&outFeed);
|
||||
mqtt.subscribe(&inFeed);
|
||||
mqtt.subscribe(&humidFeed);
|
||||
//debug
|
||||
Serial.println(ESP.getVcc());
|
||||
Serial.println(ESP.getFlashChipRealSize());
|
||||
}
|
||||
|
||||
void loop(){
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
// displayStatus(1);
|
||||
wifiConnect();
|
||||
}
|
||||
MQTT_connect();
|
||||
mqtt.processPackets(500);
|
||||
if(! mqtt.ping()) {
|
||||
mqtt.disconnect();
|
||||
}
|
||||
mainScreen();
|
||||
if (timeClient.getMinutes() == 0 && timeClient.getSeconds() < 5 && !nightMode() && lastBeep != timeClient.getHours()) { //beep
|
||||
tone(15,1000);
|
||||
delay(100);
|
||||
noTone(15);
|
||||
lastBeep = timeClient.getHours();
|
||||
}
|
||||
updateNtp();
|
||||
}
|
||||
|
||||
//TODO
|
||||
//AT LEAST MAKE IT WORK (show ui and get data + ntp) - compiling - ... - WORKS!!11
|
||||
|
||||
//debug -> release
|
||||
//remove useless serial debug - DONE
|
||||
//show wifi info on oled - DONE
|
||||
//reset on not connected - DONE
|
||||
//check connectivity during work and do actions - DONE
|
||||
//beep hourly - DONE
|
||||
//second screen
|
||||
//reconfig wifi if not found (start webserver and AP)
|
||||
//load config
|
||||
//webconfig (?)
|
||||
//mqtt update interval
|
||||
|
||||
//GRAPH
|
||||
/*
|
||||
get json from server
|
||||
~12 values
|
||||
hourly values + hourly display
|
||||
if pressure lowers then weather gonna be bad
|
||||
if pressure uppers then weather gonna be good
|
||||
*/
|
||||
|
||||
//CONFIG
|
||||
/*
|
||||
beep time
|
||||
on time
|
||||
off time
|
||||
mqtt update interval
|
||||
|
||||
*/
|
||||
|
||||
|
||||
//====================IN PROGRESS===================
|
||||
void displayStatus(int state){
|
||||
display.clear();
|
||||
if (state == 0) {
|
||||
display.setFont(ArialMT_Plain_16);
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display.drawString(64, 22, "WL_CONNECTED");
|
||||
|
||||
}
|
||||
if (state == 1) {
|
||||
display.setFont(ArialMT_Plain_16);
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display.drawString(64, 22, "Connecting...");
|
||||
}
|
||||
if (state == 2) {
|
||||
display.setFont(ArialMT_Plain_16);
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display.drawString(64, 22, "Not connected!");
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display.drawString(0, 53, "we will die in 10s! :0");
|
||||
}
|
||||
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() {
|
||||
int8_t ret;
|
||||
|
||||
// Stop if already connected.
|
||||
if (mqtt.connected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print("Connecting to MQTT... ");
|
||||
|
||||
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 10 seconds...");
|
||||
mqtt.disconnect();
|
||||
delay(10000); // wait 10 seconds
|
||||
retries--;
|
||||
if (retries == 0) {
|
||||
// basically die and wait for WDT to reset me
|
||||
while (1);
|
||||
}
|
||||
}
|
||||
Serial.println("MQTT Connected!");
|
||||
}
|
||||
void pressureCall(double x) {
|
||||
pressure = x;
|
||||
}
|
||||
void inCall(double x) {
|
||||
inTemp = x;
|
||||
}
|
||||
void outCall(double x) {
|
||||
outTemp = x;
|
||||
}
|
||||
void humidCall(double x){
|
||||
humid = x;
|
||||
}
|
||||
|
||||
void updateNtp() {
|
||||
if (lastNtp != timeClient.getHours()) {
|
||||
timeClient.update();
|
||||
lastNtp = timeClient.getHours();
|
||||
}
|
||||
}
|
||||
|
||||
bool nightMode() {
|
||||
if ((timeClient.getHours() > offTime)||(timeClient.getHours() < onTime)) { //turn off screen between loaded time
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user