Example program using the ESPAT library. Made for BULME Bertl 2017.

Dependencies:   mbed ESPAT

Demo Program für mein ESPAT Library für Bulme Bertl 2017. Startet einen WebServer mit zwei Buttons um die LED D10 zu steuern.

main.cpp

Committer:
EliasN
Date:
2019-02-18
Revision:
0:617bf6669ab4
Child:
1:f1f79c0e0d15

File content as of revision 0:617bf6669ab4:

#include "mbed.h"
#include "ESPAT.h"

/*
Example program using the ESPAT library.
Made for BULME Bertl 2017 (LPC11U68)
Make sure to edit your wifi login data below
# Features:
 - Led D10 turns on when ready (wifi connected + server listening)
 - Navigate to the device's ip in your browser and use the buttons to control Led D11
 - Navigate to <device ip>/test for a test page that demonstrates that paths work
(C)2019 Elias Nestl
*/

ESPAT esp(P1_0, P0_20, "wifi name", "wifi password", 115200);

DigitalOut Led0 (P1_18); // D10
DigitalOut Led1 (P2_16); // D11

string htmlPage = "<html>"
"<head><title>Led toggler</title></head>"
"<body>"
"<button onclick=\"fetch('./ledOn')\">Led ON</button>"
"<button onclick=\"fetch('./ledOff')\">Led OFF</button>"
"</body></html>";

void handleReady() {
    Led0 = 0;
}

void handleRequest(int linkId, string path) {
    if (path == "/") {
        esp.httpReply(linkId, "200 OK", htmlPage);
    } else if (path == "/ledOn") {
        Led1 = 0;
        esp.httpReply(linkId, "200 OK", "success");
    } else if (path == "/ledOff") {
        Led1 = 1;
        esp.httpReply(linkId, "200 OK", "success");
    } else if (path == "/test") {
        esp.httpReply(linkId, "200 OK", "This is just a test");
    } else {
        esp.httpReply(linkId, "404 Not Found", "404 Not found!");
    }
}

int main() {
    Led0 = Led1 = 1;
    esp.startWebServer(handleReady, handleRequest);
}