- Mobil flották
- Yettel topik
- Egy szenzor, két zoomkamera: újraírta a Huawei a mobilfotózás történetét
- Bemutatkozott a Poco X7 és X7 Pro
- Xiaomi 11 Lite 5G NE (lisa)
- Samsung Galaxy A56 - megbízható középszerűség
- Samsung Galaxy S22 Ultra - na, kinél van toll?
- Google Pixel topik
- Samsung Galaxy A55 - új év, régi stratégia
- Milyen okostelefont vegyek?
-
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
- AMD Ryzen 9 / 7 / 5 9***(X) "Zen 5" (AM5)
- Path of Exile (ARPG)
- TCL LCD és LED TV-k
- Milyen TV-t vegyek?
- Milyen légkondit a lakásba?
- Radeon RX 9060 XT: Ezt aztán jól meghúzták
- Teljes verziós játékok letöltése ingyen
- Mobil flották
- Epson nyomtatók
- Kazy Computers - Fehérvár - Megbízható?
- További aktív témák...
- RTX 4080 SUPER,16GB. Ryzen 7 7800X3D, 32 RAM Fury RGB! Garancia!
- Asztali PC , i7 9700K , RX 5700 XT , 32GB DDR4 , 500GB NVME , 1TB HDD
- Dell Inspiron 5406 2-in-1i5-1135G7 16GB DDR4 3200 512GB NVME 14" FHD Érintőkijelző W11Pro
- Eladó MacBook Pro 14" M1 Pro (2021) 16/512 99% akku Makulátlan állapotban!
- Újszeru GIGABYTE G5 - 15.6" FullHD 144Hz - i7-13620H - 48GB - 1TB - RTX 4050 - Win11 - 1,5 év gari
- Bomba ár! HP EliteBook 820 G2 - i5-5GEN I 8GB I 256GB SSD I 12,5" FHD I Cam I W10 I Garancia!
- Fém, összecsukható és kihúzható fotó állvány eladó
- BESZÁMÍTÁS! 16GB (2x8) G.Skill Trident Z RGB 4266MHz DDR4 memória garanciával hibátlan működéssel
- Apple iPhone 13Pro 128GB Kártyafüggetlen 1Év Garanciával
- LG 55G4 - 55" OLED evo - 4K 144Hz & 0.1ms - MLA Plus - 3000 Nits - NVIDIA G-Sync - FreeSync Premium
Állásajánlatok
Cég: CAMERA-PRO Hungary Kft
Város: Budapest
Cég: PC Trade Systems Kft.
Város: Szeged