web-server-without-style

uum-iot-lab/web-server-esp32/web-server-without-style

No description
web-server-without-style
@/web-server-without-style
INETjesuso/esp32-wifi/esp32-inet
CONNpulse
Establish the connection
TITLEstring
HTML Title
OPstring
Operation to be done on the web server
STYLEstring
HTML code to style the web server
RUNpulse
web-server-without-style
INET
CONN
TITLE
OP
STYLE
RUN
IP
DONE
DONEpulse
Pulse when new client is detected
IPxod/net/ip-address
IP address for the web server
To use the node in your project you should have the uum-iot-lab/web-server-esp32 library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#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);

    }
}