file hosting through esp
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
{
|
{
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
// for the documentation about the extensions.json format
|
// for the documentation about the extensions.json format
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"platformio.platformio-ide"
|
"platformio.platformio-ide"
|
||||||
]
|
],
|
||||||
}
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
@@ -13,7 +13,10 @@ platform = espressif8266
|
|||||||
board = d1_mini_pro
|
board = d1_mini_pro
|
||||||
framework = arduino
|
framework = arduino
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
board_build.filesystem = littlefs
|
||||||
|
board_build.ldscript = eagle.flash.4m3m.ld
|
||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
https://git.aterve.com/Frozenverse/SimpleSerialProtocol.git
|
https://git.aterve.com/Frozenverse/SimpleSerialProtocol.git
|
||||||
https://github.com/bblanchon/ArduinoJson.git
|
https://github.com/bblanchon/ArduinoJson.git
|
||||||
|
https://github.com/earlephilhower/arduino-esp8266littlefs-plugin.git
|
@@ -7,6 +7,9 @@
|
|||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
|
||||||
|
#include <FS.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
|
|
||||||
#include <SimpleSerialProtocol.h>
|
#include <SimpleSerialProtocol.h>
|
||||||
|
|
||||||
#include <StateData.h>
|
#include <StateData.h>
|
||||||
@@ -31,10 +34,12 @@ namespace Connection {
|
|||||||
void initWifi();
|
void initWifi();
|
||||||
void handleWifi();
|
void handleWifi();
|
||||||
void sendResponse(DynamicJsonDocument response);
|
void sendResponse(DynamicJsonDocument response);
|
||||||
|
void handleWifiStatus();
|
||||||
|
|
||||||
void onApiStatusRoute();
|
void onApiStatusRoute();
|
||||||
void getCurrentStateRoute();
|
void getCurrentStateRoute();
|
||||||
void onDeviceRoute();
|
void onDeviceRoute();
|
||||||
|
void onWebpageRoute();
|
||||||
}
|
}
|
||||||
|
|
||||||
// serial
|
// serial
|
||||||
@@ -78,10 +83,24 @@ void Connection::initWifi(){
|
|||||||
WiFi.localIP().toString().toCharArray(ipAdress,50);
|
WiFi.localIP().toString().toCharArray(ipAdress,50);
|
||||||
controller.sendPacket("controller", "wifi_details", ipAdress);
|
controller.sendPacket("controller", "wifi_details", ipAdress);
|
||||||
|
|
||||||
|
server.on("/", Connection::onWebpageRoute);
|
||||||
server.on("/api/status", Connection::onApiStatusRoute);
|
server.on("/api/status", Connection::onApiStatusRoute);
|
||||||
server.on("/api/currentstate", Connection::getCurrentStateRoute);
|
server.on("/api/currentstate", Connection::getCurrentStateRoute);
|
||||||
server.on("/api/device", Connection::onDeviceRoute);
|
server.on("/api/device", Connection::onDeviceRoute);
|
||||||
|
|
||||||
|
|
||||||
|
LittleFS.begin();
|
||||||
|
|
||||||
|
server.serveStatic("/Icon2.ico", LittleFS, "/Icon2.ico");
|
||||||
|
server.serveStatic("/background.jpg", LittleFS, "/background.jpg");
|
||||||
|
server.serveStatic("/index.js", LittleFS, "/index.js");
|
||||||
|
server.serveStatic("/kksign.png", LittleFS, "/kksign.png");
|
||||||
|
server.serveStatic("/Styles.css", LittleFS, "/Styles.css");
|
||||||
|
|
||||||
|
server.onNotFound([]() {
|
||||||
|
server.send(404, "text/plain", "404: Not Found");
|
||||||
|
});
|
||||||
|
|
||||||
server.begin();
|
server.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +119,14 @@ void Connection::sendResponse(DynamicJsonDocument response) {
|
|||||||
server.send(200, "application/json", serializedJson);
|
server.send(200, "application/json", serializedJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Connection::handleWifiStatus() {
|
||||||
|
if(WiFi.status() != WL_CONNECTED){
|
||||||
|
controller.sendPacket("controller", "wifi_status", "reconnecting");
|
||||||
|
WiFi.disconnect();
|
||||||
|
WiFi.reconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Connection::onApiStatusRoute() {
|
void Connection::onApiStatusRoute() {
|
||||||
// Init Json Document
|
// Init Json Document
|
||||||
DynamicJsonDocument response(jsonBufferSize);
|
DynamicJsonDocument response(jsonBufferSize);
|
||||||
@@ -157,4 +184,11 @@ void Connection::onDeviceRoute() {
|
|||||||
response["msg"] = "Processed command!";
|
response["msg"] = "Processed command!";
|
||||||
|
|
||||||
sendResponse(response);
|
sendResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Connection::onWebpageRoute() {
|
||||||
|
LittleFS.begin();
|
||||||
|
File file = LittleFS.open("/index.html", "r");
|
||||||
|
server.streamFile(file, "text/html");
|
||||||
|
file.close();
|
||||||
}
|
}
|
Reference in New Issue
Block a user