#pragma XOD require "https://github.com/espressif/arduino-esp32"
#pragma XOD error_raise enable
#include <WiFi.h>
#include <WiFiServer.h>
WiFiServer wifiServer(80);
node {
String request = "";
void evaluate(Context ctx) {
if (isInputDirty<input_CONN>(ctx)) {
wifiServer.begin();
auto ip = WiFi.localIP();
emitValue<output_IP>(ctx, ip);
}
if (isInputDirty<input_RUN>(ctx)) {
WiFiClient client = wifiServer.available();
if(!client)
return;
boolean currentLineIsBlank = true;
while (client.connected())
{
if(client.available())
{
char c = client.read();
request += c;
Serial.write(c);
if (c == '\n' && currentLineIsBlank)
{
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<head>");
client.println("<title>");
auto title = getValue<input_TITLE>(ctx);
char _title[length(title) + 1] = { 0 };
dump(title, _title);
client.println(_title);
delay(2000);
client.println("</title>");
client.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
auto style = getValue<input_STYLE>(ctx);
char _style[length(style) + 1] = { 0 };
dump(style, _style);
client.println(_style);
delay(2000);
client.println("</head>");
client.println("<body>");
client.println("<div id=\"operation\">");
auto op = getValue<input_OP>(ctx);
char _op[length(op) + 1] = { 0 };
dump(op, _op);
client.println(_op);
client.println("</div>");
client.println("</body>");
client.println("</html>");
break;
}
if(c == '\n')
{
currentLineIsBlank = true;
}
else if(c != '\r')
{
currentLineIsBlank = false;
}
}
}
}
emitValue<output_DONE>(ctx, 1);
}
}