Added files web service (directory) and fixed setDT service to fastforward the clock.
This commit is contained in:
parent
3dfd08e495
commit
de9fc112d0
39
src/main.cpp
39
src/main.cpp
|
@ -29,6 +29,7 @@
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
#include <ESPAsyncTCP.h> // https://github.com/me-no-dev/AsyncTCP
|
#include <ESPAsyncTCP.h> // https://github.com/me-no-dev/AsyncTCP
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
|
#include <ESP8266HTTPClient.h>
|
||||||
#include "Relays.h"
|
#include "Relays.h"
|
||||||
|
|
||||||
IOTAppStory IAS(COMPDATE, MODEBUTTON);
|
IOTAppStory IAS(COMPDATE, MODEBUTTON);
|
||||||
|
@ -161,7 +162,7 @@ void setupIAS(void) {
|
||||||
// Call home interval in seconds, use 60s only for development.
|
// Call home interval in seconds, use 60s only for development.
|
||||||
// Please change it to at least 2 hours in production
|
// Please change it to at least 2 hours in production
|
||||||
IAS.setCallHomeInterval(120);
|
IAS.setCallHomeInterval(120);
|
||||||
//IAS.callHome(false /*SPIFFS-check*/);
|
IAS.callHome(true /*SPIFFS-check*/);
|
||||||
clockSpeed_modelMsPerRealSec = atoi(clockSpeed_modelMsPerRealSec_String);
|
clockSpeed_modelMsPerRealSec = atoi(clockSpeed_modelMsPerRealSec_String);
|
||||||
relay1Pin = IAS.dPinConv(relay1Pin_String);
|
relay1Pin = IAS.dPinConv(relay1Pin_String);
|
||||||
relay2Pin = IAS.dPinConv(relay2Pin_String);
|
relay2Pin = IAS.dPinConv(relay2Pin_String);
|
||||||
|
@ -318,8 +319,42 @@ void setupWebServer() {
|
||||||
// return json to WebApp
|
// return json to WebApp
|
||||||
request->send(200, F("text/json"), json);
|
request->send(200, F("text/json"), json);
|
||||||
json = String();
|
json = String();
|
||||||
|
R.fwdToTime(hours, minutes);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server.on("/files", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
|
Serial.println(F("\n Directory of FS requested"));
|
||||||
|
FSInfo fs_info;
|
||||||
|
String message = "";
|
||||||
|
|
||||||
|
if (!SPIFFS.info(fs_info)) {
|
||||||
|
message += "Cannot get info about file system! ";
|
||||||
|
}
|
||||||
|
|
||||||
|
// create json return
|
||||||
|
String json = "{";
|
||||||
|
if (message.length() > 0) {
|
||||||
|
json += "\"result\":\"Error\",";
|
||||||
|
json += "\"message\":\"" + message + "\"";
|
||||||
|
} else {
|
||||||
|
json += "\"result\":\"OK\",";
|
||||||
|
json += "\"files\":\"[";
|
||||||
|
Dir dir = SPIFFS.openDir("/");
|
||||||
|
boolean isFirstEntry = true;
|
||||||
|
while (dir.next()) {
|
||||||
|
if (isFirstEntry) { isFirstEntry = false; } else { json += ","; }
|
||||||
|
json += "{\"filename\":\"" + dir.fileName() + "\",\"size\":" + dir.fileSize() + "}";
|
||||||
|
}
|
||||||
|
json += "]";
|
||||||
|
}
|
||||||
|
json += "}";
|
||||||
|
|
||||||
|
// return json to WebApp
|
||||||
|
request->send(200, F("text/json"), json);
|
||||||
|
json = String();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
server.serveStatic("/", SPIFFS, "/");
|
server.serveStatic("/", SPIFFS, "/");
|
||||||
server.onNotFound(onRequest);
|
server.onNotFound(onRequest);
|
||||||
|
|
||||||
|
@ -335,8 +370,8 @@ void setup(void)
|
||||||
{
|
{
|
||||||
Serial.println(F("setup():"));
|
Serial.println(F("setup():"));
|
||||||
setupDisplay();
|
setupDisplay();
|
||||||
setupIAS();
|
|
||||||
setupFS();
|
setupFS();
|
||||||
|
setupIAS();
|
||||||
setupWebServer();
|
setupWebServer();
|
||||||
delay(200);
|
delay(200);
|
||||||
R.begin(relay1Pin, relay2Pin);
|
R.begin(relay1Pin, relay2Pin);
|
||||||
|
|
Loading…
Reference in New Issue