Compare commits

...

2 Commits

Author SHA1 Message Date
b123fc7a6a notify in progress 2018-05-29 12:07:43 +03:00
d462dcc147 test notify 2018-05-09 13:01:27 +03:00

View File

@ -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 <ESP8266WiFi.h>
#include <WiFiClient.h> #include <WiFiClient.h>
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
@ -76,6 +113,7 @@ void setup(){
mqtt.subscribe(&inFeed); mqtt.subscribe(&inFeed);
mqtt.subscribe(&humidFeed); mqtt.subscribe(&humidFeed);
server.on("/edit", editConfig); server.on("/edit", editConfig);
server.on("/notify", notify);
server.begin(); 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 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); tone(15,1000);
delay(100); delay(100);
noTone(15); noTone(15);
lastBeep = timeClient.getHours()*60; lastBeep = timeClient.getHours()*60;
} }
notifyCheck();
updateNtp();//update time 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=================== //====================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(){ void editConfig(){
if (server.args() > 0 ) { if (server.args() > 0 ) {
for ( uint8_t i = 0; i < server.args(); i++ ){ 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"); server.send(200, "text/plain", "to update config, goto " + String(WiFi.localIP()) + "/edit?parameter=value");
} }
} }
bool updateConfig() { bool updateConfig() {
StaticJsonBuffer<200> jsonBuffer; StaticJsonBuffer<200> jsonBuffer;
JsonObject& json = jsonBuffer.createObject(); JsonObject& json = jsonBuffer.createObject();
@ -177,7 +310,6 @@ bool updateConfig() {
return true; return true;
} }
bool readConfig() { bool readConfig() {
File configFile = SPIFFS.open("/config.json", "r"); File configFile = SPIFFS.open("/config.json", "r");
if (!configFile) { if (!configFile) {
@ -210,7 +342,7 @@ bool readConfig() {
onTime = int(json["onTime"]); onTime = int(json["onTime"]);
beepDelay = int(json["beepDelay"]); beepDelay = int(json["beepDelay"]);
return true; return true;
configFile.close();
} }
bool defConfig() { bool defConfig() {
StaticJsonBuffer<200> jsonBuffer; StaticJsonBuffer<200> jsonBuffer;
@ -223,34 +355,11 @@ bool defConfig() {
Serial.println("Failed to open config file for writing"); Serial.println("Failed to open config file for writing");
return false; return false;
} }
json.printTo(configFile); json.printTo(configFile);
configFile.close();
return true; 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() { void mainScreen() {
display.clear(); display.clear();
@ -288,7 +397,6 @@ void mainScreen() {
} }
display.display(); display.display();
} }
void displayStatus(int state){ void displayStatus(int state){
display.clear(); display.clear();
if (state == 0) { if (state == 0) {