From f161e467bf8833b74e238b0df36d214875ed524b Mon Sep 17 00:00:00 2001 From: l0sted Date: Tue, 30 Oct 2018 12:45:40 +0300 Subject: [PATCH] updated board --- .vscode/arduino.json | 2 +- frontend.ino | 54 +++++++++++++++++++++----------------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/.vscode/arduino.json b/.vscode/arduino.json index c094bc0..3b7c067 100644 --- a/.vscode/arduino.json +++ b/.vscode/arduino.json @@ -2,6 +2,6 @@ "output": "Output", "port": "/dev/ttyUSB0", "board": "esp8266:esp8266:generic", - "configuration": "CpuFrequency=80,VTable=flash,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,FlashSize=4M2M,led=2,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,FlashErase=none,UploadSpeed=921600", + "configuration": "CpuFrequency=80,FlashFreq=40,FlashMode=qio,UploadSpeed=921600,FlashSize=4M2M,ResetMethod=ck,Debug=Disabled,DebugLevel=None____", "sketch": "frontend.ino" } \ No newline at end of file diff --git a/frontend.ino b/frontend.ino index 7968b02..fa5f883 100644 --- a/frontend.ino +++ b/frontend.ino @@ -14,26 +14,8 @@ const String httpAddr="http://192.168.100.101:1880"; WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP); -SSD1306Brzo display(0x3C, 5, 4); //oled display w/ address 0x3C with SDA on GPIO4 and SCL on GPIO5 //address == offset +SSD1306Brzo display(0x3C, 5, 4); -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(); - } else { - Serial.print("Connected to " + String(ssid) + "; IP address: "); - Serial.println(WiFi.localIP()); - displayStatus(0); - } -} void setup(){ Serial.begin(115200); //==DISPLAY INIT== @@ -51,7 +33,7 @@ void setup(){ } void loop(){ - mainScreen();//it could be cool and smooth if we could update screen independently, in some kind of separate thread or smthn similar + mainScreen(); if (((timeClient.getHours()*60 + timeClient.getMinutes()) % beepDelay == 0)&&(timeClient.getSeconds() < 1)&&(!nightMode())){ tone(15,1000); delay(100); @@ -66,7 +48,6 @@ void loop(){ delay(750); } } -//====================IN PROGRESS=================== void netTasks() { HTTPClient http; WiFi.forceSleepWake(); @@ -77,13 +58,13 @@ void netTasks() { http.begin(httpAddr+"/inTemp"); if (http.GET() < 0) //IDK why the fuck i cant getString without this check return; - inTemp="i:"+http.getString(); + inTemp="i:"+http.getString()+"C"; http.end(); http.begin(httpAddr+"/outTemp"); if (http.GET() < 0) return; - outTemp="o:"+http.getString(); + outTemp="o:"+http.getString()+"C"; http.end(); http.begin(httpAddr+"/humid"); @@ -95,7 +76,7 @@ void netTasks() { http.begin(httpAddr+"/pressure"); if (http.GET() < 0) return; - pressure="p:"+http.getString(); + pressure="p:"+http.getString()+"mBar"; http.end(); updateNtp(); @@ -150,14 +131,31 @@ void displayStatus(int state){ display.display(); } void updateNtp() { - // if (lastNtp != timeClient.getHours()) { - while (!timeClient.update()) - Serial.println(timeClient.getHours()); + while (!timeClient.update()) + Serial.println(timeClient.getHours()); } bool nightMode() { - if ((timeClient.getHours() > offTime)||(timeClient.getHours() < onTime)) { //turn off screen between loaded time + if ((timeClient.getHours() > offTime)||(timeClient.getHours() < onTime)) { return true; } else return false; } +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(); + } else { + Serial.print("Connected to " + String(ssid) + "; IP address: "); + Serial.println(WiFi.localIP()); + displayStatus(0); + } +}