Hirdetés
- Brogyi: CTEK akkumulátor töltő és másolatai
- Lalikiraly: Astra kalandok @ Negyedik rész
- Sub-ZeRo: Euro Truck Simulator 2 & American Truck Simulator 1 (esetleg 2 majd, ha lesz) :)
- sziku69: Szólánc.
- sziku69: Fűzzük össze a szavakat :)
- sh4d0w: Kalózkodás. Kalózkodás?
- sh4d0w: StarWars: Felismerés
- D1Rect: Nagy "hülyétkapokazapróktól" topik
- .LnB: Az új király! The Witcher 3-ról, a magam módján.
- Luck Dragon: Asszociációs játék. :)
-
LOGOUT
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
- Lenovo ThinkPad P15s Gen2 i7-11850H, 16RAM/512SSD/NVIDIA T500/FULLHD IPS, üzleti mobil munkaállomás
- Lenovo Thinkpad T450S, 14" HD+ kijelző, I5-5200U CPU, 12GB DDR3, 128GB SSD, W11, Számla, 1 év ga
- Slot1 alaplap Pentium III processzorral, rammal
- ASUS TUF Z390-PLUS GAMING Eladó!
- Akciós áron, Lenovo ThinkPad X13 Gen 2 - 16GB RAM, 512GB SSD, érintőkijelző, Yoga funkció, Toll
- Honor 400 5G 256GB, Kártyafüggetlen, 1 Év Garanciával
- Redmi 15C / 4/128GB / Kártyafüggetlen / 12Hó Garancia / BONTATLAN NULL Perces
- Azonnali készpénzes nVidia RTX 3000 sorozat videokártya felvásárlás személyesen / csomagküldéssel
- iPhone 13 mini 128GB Starlight -1 ÉV GARANCIA - Kártyafüggetlen, MS3831, 100% Akkumulátor
- Telefon felvásárlás!! Samsung Galaxy S21/Samsung Galaxy S21+/Samsung Galaxy S21 Ultra
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
ekkold
