Hello everybody.
(Sorry for my english I’m a foreigner)
Using Platformio I’m almost able to display whatever widget I want but I’m struggling with a picture.
FYI lodePNG is set to 1 into lvconf.h
What do you want to achieve?
Just want to display a PNG picture provided by a weather forecast website.
What have you tried so far?
Tried to download to LittleFS and display it => no success at all
Tried tu download to a buffer and the display it (code below) all I have is ‘PNG’ displayed like a watermark.
Code to reproduce
#include "main.h"
#include <Arduino.h>
#include <WiFi.h>
#include <esp_wifi.h>
#include <HTTPClient.h>
#include <esp32_smartdisplay.h>
#include <lvgl.h>
// URL de l’image PNG
const char *url_png = "https://prevision-meteo.ch/style/images/icon/faiblement-nuageux-big.png";
// Buffer PNG
std::vector<uint8_t> png_buf;
bool download_png(const char *url)
{
HTTPClient http;
WiFiClientSecure client;
client.setInsecure(); // Pour HTTPS sans certificat
if (!http.begin(client, url))
{
Serial.println("HTTP begin failed");
return false;
}
int httpCode = http.GET();
if (httpCode != 200)
{
Serial.printf("HTTP GET failed, code: %d\n", httpCode);
http.end();
return false;
}
int len = http.getSize();
if (len <= 0)
len = 1024 * 10; // fallback
Serial.print("image len: ");
Serial.println(len);
png_buf.resize(len);
WiFiClient *stream = http.getStreamPtr();
int idx = 0;
while (http.connected() && idx < len)
{
while (stream->available())
{
png_buf[idx++] = stream->read();
}
}
png_buf.resize(idx); // Ajuste à taille réelle
http.end();
return true;
}
void setup()
{
Serial.begin(115200);
delay(500);
// Connexion WiFi
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi connected!");
// Initialisation SmartDisplay / LVGL
smartdisplay_init();
lv_obj_t *scr = lv_scr_act();
// Création de l'objet image
lv_obj_t *img = lv_img_create(scr);
lv_obj_center(img);
// Téléchargement PNG
if (!download_png(url_png))
{
Serial.println("PNG download failed!");
return;
}
// Affectation du buffer PNG à l'objet image
lv_img_set_src(img, png_buf.data());
Serial.print( (const char*)png_buf.data());
Serial.println("PNG displayed!");
}
void loop()
{
lv_timer_handler(); // Gestion des tâches LVGL
delay(5);
}
Screenshot and/or video
unfortunately nono
Environment
- MCU/MPU/Board: ESP32S3
- **LVGL version:**9.4
Thanks for your help