Compare commits
2 Commits
master
...
added_noti
Author | SHA1 | Date | |
---|---|---|---|
b123fc7a6a | |||
d462dcc147 |
240
frontend.ino
240
frontend.ino
@ -1,3 +1,40 @@
|
||||
//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
|
||||
//github - oh yeahhh
|
||||
|
||||
//load config
|
||||
//webconfig (?) - in progress
|
||||
//mqtt update interval
|
||||
|
||||
//second screen
|
||||
|
||||
//reconfig wifi if not found (start webserver and AP)
|
||||
|
||||
//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
|
||||
|
||||
*/
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
@ -76,6 +113,7 @@ void setup(){
|
||||
mqtt.subscribe(&inFeed);
|
||||
mqtt.subscribe(&humidFeed);
|
||||
server.on("/edit", editConfig);
|
||||
server.on("/notify", notify);
|
||||
server.begin();
|
||||
}
|
||||
|
||||
@ -89,55 +127,151 @@ void loop(){
|
||||
|
||||
mainScreen();//it could be cool and smooth if we could update screen independently, in some kind of separate thread or smthn similar
|
||||
|
||||
if ((timeClient.getHours()*60 + timeClient.getMinutes() - lastBeep > beepDelay)&&(!nightMode())){ //beep every $lastBeep
|
||||
if ((timeClient.getHours()*60 + timeClient.getMinutes() - lastBeep >= beepDelay)&&(!nightMode())){ //beep every $lastBeep
|
||||
tone(15,1000);
|
||||
delay(100);
|
||||
noTone(15);
|
||||
lastBeep = timeClient.getHours()*60;
|
||||
}
|
||||
|
||||
notifyCheck();
|
||||
updateNtp();//update time
|
||||
}
|
||||
|
||||
//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
|
||||
//github - oh yeahhh
|
||||
|
||||
//load config
|
||||
//webconfig (?) - in progress
|
||||
//mqtt update interval
|
||||
|
||||
//second screen
|
||||
|
||||
//reconfig wifi if not found (start webserver and AP)
|
||||
|
||||
//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===================
|
||||
bool notifyCheck(){
|
||||
File notifyFile = SPIFFS.open("/notify.json", "r");
|
||||
if (!notifyFile) {
|
||||
Serial.println("Failed to open notify file");
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t size = notifyFile.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.
|
||||
notifyFile.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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
notifyFile.close();
|
||||
|
||||
}
|
||||
|
||||
bool testNotifySave() {
|
||||
StaticJsonBuffer<200> jsonBuffer;
|
||||
JsonObject& json = jsonBuffer.createObject();
|
||||
|
||||
json["text"] = "testNotifySave";//string
|
||||
json["time"] = "960";//in minutes
|
||||
|
||||
File notifyFile = SPIFFS.open("/notify.json", "w");
|
||||
if (!notifyFile) {
|
||||
Serial.println("Failed to open notify file for writing");
|
||||
return false;
|
||||
}
|
||||
json.printTo(notifyFile);
|
||||
notifyFile.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
void notify() {
|
||||
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 == "text"){
|
||||
server.send(200, "text/plain", "notify");
|
||||
notifyScreen(client_response);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
server.send(200, "text/plain", "to notify, goto " + String(WiFi.localIP()) + "/edit?text=value");
|
||||
}
|
||||
|
||||
}
|
||||
void notifyScreen(String n_text) { //display func
|
||||
while (true) {
|
||||
display.clear();
|
||||
|
||||
if (!nightMode()) { //turn off screen at night
|
||||
//Center
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display.drawString(64, 22, n_text);
|
||||
//progress bar
|
||||
//top left
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display.drawString(0, 0, timeClient.getFormattedTime());
|
||||
//top right
|
||||
// display.setFont(ArialMT_Plain_10);
|
||||
// display.setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
// display.drawString(128, 0, "p:"+String(pressure));
|
||||
//bottom left
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display.drawString(0, 53, "192.168.100.8");
|
||||
//bottom right
|
||||
// display.setFont(ArialMT_Plain_10);
|
||||
// display.setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
// display.drawString(128, 53, "h:"+String(humid)+"%");
|
||||
|
||||
|
||||
//beep beep!
|
||||
tone(15,750);
|
||||
delay(100);
|
||||
noTone(15);
|
||||
tone(15,900);
|
||||
delay(100);
|
||||
noTone(15);
|
||||
tone(15,1000);
|
||||
delay(100);
|
||||
noTone(15);
|
||||
|
||||
delay(3000);
|
||||
}
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
//====================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 editConfig(){
|
||||
if (server.args() > 0 ) {
|
||||
for ( uint8_t i = 0; i < server.args(); i++ ){
|
||||
@ -160,7 +294,6 @@ void editConfig(){
|
||||
server.send(200, "text/plain", "to update config, goto " + String(WiFi.localIP()) + "/edit?parameter=value");
|
||||
}
|
||||
}
|
||||
|
||||
bool updateConfig() {
|
||||
StaticJsonBuffer<200> jsonBuffer;
|
||||
JsonObject& json = jsonBuffer.createObject();
|
||||
@ -177,7 +310,6 @@ bool updateConfig() {
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool readConfig() {
|
||||
File configFile = SPIFFS.open("/config.json", "r");
|
||||
if (!configFile) {
|
||||
@ -210,7 +342,7 @@ bool readConfig() {
|
||||
onTime = int(json["onTime"]);
|
||||
beepDelay = int(json["beepDelay"]);
|
||||
return true;
|
||||
|
||||
configFile.close();
|
||||
}
|
||||
bool defConfig() {
|
||||
StaticJsonBuffer<200> jsonBuffer;
|
||||
@ -223,34 +355,11 @@ bool defConfig() {
|
||||
Serial.println("Failed to open config file for writing");
|
||||
return false;
|
||||
}
|
||||
|
||||
json.printTo(configFile);
|
||||
configFile.close();
|
||||
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();
|
||||
|
||||
@ -288,7 +397,6 @@ void mainScreen() {
|
||||
}
|
||||
display.display();
|
||||
}
|
||||
|
||||
void displayStatus(int state){
|
||||
display.clear();
|
||||
if (state == 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user