Files
pti-ledy/server.ino
T

60 lines
1.4 KiB
Arduino

const char* ssid = "PPIA";
const char* password = "pawelpdaldonejta";
WebServer server(80);
void handleRoot() {
server.send(200, "text/html", index_html);
}
void handleUpload() {
if (server.hasArg("plain") == false) {
server.send(400, "text/plain", "body not received");
return;
}
String body = server.arg("plain");
DynamicJsonDocument doc(8192);
deserializeJson(doc, body);
JsonArray arr = doc.as<JsonArray>();
int row = 0;
for (JsonVariant val : arr) {
int col = 0;
for (JsonVariant val2 : val.as<JsonArray>()) {
long color = strtol(val2.as<const char*>(), NULL, 16);
new_image[row][col] = { (unsigned short)col, (unsigned short)row, (uint32_t)color };
col++;
}
row++;
}
pixels.clear();
drawImageFromArr(0, 0);
pixels.show();
server.send(200, "text/plain", "OK");
}
void handleShowSaved() {
pixels.clear();
drawImageFromSaved(0, 0, 0);
pixels.show();
server.send(200, "text/plain", "OK");
}
void start_server() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.on("/show-saved", handleShowSaved);
server.on("/upload", HTTP_POST, handleUpload);
server.begin();
}
void handle_server() {
server.handleClient();
}