#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <QRCode.h>
const char* ssid = "nom_du_reseau_wifi";
const char* password = "mot_de_passe_wifi";
WiFiServer server(80);
void setup() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
}
server.begin();
}
void generateQRCode(String text) {
QRCode qrcode;
uint8_t qrcodeData[qrcode_getBufferSize(3)];
qrcode_initText(&qrcode, qrcodeData, 3, ECC_MEDIUM, text.c_str());
Adafruit_SSD1306 display(128, 64, &Wire, -1);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
for (int8_t y = 0; y < qrcode.size; y++) {
for (int8_t x = 0; x < qrcode.size; x++) {
if (qrcode_getModule(&qrcode, x, y)) {
display.drawPixel(x, y, WHITE);
} else {
display.drawPixel(x, y, BLACK);
}
}
}
display.display();
}
void handleRoot() {
String text = "Hello World!";
generateQRCode(text);
server.send(200, "text/html", "<html><body><img src=\"qr.png\"></body></html>");
}
void loop() {
WiFiClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
client.read();
}
}
handleRoot();
}
}