Hirdetés
- Bemutatkozott a Poco X7 és X7 Pro
- Huawei Watch GT 6 és GT 6 Pro duplateszt
- Poco F7 – bajnokesélyes
- Samsung Galaxy Watch (Tizen és Wear OS) ingyenes számlapok, kupon kódok
- Xiaomi 15T - reakció nélkül nincs egyensúly
- Samsung Galaxy A56 - megbízható középszerűség
- Honor Magic6 Pro - kör közepén számok
- A vártnál korábban érkezhet a Xiaomi 17 Ultra
- Yettel topik
- Samsung Gear S3 - második kör
-
Mobilarena
Arduino hardverrel és szoftverrel foglakozó téma. Minden mikrovezérlő ami arduinoval programozható, és minden arduino program, board, és hardverrel kapcsolatos kérdések helye.
Új hozzászólás Aktív témák
-
Tomika86
senior tag
válasz
Janos250
#17917
üzenetére
Már szerkeszteni nem tudtam
Szeretnék egyet kérdezni, ha tud valaki segíteni ebben.
Van ebben a könyvtárban webserveres példaprogram.Viszont én már az ESP32 ota feltöltéshez is azt használok, ebbe belezavar ha most a kijelzőét is beletenném a programba?
Ezek első blikkre mindkettőben ott vannak
MDNS.begin(host);
WebServer server(80);
server.begin();
server.handleClient();Nextion upload webserver
#include <FS.h>
#include <WiFi.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <SPIFFS.h>
#include <ESPNexUpload.h>
/*
ESP32 uses Hardware serial RX:16, TX:17
Serial pins are defined in the ESPNexUpload.cpp file
*/
const char* ssid = "your_wlan_ssid";
const char* password = "your_wlan_password";
const char* host = "nextion";
// used only internally
int fileSize = 0;
bool result = true;
// init Nextion object
ESPNexUpload nextion(115200);
WebServer server(80);
String getContentType(String filename){
if(server.hasArg(F("download"))) return F("application/octet-stream");
else if(filename.endsWith(F(".htm"))) return F("text/html");
else if(filename.endsWith(".html")) return F("text/html");
else if(filename.endsWith(F(".css"))) return F("text/css");
else if(filename.endsWith(F(".js"))) return F("application/javascript");
else if(filename.endsWith(F(".png"))) return F("image/png");
else if(filename.endsWith(F(".gif"))) return F("image/gif");
else if(filename.endsWith(F(".jpg"))) return F("image/jpeg");
else if(filename.endsWith(F(".ico"))) return F("image/x-icon");
else if(filename.endsWith(F(".xml"))) return F("text/xml");
else if(filename.endsWith(F(".pdf"))) return F("application/x-pdf");
else if(filename.endsWith(F(".zip"))) return F("application/x-zip");
else if(filename.endsWith(F(".gz"))) return F("application/x-gzip");
return F("text/plain");
}
bool handleFileRead(String path) { // send the right file to the client (if it exists)
Serial.print("handleFileRead: " + path);
if (path.endsWith("/")) path += "index.html"; // If a folder is requested, send the index file
String contentType = getContentType(path); // Get the MIME type
String pathWithGz = path + ".gz";
if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) { // If the file exists, either as a compressed archive, or normal
if (SPIFFS.exists(pathWithGz)) // If there's a compressed version available
path += ".gz"; // Use the compressed verion
File file = SPIFFS.open(path, "r"); // Open the file
size_t sent = server.streamFile(file, contentType); // Send it to the client
file.close(); // Close the file again
Serial.println(String("\tSent file: ") + path);
return true;
}
Serial.println(String("\tFile Not Found: ") + path); // If the file doesn't exist, return false
return false;
}
// handle the file uploads
bool handleFileUpload(){
HTTPUpload& upload = server.upload();
// Check if file seems valid nextion tft file
if(!upload.filename.endsWith(F(".tft"))){
server.send(500, F("text/plain"), F("ONLY TFT FILES ALLOWED\n"));
return false;
}
if(!result){
// Redirect the client to the failure page
server.sendHeader(F("Location"),"/failure.html?reason=" + nextion.statusMessage);
server.send(303);
return false;
}
if(upload.status == UPLOAD_FILE_START){
Serial.println(F("\nFile received. Update Nextion..."));
// Prepare the Nextion display by seting up serial and telling it the file size to expect
result = nextion.prepareUpload(fileSize);
if(result){
Serial.print(F("Start upload. File size is: "));
Serial.print(fileSize);
Serial.println(F(" bytes"));
}else{
Serial.println(nextion.statusMessage + "\n");
return false;
}
}else if(upload.status == UPLOAD_FILE_WRITE){
// Write the received bytes to the nextion
result = nextion.upload(upload.buf, upload.currentSize);
if(result){
Serial.print(F("."));
}else{
Serial.println(nextion.statusMessage + "\n");
return false;
}
}else if(upload.status == UPLOAD_FILE_END){
// End the serial connection to the Nextion and softrest it
nextion.end();
Serial.println("");
//Serial.println(nextion.statusMessage);
return true;
}
}
void setup(void){
Serial.begin(115200);
Serial.println(F("\nRunning UploadServer Example\n"));
Serial.setDebugOutput(false);
if(!SPIFFS.begin()){
Serial.println(F("An Error has occurred while mounting SPIFFS"));
Serial.println(F("Did you upload the data directory that came with this example?"));
return;
}
//WIFI INIT
Serial.printf("Connecting to %s\n", ssid);
if (String(WiFi.SSID()) != String(ssid)) {
WiFi.begin(ssid, password);
}
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.print(F("\nConnected! IP address: "));
Serial.println(WiFi.localIP());
MDNS.begin(host);
Serial.print(F("http://"));
Serial.print(host);
Serial.println(F(".local"));
//SERVER INIT
server.on("/", HTTP_POST, [](){
Serial.println(F("Succesfully updated Nextion!\n"));
// Redirect the client to the success page after handeling the file upload
server.sendHeader(F("Location"),F("/success.html"));
server.send(303);
return true;
},
// Receive and save the file
handleFileUpload
);
// receive fileSize once a file is selected (Workaround as the file content-length is of by +/- 200 bytes. Known issue: https://github.com/esp8266/Arduino/issues/3787)
server.on("/fs", HTTP_POST, [](){
fileSize = server.arg(F("fileSize")).toInt();
server.send(200, F("text/plain"), "");
});
// called when the url is not defined here
// use it to load content from SPIFFS
server.onNotFound([](){
if(!handleFileRead(server.uri()))
server.send(404, F("text/plain"), F("FileNotFound"));
});
server.begin();
Serial.println(F("\nHTTP server started"));
}
void loop(void){
server.handleClient();
}
Új hozzászólás Aktív témák
- VGA kibeszélő offtopik
- Haditechnika, harcászat
- Motorolaj, hajtóműolaj, hűtőfolyadék, adalékok és szűrők topikja
- Brogyi: CTEK akkumulátor töltő és másolatai
- Haladó fotósok digitális fényképei
- NVIDIA GeForce RTX 5070 / 5070 Ti (GB205 / 203)
- Kuponkunyeráló
- Milyen notebookot vegyek?
- Arc Raiders
- D1Rect: Nagy "hülyétkapokazapróktól" topik
- További aktív témák...
- SNES Edge Sharpener (Enhancer) modkit
- ÚJ GIGABYTE A16 3VH - 16" WUXGA 165Hz - Ryzen 7 260 - 16GB - 1TB - Win11 - RTX 5060 - 3 év garancia
- Dell Latitude FHD IPS Intel core i5-1345u 16GB DDR4 256gb SSD WIN11
- Surface STUDIO AIO PC 28col 4k TOUCH / Intel i7 /32gb ram / 512NvMe + 1TB / NVIDIA 4gb dedikált
- Asztali Gamer Gép Garanciális Ryzen 7-7800x3d 4070 Super
- ÁRGARANCIA!Épített KomPhone Ryzen 7 5700X 16/32/64GB RAM RTX 3060 12GB GAMER PC termékbeszámítással
- FELVÁSÁRLÁS A GYŐRÚJBARÁTI BOLTUNKBAN!
- Készpénzes / Utalásos Videokártya és Hardver felvásárlás! Személyesen vagy Postával!
- Bontatlan Lenovo T14S WUXGA Touch Ryzen5 Pro 7540U 16GB 256GB Radeon 740M Win11 Pro 3év Garancia
- GYÖNYÖRŰ iPhone 12 Mini 64GB Black -1 ÉV GARANCIA - Kártyafüggetlen, MS3648, 96% Akkumulátor
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: NetGo.hu Kft.
Város: Gödöllő
ekkold

