Последовательный вывод:
Connecting to WiFi...
..Wifi connected; getting data ...
[HTTP] GET...
[HTTP] GET... code: 200
15000
4130
GROTCHAMPIGNONS
AGF
0.50
Kg
3.99
St
België
Wi-Fi disconnected and radio turned off.
_Update_Full : 25278999
Ниже показано изображение, когда я отправил фиксированные значения:

После реализации JSON (теперь отображается только ошибка: первая строка; после перезапуска esp32-c3 и обновления текста на экране получите страннее)

Вывод PHP-скрипта на веб-странице:
{"ArtId":"15000","ArtBestelCode":"4130","ArtNaam":"GROTCHAMPIGNONS","ArtMerk":"AGF","ArtAantal":"0.50","ArtInhoud":"Kg","ArtPrijs":"3.99","ArtEenheid":"St","ArtHerkomst":"Belgi\u00eb"}
Я думаю, что делаю что-то не так с объявлением различных переменных, которые я использую.
// base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
// enable or disable GxEPD2_GFX base class
#define ENABLE_GxEPD2_GFX 0
#include
#include
#include
#include
#include
#include
#include
U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
// Set your access point network credentials
const char* ssid = "MySSID";
const char* password = "PASSWD";
const char* hostname = "ESP32-ESL";
// Initialize the client library
WiFiClient client;
// ESP8266 CS(SS)=15,SCL(SCK)=14,SDA(MOSI)=13,BUSY=16,RES(RST)=5,DC=4
#define CS_PIN (10)
#define BUSY_PIN (21)
#define RES_PIN (6)
#define DC_PIN (7)
//Deep sleep defines
#define uS_TO_S_FACTOR 1000000ULL // Microseconds to seconds
#define TIME_TO_SLEEP 60
static const uint8_t EPD_SCK = 20; // to EPD CLK
static const uint8_t EPD_MISO = -1; // Master-In Slave-Out not used, as no data from display
static const uint8_t EPD_MOSI = 5; // to EPD DIN / SDA
// 2.9'' EPD Module
GxEPD2_3C display(GxEPD2_290_C90c(/*CS=5*/ CS_PIN, /*DC=*/ DC_PIN, /*RES=*/ RES_PIN, /*BUSY=*/ BUSY_PIN)); // GDEM029C90 128x296, SSD1680
//Bestelcode -> Code
String Code = "4130";
String Link = "http://192.168.1.250/status/getdata.php?code=";
String FullLink = Link + Code;
//Declare global vars
const char* artId;
const char* artBestelCode;
const char* artNaam;
const char* artMerk;
const char* artAantal;
const char* artInhoud;
const char* artPrijs;
const char* artEenheid;
const char* artHerkomst;
//const char ArtNaam[] = "Tomaat VVP";
//const char ArtMerk[] = "AGF";
//const char ArtInhoud[] = "0,70kg";
//const char ArtPrijsKg[] = "/kg 4,70";
//const char ArtHerkomst[] = "Zie verpakking";
//const char ArtPrijs[] = "3,29";
//const char ArtEenheid[] = "/st";
void setup()
{
Serial.begin(115200);
Serial.println("Booting ESP32-C3 mini ...");
Serial.println("Starting WiFi ...");
GetData();
display.init(115200,true,50,false);
//2 lines below added to make it work on the esp32-C3-mini
SPI.end();
SPI.begin(EPD_SCK, EPD_MISO, EPD_MOSI, CS_PIN);
u8g2Fonts.begin(display); // connect u8g2 procedures to Adafruit GFX
UpdateScreen();
delay(1000);
display.hibernate();
// Set deep sleep timer
//esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
// Enter deep sleep
//esp_deep_sleep_start();
}
void GetData()
{
WiFi.mode(WIFI_STA);
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
WiFi.setHostname(hostname);
WiFi.begin(ssid, password);
Serial.println("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println("Wifi connected; getting data ...");
// configure traged server and url
HTTPClient http;
http.useHTTP10(true);
http.begin(FullLink); //HTTP
Serial.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK) {
//String payload = http.getString();
//Serial.println(payload);
//Json Code
DynamicJsonDocument doc(1024);
DeserializationError error = deserializeJson(doc, http.getStream());
if (error) {
Serial.print(F("deserializeJson() failed with code "));
Serial.println(error.c_str());
return;
}
artId = doc["ArtId"];
artBestelCode = doc["ArtBestelCode"];
artNaam = doc["ArtNaam"];
artMerk = doc["ArtMerk"];
artAantal = doc["ArtAantal"];
artInhoud = doc["ArtInhoud"];
artPrijs = doc["ArtPrijs"];
artEenheid = doc["ArtEenheid"];
artHerkomst = doc["ArtHerkomst"];
Serial.println(artId);
Serial.println(artBestelCode);
Serial.println(artNaam);
Serial.println(artMerk);
Serial.println(artAantal);
Serial.println(artInhoud);
Serial.println(artPrijs);
Serial.println(artEenheid);
Serial.println(artHerkomst);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
WiFi.disconnect(true); // 'true' disconnects from current AP
// Then turn off the Wi-Fi radio completely
WiFi.mode(WIFI_OFF);
Serial.println("Wi-Fi disconnected and radio turned off.");
}
void UpdateScreen()
{
uint16_t bg = GxEPD_WHITE;
uint16_t fg = GxEPD_BLACK;
display.setRotation(1);
u8g2Fonts.setFontMode(1); // use u8g2 transparent mode (this is default)
u8g2Fonts.setFontDirection(0); // left to right (this is default)
u8g2Fonts.setForegroundColor(fg); // apply Adafruit GFX color
u8g2Fonts.setBackgroundColor(bg); // apply Adafruit GFX color
u8g2Fonts.setFont(u8g2_font_profont29_mr); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
int16_t naamtw = u8g2Fonts.getUTF8Width(artNaam); // text box width
int16_t ta = u8g2Fonts.getFontAscent(); // positive
int16_t td = u8g2Fonts.getFontDescent(); // negative; in mathematicians view
int16_t naamth = ta - td; // text box height
uint16_t naamx = (display.width() - naamtw) / 2;
uint16_t naamy = (display.height() - naamth) / 2 + ta;
int16_t prijstw = u8g2Fonts.getUTF8Width(artPrijs); // text box width
int16_t prijsth = ta - td; // text box height
uint16_t prijsx = (display.width() - prijstw) / 2;
uint16_t prijsy = (display.height() - prijsth) / 2 + ta;
display.setFullWindow();
display.firstPage();
do
{
display.fillScreen(bg);
u8g2Fonts.setCursor(naamx, 18);
u8g2Fonts.print(artNaam);
u8g2Fonts.setFont(u8g2_font_profont17_mr);
u8g2Fonts.setCursor(1,40);
u8g2Fonts.print(artMerk);
u8g2Fonts.setCursor(1,60);
//u8g2Fonts.print(ArtBestelCode);
u8g2Fonts.print(Code);
u8g2Fonts.setCursor(1,80);
u8g2Fonts.print((String)"Inh.: " + artAantal + artInhoud);
u8g2Fonts.setFont(u8g2_font_cu12_h_symbols);
u8g2Fonts.setCursor(1,100);
u8g2Fonts.print("€");
u8g2Fonts.setFont(u8g2_font_profont17_mr);
//u8g2Fonts.setCursor(15,100);
//u8g2Fonts.print(ArtPrijsKg);
u8g2Fonts.setCursor(1,120);
u8g2Fonts.print((String)"Herkomst: " + artHerkomst);
u8g2Fonts.setFont(u8g2_font_profont29_mr);
u8g2Fonts.setCursor(220,prijsy);
u8g2Fonts.print(artPrijs);
u8g2Fonts.setFont(u8g2_font_cu12_h_symbols);
u8g2Fonts.setCursor(240,prijsy+20);
u8g2Fonts.print("€");
u8g2Fonts.setFont(u8g2_font_profont17_mr);
u8g2Fonts.setCursor(255,prijsy+20);
u8g2Fonts.print((String)"/" + artEenheid);
//u8g2Fonts.setFont(u8g2_font_profont17_mr);
u8g2Fonts.setCursor(255,prijsy+20);
u8g2Fonts.print(artEenheid);
}
while (display.nextPage());
}
void loop() {
// put your main code here, to run repeatedly:
}
//EDIT-UPDATE//
Я изменил некоторые определения var на int и float, и теперь они каждый раз печатаются прилично; для остальных пока нет решения.
int ArtId = doc["ArtId"]; // 15000
int ArtBestelCode = doc["ArtBestelCode"]; // 4130
float ArtAantal = doc["ArtAantal"]; // 0.5
float ArtPrijs = doc["ArtPrijs"]; // 15.99
Подробнее здесь: https://stackoverflow.com/questions/798 ... ata-output
Мобильная версия