Hey @Blynk_Coeur did you get nextion HTTP upload working? Do you have a video or sources for me to look at?
Hey @daveblynk !
This is my code to upload nextion through HTTP
I used ESP8266 and I can upload at 57600, I tried 115200 but unfortunately it was unsuccessful .
I think it is due to the limit of ESP8266’s virtual serial port.
May be ESP32 is better because there are three serial ports on it.
const char* fwUrlBase = "http://192.168.0.100:8000/name_of_nextion_file.tft"; // python server needed
const char* ssid = "SSID"; /// put your AP SSID here
const char* password = "PASS"; /// put your AP PASSWORD
/// HTTP OTA dependencies ///
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#include <WiFiClient.h>
WiFiClient client;
#define NxBaud 57600
#define SrlBaud 115200
#include <ESPNexUpload.h>
bool updated = false;
int count = 0;
void setup() {
Serial.begin(SrlBaud);
Serial.println("Booting...");
// initialize ESPNexUpload
ESPNexUpload nextion(NxBaud);
WiFi.begin(ssid, password);
if (WiFi.status() != WL_CONNECTED) {
Serial.println("Connecting to Wifi AP...");
for ( int i = 0; i < 300; i++) { /// try to connect to WiFi for max 30s
if (WiFi.status() == WL_CONNECTED) {
Serial.printf("it is connected after %d seconds", (i / 10));
break;
}
delay(100);
}
}
if (WiFi.status() == WL_CONNECTED) {
//if you get here you have connected to the WiFi
Serial.println("\nconnected...yesss! :)");
checkForUpdates() ;
} else {
Serial.println("TimeOut! Not Connected even after 10 Seconds trying...\n *** Something wrong happened. It did not connected... *** ");
}
}
void loop() {
//ArduinoOTA.handle();
}
void checkForUpdates() {
Serial.println("http start ... ");
HTTPClient httpClient;
httpClient.begin( client, fwUrlBase );
int httpCode = httpClient.GET();
int contentLength = httpClient.getSize();
Serial.print("httpCode ");
Serial.println (httpCode);
Serial.print("contentLength ");
Serial.println (contentLength);
if ( httpCode == 200 ) {
// Update the nextion display
Serial.println("File received. Update Nextion...");
bool result;
// initialize ESPNexUpload
ESPNexUpload nextion(57600);
//ESPNexUpload nextion(74880);
// Progress upload.....
nextion.setUpdateProgressCallback([]() {
count++;
Serial.print(count / 10);
Serial.println(" %");
});
// setup serial connection, send update command and send the expected update size
result = nextion.prepareUpload(contentLength);
if (!result) {
Serial.println("Error: " + nextion.statusMessage);
} else {
Serial.print(F("Start upload. File size is: "));
Serial.print(contentLength);
Serial.println(F(" bytes"));
// Upload the received byte Stream to the nextion
result = nextion.upload(*httpClient.getStreamPtr());
if (result) {
updated = true;
Serial.println("\nSuccesfully updated Nextion!");
} else {
Serial.println("\nError updating Nextion: " + nextion.statusMessage);
}
// end: wait(delay) for the nextion to finish the update process, send nextion reset command and end the serial connection to the nextion
nextion.end();
}
} else {
// else print http error
Serial.println(String("HTTP error: ") + httpClient.errorToString(httpCode).c_str());
}
httpClient.end();
Serial.println("Closing connection\n");
}
/// End of main function that performs HTTP OTA ///
Did you mess with iotappstory? They have a OTA update for Nextion that isn’t well documented but looks rather simple If it is like the esp OTA. (Maybe you like the hard way🤷‍♂️) I have been playing with their OTA for my D1 Minis but 2 out of 3 keep loosing their certificates. (That’s a different topic) My displays are sitting on the other side of the pond waiting for me but I’m trying to learn some stuff before I get there. (Difficult for me).
I’m too lazy
And I use Python server, because I use it for blynk images, it’s really easy to update Nextion.
Work in progress …
New Smart thermostat with forecast station and fuel tank control
Wifi signal strength and Blynk connection control
NodeMcu - Nextion 3.5" - openweathermap API - DHT22 - HC-SR04 Ultrasonic Sensor
I finally got my display the other day. I have done some playing around and I am getting sick of popping the SD card in and out to upload new layouts. Do you have a tutorial that you followed to do the http upload for the screen?
Papa google let me down there is one video that looks like it uses http OTA but it is in French. Sadly I don’t know French.
I’m french
What do you need to know David ?
I think Dave was wanting a step by step guide to getting OTA updates for the Nextion working.
Is this something you could do?
Pete.
Ya that would be awesome. However I realize I probably need to understand http OTA first. (Will work on that when I have time.) It will probably be clear when I have that figured out. Some of my questions right now…
This code runs on the esp and not the display, correct?
This code can be mixed in with the regular code and set on a timer to send to the device?
Or does the device call out to the esp to trigger this code?
Also I don’t have my own website, it looks like your are pulling a file from your local server. Is it also possible to pull a file from a Google drive? Provided it is shared properly?
Yes I know “mon ami” our local town is French and Canada is bilingual but sad to say what I studied in school I have mostly lost.
Another comment your design skills are amazing. Do you use free software, if so which one?
I’m guessing that @Blynk_Coeur is a Photoshop guy, but unless you’re really proficient with PS it’s a steep learning curve, especially for this type of thing.
Although I’m pretty handy with PS myself, I do my Nextion screen layouts with PowerPoint and export the elements as image files. I find it makes it easier to clone a page and keep everything in the same location, but then just change a few elements. If you don’t do that then objects jump around all over the screen.
Having said that, I’m still using an old version of the Nextion editor and use a different Nextion library, so maybe my approach isn’t the best nowadays.
Pete.
I’m using PS, but you can use gimp as well !
Are you talking about my Thermostat?
I mix both, Nextion code and ESP code
I don’t use any nextion library, I use basic command to write and read nextion serial port.
The nextion library gave me a headache
My last update
No that stuff is all in my scope. It’s the http OTA to nextion that I’m have a hard time finding info on.
This my running code, you have to install python server
const char* fwUrlBase = "http://192.168.0.100:8000/nextion.tft"; // python server - file to upload
const char* ssid = "your SSID"; /// put your AP SSID here
const char* password = "your key"; /// put your AP PASSWORD
/// HTTP OTA dependencies ///
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#include <WiFiClient.h>
WiFiClient client;
#define NxBaud 57600
#define SrlBaud 115200
#include <ESPNexUpload.h>
bool updated = false;
int count = 0;
void setup() {
Serial.begin(SrlBaud);
Serial.println("Booting...");
// initialize ESPNexUpload
ESPNexUpload nextion(NxBaud);
WiFi.begin(ssid, password);
if (WiFi.status() != WL_CONNECTED) {
Serial.println("Connecting to Wifi AP...");
for ( int i = 0; i < 300; i++) { /// try to connect to WiFi for max 30s
if (WiFi.status() == WL_CONNECTED) {
Serial.printf("it is connected after %d seconds", (i / 10));
break;
}
yield();
delay(100);
}
}
if (WiFi.status() == WL_CONNECTED) {
//if you get here you have connected to the WiFi
Serial.println("\nconnected...yesss! :)");
checkForUpdates() ;
} else {
Serial.println("TimeOut! Not Connected even after 10 Seconds trying...\n *** Something wrong happened. It did not connected... *** ");
}
}
void loop() {
//ArduinoOTA.handle();
}
void checkForUpdates() {
Serial.println("http start ... ");
HTTPClient httpClient;
httpClient.begin( client, fwUrlBase );
int httpCode = httpClient.GET();
int contentLength = httpClient.getSize();
Serial.print("httpCode ");
Serial.println (httpCode);
Serial.print("contentLength ");
Serial.println (contentLength);
if ( httpCode == 200 ) {
// Update the nextion display
Serial.println("File received. Update Nextion...");
bool result;
// initialize ESPNexUpload
ESPNexUpload nextion(NxBaud );
// Progress upload.....
nextion.setUpdateProgressCallback([]() {
count++;
Serial.print(count / 10);
Serial.println(" %");
});
// setup serial connection, send update command and send the expected update size
result = nextion.prepareUpload(contentLength);
if (!result) {
Serial.println("Error: " + nextion.statusMessage);
} else {
Serial.print(F("Start upload. File size is: "));
Serial.print(contentLength);
Serial.println(F(" bytes"));
// Upload the received byte Stream to the nextion
result = nextion.upload(*httpClient.getStreamPtr());
if (result) {
updated = true;
Serial.println("\nSuccesfully updated Nextion!");
} else {
Serial.println("\nError updating Nextion: " + nextion.statusMessage);
}
// end: wait(delay) for the nextion to finish the update process, send nextion reset command and end the serial connection to the nextion
nextion.end();
}
} else {
// else print http error
Serial.println(String("HTTP error: ") + httpClient.errorToString(httpCode).c_str());
}
httpClient.end();
Serial.println("Closing connection\n");
}
/// End of main function that performs HTTP OTA ///
Ok I’ll fill in some of my own blanks here.
1.After installing Python (I ran the install for 3.x.x but I can’t seem to find it on my system) open CMD and run “python”.
2. My version ended up with 2.7.x
3. For 2.x.x versions try typing “python -m SimpleHTTPServer 8000” in the CMD window.
4. Then open a browser and type your computers ip address followed with : and the port 8000 (example http://192.168.0.111:8000/)
5. You should get a file explorer like page in the browser. Navigate to the file and copy the file path and paste into @Blynk_Coeur 's code above.
6. Install the supporting libraries I used GitHub - Nredor/ESPNexUpload: ESP8266 and ESP32 compatible library for uploading GUI (.tft) file to Nextion display over the air. for the EspNexUpload.
EDIT !!! 6.1 -Find the ESPNexUpload.cpp and take note of the TX and RX pins in the Library. Also note that they are inverted from the display RX to TX and vice versa-
7. Upload to the ESP.
Here is where I run into problems…
I get the following error in the serial monitor.
Connecting to Wifi AP...
it is connected after 0 seconds
connected...yesss! :)
http start ...
httpCode 200
contentLength 1458140
File received. Update Nextion...
Error: get baudrate error
Closing connection
And this in the CMD window…
Serving HTTP on 0.0.0.0 port 8000 ...
192.168.0.111 - - [10/Feb/2021 15:48:01] "GET / HTTP/1.1" 200 -
192.168.0.228 - - [10/Feb/2021 15:54:45] "GET /Documents/Nextion/Weather.tft HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('192.168.0.228', 53044)
Traceback (most recent call last):
File "C:\Python27\lib\SocketServer.py", line 293, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python27\lib\SocketServer.py", line 657, in __init__
self.finish()
File "C:\Python27\lib\SocketServer.py", line 716, in finish
self.wfile.close()
File "C:\Python27\lib\socket.py", line 283, in close
self.flush()
File "C:\Python27\lib\socket.py", line 307, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine
----------------------------------------
Hi Dave.
You have to run nextion editor to set Baud to 57600 with the cmd line.
I tried to upload tft at 115000 but it failed.
I didn’t with the cmd line. I did bauds in “preinitialize” and when put the sd card in it show the correct baud. I tried all the way down to 9600.