Skip to content

Commit

Permalink
use FIFO queue
Browse files Browse the repository at this point in the history
  • Loading branch information
amymc committed Oct 14, 2024
1 parent 30ea8cd commit 5e922e9
Showing 1 changed file with 22 additions and 56 deletions.
78 changes: 22 additions & 56 deletions server/server.ino
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include <string>
#include <ArduinoJson.h>
// #include <ESP8266WiFi.h>
// #include <WiFiClient.h>
#include <queue>
#include <ESP8266WebServer.h>
// #include <ESP8266mDNS.h>

#include "secrets.h" // add WLAN Credentials in here.

ESP8266WebServer server(80);
Expand All @@ -25,20 +22,30 @@ String grimReaper = " ___\n"
" | \\\\\n"
" |________|\\\n";

int handleForm() {
server.send(200, "text/plain", "success message");

class Participant {
public:
String name;
String expectancy;
};

Participant participant;
std::queue<Participant> participantQueue;

void handleForm() {
DynamicJsonDocument doc(1024);

String input = server.arg("plain");
deserializeJson(doc, input);

const String name = doc["name"];
const String expectancy = doc["expectancy"];
return printMemento(name, expectancy);

participantQueue.push({ name: name, expectancy: expectancy });

server.send(200, "text/plain", "success");
}

int printMemento(String name, String expectancy) {
void printMemento(String name, String expectancy) {
String years = expectancy + " years";
if (expectancy == "1"){
years = expectancy + " year";
Expand All @@ -53,19 +60,10 @@ int printMemento(String name, String expectancy) {
Serial.println("I'll be waiting for you.");
Serial.println("********************************");
Serial.println("********************************");

return 0;
}

// void handleListFiles() {
// Serial.println("list files");
// server.sendHeader("Cache-Control", "no-cache");
// server.send(200, "text/javascript; charset=utf-8", "result");
// } // handleListFiles()

void setup()
{

// Serial.begin(19200);
Serial.begin(9600);

Expand All @@ -83,50 +81,18 @@ void setup()
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

// server.on("/$list", HTTP_GET, handleListFiles);
server.on("/participants", HTTP_POST, handleForm);

server.enableCORS(true);

// server.on("/$participants", HTTP_POST, handleForm, handleForm);
// server.on("/participants", []() {
// server.send(200, "text/plain", "success result");
// });

server.begin();
}

void loop()
{
server.handleClient();
// while (!Serial) {
// // wait for serial port to connect. Needed for native USB
// }
// if (Serial.available() > 0)
// {

// String info = Serial.readString();
// String strs[2];
// int StringCount = 0;

// int index = info.indexOf(' ');
// strs[0] = info.substring(0, index);
// strs[1] = info.substring(index + 1);

// String years = strs[1] + " years";
// if (strs[1] == "1")
// {
// years = strs[1] + " year";
// }

// String expiration = String(" You are due to expire in \n " + years + ".");

// Serial.println("\n********************************");
// Serial.println(expiration);
// Serial.print(grimReaper);
// Serial.println("Enjoy it " + strs[0] + ".");
// Serial.println("I'll be waiting for you.");
// Serial.println("********************************");
// Serial.println("********************************");
//}

while(!participantQueue.empty()) {
participant = participantQueue.front();
printMemento(participant.name, participant.expectancy);
participantQueue.pop();
}
}

0 comments on commit 5e922e9

Please sign in to comment.