/*
* Sciensano Virus Barometer voor Inkplate 5
* Aangepaste versie van de Wokwi ESP32 + 2.9" E-Paper code.
*/
// --- KERN BIBLIOTHEKEN (blijven hetzelfde) ---
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
// --- DISPLAY BIBLIOTHEEK (VERANDERD) ---
#include "Inkplate.h" // Gebruik de Inkplate bibliotheek
// --- CONFIGURATIE (blijft hetzelfde) ---
const char* ssid = "Wokwi-GUEST"; // Of je eigen WiFi SSID
const char* password = ""; // Of je eigen WiFi wachtwoord
const char* api_key = "45c5e5d376dc2689f99154c759fcdb3b6043bcda53e16b7f";
const char* api_endpoint = "https://iotsolutions.be/api/iot/virus-data";
// --- DISPLAY OBJECT (VERANDERD) ---
// Initialiseer het Inkplate object.
// INKPLATE_3BIT activeert 8 grijstinten, perfect voor dit project!
Inkplate display(INKPLATE_3BIT);
// Pin definities zijn niet meer nodig. De bibliotheek regelt dit.
// Hulpfunctie om tekst te centreren (blijft grotendeels hetzelfde)
void drawCentered(String text, int y) {
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(text, 0, 0, &tbx, &tby, &tbw, &tbh);
uint16_t x = (display.width() - tbw) / 2 - tbx;
display.setCursor(x, y);
display.print(text);
}
void setup() {
Serial.begin(115200);
Serial.println("Sciensano E-Paper Barometer voor Inkplate 5 opstarten...");
// --- DISPLAY INITIALISATIE (VERANDERD) ---
display.begin(); // Eenvoudige initialisatie
showLoadingScreen("Verbinden met WiFi...");
connectWiFi();
fetchDataAndUpdate("België");
promptForInput();
}
void loop() {
if (Serial.available() > 0) {
String input = Serial.readStringUntil('\n');
input.trim();
if (input.length() > 0) {
fetchDataAndUpdate(input);
promptForInput();
}
}
}
void promptForInput() {
Serial.println("\nVoer een stationsnaam in en druk op Enter:");
}
// WiFi en data ophalen functies blijven 100% hetzelfde
void connectWiFi() {
WiFi.begin(ssid, password);
int attempts = 0;
while (WiFi.status() != WL_CONNECTED && attempts < 20) {
delay(500);
Serial.print(".");
attempts++;
}
if (WiFi.status() != WL_CONNECTED) {
showError("WiFi Fout");
} else {
Serial.println(" Verbonden!");
}
}
// --- AANGEPASTE DISPLAY FUNCTIES ---
void showLoadingScreen(String message) {
// display.setRotation(1); // Inkplate is standaard al in landschapsmodus
display.setTextSize(3); // Groter lettertype voor het grotere scherm
display.setTextColor(BLACK);
// De paged rendering loop is niet meer nodig
display.clearDisplay(); // Maakt de buffer schoon (wit)
drawCentered(message, display.height() / 2);
display.display(); // Toon de buffer op het scherm
}
void showError(String message) {
showLoadingScreen(message); // Hergebruik dezelfde functie voor foutmeldingen
display.eink_sleep(); // Zet het scherm in slaapstand
}
// De fetchDataAndUpdate functie blijft grotendeels hetzelfde,
// enkel de aanroepen naar de display functies zijn nu anders.
void fetchDataAndUpdate(String station) {
if (WiFi.status() != WL_CONNECTED) {
showLoadingScreen("WiFi opnieuw verbinden...");
connectWiFi();
if (WiFi.status() != WL_CONNECTED) return;
}
showLoadingScreen("Data ophalen...");
WiFiClientSecure client;
client.setInsecure();
HTTPClient http;
if (http.begin(client, api_endpoint)) {
http.addHeader("Content-Type", "application/json");
http.addHeader("X-API-KEY", api_key);
String jsonPayload = "{\"station\":\"" + station + "\"}";
int httpCode = http.POST(jsonPayload);
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
DynamicJsonDocument doc(2048);
DeserializationError error = deserializeJson(doc, payload);
if (!error && doc["success"]) {
String last_update = doc["data"]["last_update"];
String station_name = doc["data"]["station_name"];
String covid_level = doc["data"]["covid"]["activity_level"];
String griep_level = doc["data"]["influenza"]["activity_level"];
String rsv_level = doc["data"]["rsv"]["activity_level"];
drawFinalDisplay(station_name, last_update, covid_level, griep_level, rsv_level);
} else {
showError("JSON Fout");
}
} else {
showError("HTTP Fout: " + String(httpCode));
}
http.end();
} else {
showError("Verbindingsfout");
}
}
void drawFinalDisplay(String station_name, String last_update, String covid_level, String griep_level, String rsv_level) {
// Coördinaten en groottes aangepast voor het 1280x720 scherm
int y_titel = 60;
int y_subtitle = 110;
int y_lijn = 140;
int y_koppen = 180;
int y_waarden = 250;
// Met moderne GFX fonts is dit waarschijnlijk niet meer nodig, maar we laten het staan voor de zekerheid.
station_name.replace("ë", "e");
// Begin met tekenen
display.clearDisplay();
display.setTextColor(BLACK);
// Titel
display.setTextSize(5);
drawCentered("Sciensano Barometer", y_titel);
// Subtitel
display.setTextSize(3);
String subtitle = station_name + " (Update: " + last_update + ")";
drawCentered(subtitle, y_subtitle);
// Lijn
display.drawLine(50, y_lijn, display.width() - 50, y_lijn, BLACK);
// Koppen
display.setTextSize(3);
display.setCursor(150, y_koppen); display.print("COVID");
display.setCursor(550, y_koppen); display.print("GRIEP");
display.setCursor(950, y_koppen); display.print("RSV");
// Waarden
display.setTextSize(4);
display.setCursor(150, y_waarden); display.print(covid_level.toUpperCase());
display.setCursor(550, y_waarden); display.print(griep_level.toUpperCase());
display.setCursor(950, y_waarden); display.print(rsv_level.toUpperCase());
// --- VERSTUUR ALLES NAAR HET SCHERM (VERANDERD) ---
display.display();
Serial.println("Display bijgewerkt!");
display.eink_sleep(); // Zet het scherm in slaapstand
}```
### Samenvatting van de Wijzigingen:
1. **Bibliotheek:** `#include "Inkplate.h"` in plaats van `GxEPD2`.
2. **Display Object:** `Inkplate display(INKPLATE_3BIT);` in plaats van de complexe `GxEPD2_BW` definitie.
3. **Initialisatie:** `display.begin();` in `setup()`.
4. **Tekenen:** Alle `do...while(display.nextPage())` loops zijn verwijderd. In plaats daarvan:
* Roep `display.clearDisplay();` aan.
* Teken alles wat je wilt met functies als `display.print()`, `display.drawLine()`, etc.
* Roep `display.display();` één keer aan op het einde om het resultaat te tonen.
5. **Layout:** De lettergroottes (`setTextSize`) en Y-posities zijn flink verhoogd om de ruimte op het grotere scherm te benutten.
6. **Slaapstand:** `display.hibernate()` is vervangen door `display.eink_sleep()`.
Je hoeft alleen nog maar de **Inkplate bibliotheek te installeren** via de Arduino IDE Library Manager, de juiste board ("Inkplate 5") te selecteren in het `Tools`-menu, je API-key en WiFi-gegevens in te vullen, en deze code te uploaden
Loading
epaper-2in9
epaper-2in9