Commit
This commit is contained in:
parent
d0cf1c5d07
commit
ed404edcbd
154
panel.ino
154
panel.ino
@ -3,7 +3,9 @@
|
|||||||
#include <WebServer.h>
|
#include <WebServer.h>
|
||||||
#include <DMD32.h>
|
#include <DMD32.h>
|
||||||
#include <fonts/Font_BOLD.h>
|
#include <fonts/Font_BOLD.h>
|
||||||
#include <FS.h>
|
#include <SPIFFS.h>
|
||||||
|
#include <ESPAsyncWebServer.h>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
//-------------------------------------------------//
|
//-------------------------------------------------//
|
||||||
|
|
||||||
//----------------settings panel----------------//
|
//----------------settings panel----------------//
|
||||||
@ -14,12 +16,12 @@ DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
|
|||||||
//----------------------------------------------//
|
//----------------------------------------------//
|
||||||
|
|
||||||
//----------------settings local wifi----------------//
|
//----------------settings local wifi----------------//
|
||||||
const char* ssid = "SKBKIT"; //edit for your local wifi
|
const char *ssid = "SKBKIT"; //edit for your local wifi
|
||||||
const char* password = "skbkit2024"; //edit for your local wifi
|
const char *password = "skbkit2024"; //edit for your local wifi
|
||||||
//---------------------------------------------------//
|
//---------------------------------------------------//
|
||||||
|
|
||||||
//----------------settings web server----------------//
|
//----------------settings web server----------------//
|
||||||
WebServer server(80);
|
AsyncWebServer server(80);
|
||||||
IPAddress staticIP(10, 131, 170, 4); //edit for your local ip
|
IPAddress staticIP(10, 131, 170, 4); //edit for your local ip
|
||||||
IPAddress gateway(10, 131, 170, 1);
|
IPAddress gateway(10, 131, 170, 1);
|
||||||
IPAddress subnet(255, 255, 255, 0);
|
IPAddress subnet(255, 255, 255, 0);
|
||||||
@ -27,7 +29,7 @@ IPAddress subnet(255, 255, 255, 0);
|
|||||||
|
|
||||||
//----------------other variables----------------//
|
//----------------other variables----------------//
|
||||||
String displayText = "Привет из СКБ \"КИТ\""; //change the default label
|
String displayText = "Привет из СКБ \"КИТ\""; //change the default label
|
||||||
hw_timer_t* timer = NULL;
|
hw_timer_t *timer = NULL;
|
||||||
bool panel = true;
|
bool panel = true;
|
||||||
//-----------------------------------------------//
|
//-----------------------------------------------//
|
||||||
|
|
||||||
@ -43,6 +45,8 @@ void setup() {
|
|||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
dmd.selectFont(Font_BOLD);
|
dmd.selectFont(Font_BOLD);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
|
SPIFFS.begin(true);
|
||||||
|
pinMode(22, OUTPUT);
|
||||||
|
|
||||||
//---Configured WebServer---//
|
//---Configured WebServer---//
|
||||||
if (!WiFi.config(staticIP, gateway, subnet)) {
|
if (!WiFi.config(staticIP, gateway, subnet)) {
|
||||||
@ -53,11 +57,30 @@ void setup() {
|
|||||||
//--------------------------//
|
//--------------------------//
|
||||||
|
|
||||||
//---Start file system---//
|
//---Start file system---//
|
||||||
// if(!SPIFFS.begin()){
|
// File file = SPIFFS.open("/output.txt", "r");
|
||||||
// Serial.print("An occurred ERROR");
|
// if(!file){Serial.println("file open failed");}
|
||||||
// log_e("OCCURRED ERROR");
|
// Serial.println("Содержимое файла:");
|
||||||
|
// while(file.available()){
|
||||||
|
// Serial.write(file.read());
|
||||||
|
// }
|
||||||
|
// Serial.println();
|
||||||
|
// file.close();
|
||||||
|
|
||||||
|
// File root = SPIFFS.open("/");
|
||||||
|
// if(!root){
|
||||||
|
// Serial.println("Ошибка открытия директории");
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
// if(!root.isDirectory()){
|
||||||
|
// Serial.println("Не является директорией!");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// File file = root.openNextFile();
|
||||||
|
// while(file){
|
||||||
|
// Serial.println(file.name());
|
||||||
|
// file = root.openNextFile();
|
||||||
|
//}
|
||||||
//-----------------------//
|
//-----------------------//
|
||||||
|
|
||||||
//---Start the WiFi---//
|
//---Start the WiFi---//
|
||||||
@ -69,59 +92,73 @@ void setup() {
|
|||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
//--------------------//
|
//--------------------//
|
||||||
|
|
||||||
//---Main page for edit text---//
|
|
||||||
server.on("/", HTTP_GET, []() {
|
|
||||||
panel = true;
|
|
||||||
server.send(200, "text/html",
|
|
||||||
"<!DOCTYPE html>"
|
|
||||||
"<html lang='ru'>"
|
|
||||||
"<head>"
|
|
||||||
"<meta charset='UTF-8'>"
|
|
||||||
"<title>Panel text</title>"
|
|
||||||
"</head>"
|
|
||||||
"<body>"
|
|
||||||
"<h2>Введите текст для отображения на экране:</h2>"
|
|
||||||
"<form action='/api/text' method='post'><input name='text'><input type='submit'></form>"
|
|
||||||
"</body>"
|
|
||||||
"</html>");
|
|
||||||
});
|
|
||||||
//-----------------------------//
|
|
||||||
|
|
||||||
//---Request to check the status of the panel---//
|
//---Request to check the status of the panel---//
|
||||||
server.on("/api/led", HTTP_GET, [](){
|
server.on("/api/led", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
if(panel){
|
request->send(200, "application/json", panel ? "{\"state\": \"true\"}" : "{\"state\": \"false\"}");
|
||||||
server.send(200, "application/json", "{\"state\": \"true\"}");
|
|
||||||
}else if(!panel){
|
|
||||||
server.send(200, "application/json", "{\"state\": \"false\"}");
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
//----------------------------------------------//
|
//----------------------------------------------//
|
||||||
|
|
||||||
//---Request to change the status of the panel---//
|
//---Request to change the status of the panel---//
|
||||||
server.on("/api/led", HTTP_POST, [](){
|
/*server.on("/api/led", HTTP_POST,
|
||||||
String panelState = server.arg("plain");
|
[](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total)
|
||||||
Serial.println(panelState);
|
{
|
||||||
|
AsyncWebServerRequest *req = request;
|
||||||
|
Serial.println(String("data=") + (char*)data);
|
||||||
|
// // Serial.print(request);
|
||||||
|
|
||||||
if (panelState == "{\"led\": \"on\"}"){
|
// if (req->hasParam("plain", true)) {
|
||||||
Serial.println("Panel on!");
|
// String panelState = req->getParam("panel", true)->value();
|
||||||
panel = true;
|
// Serial.println(panelState);
|
||||||
//scanDisplayBySPI();
|
|
||||||
}else if(panelState == "{\"led\": \"off\"}"){
|
// if (panelState == "on") {
|
||||||
|
// Serial.println("Panel on!");
|
||||||
|
// displayText = "";
|
||||||
|
// panel = true;
|
||||||
|
// } else if (panelState == "off") {
|
||||||
|
// panel = false;
|
||||||
|
// Serial.println("Panel off!");
|
||||||
|
// digitalWrite(22, LOW);
|
||||||
|
// dmd.clearScreen(1);
|
||||||
|
// displayText = "";
|
||||||
|
// Serial.println("Screen clear");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
req->send(200, "text/html", "");
|
||||||
|
});*/
|
||||||
|
|
||||||
|
server.on(
|
||||||
|
"/api/led", HTTP_POST,
|
||||||
|
[](AsyncWebServerRequest *request) {
|
||||||
|
// Serial.println("1");
|
||||||
|
// Serial.println(request->url() );
|
||||||
|
// Serial.println(request->method());
|
||||||
|
},
|
||||||
|
[](AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final) {
|
||||||
|
//Serial.println("2");
|
||||||
|
},
|
||||||
|
[](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {
|
||||||
|
String dataRequest = String((char *)data);
|
||||||
|
Serial.println(dataRequest);
|
||||||
|
if (dataRequest == "{\"panel\" : \"on\"}") {
|
||||||
|
Serial.println("Panel on");
|
||||||
|
} else if (dataRequest == "{\"panel\" : \"off\"}") {
|
||||||
panel = false;
|
panel = false;
|
||||||
Serial.println("Panel off!");
|
Serial.println("Panel off!");
|
||||||
SPI.end();
|
digitalWrite(22, LOW);
|
||||||
|
dmd.clearScreen(1);
|
||||||
|
displayText = "";
|
||||||
|
Serial.println("Screen clear");
|
||||||
}
|
}
|
||||||
server.send(200, "text/html", "");
|
request->send(200, "text/html", "");
|
||||||
});
|
});
|
||||||
//-----------------------------------------------//
|
//-----------------------------------------------//
|
||||||
|
|
||||||
//---A text modification request---//
|
//---A text modification request---//
|
||||||
server.on("/api/text", HTTP_POST, []() {
|
server.on("/api/text", HTTP_POST, [](AsyncWebServerRequest *request) {
|
||||||
panel = true;
|
if (request->hasParam("text", true)) {
|
||||||
if (server.hasArg("text")) {
|
displayText = request->getParam("text", true)->value();
|
||||||
displayText = server.arg("text");
|
|
||||||
}
|
}
|
||||||
server.send(200, "text/html; charset=UTF-8",
|
request->send(200, "text/html; charset=UTF-8",
|
||||||
"<html><body><h2>Text set to:</h2><p>" + displayText + "</p></body></html>");
|
"<html><body><h2>Text set to:</h2><p>" + displayText + "</p></body></html>");
|
||||||
});
|
});
|
||||||
//---------------------------------//
|
//---------------------------------//
|
||||||
@ -140,23 +177,22 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
server.handleClient(); //Processing requests from the client
|
|
||||||
|
|
||||||
//---Screen cleaning and text output---//
|
//---Screen cleaning and text output---//
|
||||||
// dmd.clearScreen(true);
|
dmd.clearScreen(true);
|
||||||
// dmd.drawMarquee(displayText.c_str(), displayText.length(), (32 * DISPLAYS_ACROSS) - 1, 0);
|
dmd.drawMarquee(displayText.c_str(), displayText.length(), (32 * DISPLAYS_ACROSS) - 1, 0);
|
||||||
//-------------------------------------//
|
//-------------------------------------//
|
||||||
|
|
||||||
// long start = millis();
|
long start = millis();
|
||||||
// long timer = start;
|
long timer = start;
|
||||||
// boolean ret = false;
|
boolean ret = false;
|
||||||
|
|
||||||
//---Scrolling text---//
|
//---Scrolling text---//
|
||||||
// while (!ret) {
|
while (!ret) {
|
||||||
// if ((timer + 30) < millis()) {
|
if ((timer + 30) < millis()) {
|
||||||
// ret = dmd.stepMarquee(-1, 0); // Прокрутка текста
|
ret = dmd.stepMarquee(-1, 0); // Прокрутка текста
|
||||||
// timer = millis();
|
timer = millis();
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//--------------------//
|
//--------------------//
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user