1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #include "httpserver.h"
-
- auto HTTPServer::start() -> bool {
- if (!mount_fs()) {
- logf("cant mount filesystem, EXIT !\n\r");
- return false;
- }
-
- logf("LittleFS mounted !\n\r");
- logf("root:\n\r");
- this->listRoot();
- logf("\n\r");
-
- // default handler
- this->onNotFound([this]() {
- String message = "File Not Found\n\n";
- message += "URI: ";
- message += uri();
- message += "\nMethod: ";
- message += (method() == HTTP_GET) ? "GET" : "POST";
- message += "\nArguments: ";
- message += args();
- message += "\n";
-
- for (uint8_t i = 0; i < args(); i++) {
- message += " " + argName(i) + ": " + arg(i) + "\n";
- }
- send(404, "text/plain", message);
- });
-
- // add static root file handler for http
- this->serveStatic("/", LittleFS, "/");
- this->begin();
- Serial.printf("Server active on Port 80 !\n\r");
- return true;
- }
-
- void HTTPServer::start_apps() {
- // application handler
-
- this->on("/update", HTTP_POST, [this]() {
- if (args()) {
- for (int i = 0; i < args() - 1; i++) {
- Serial.printf("%s=%s\n", argName(i).c_str(), arg(i).c_str());
-
- if (argName(i).equals("range_act_pwm")) {
- treppe->set_active_pwm(arg(i).toInt(), VORGABE_PROZENT);
- }
- else if (argName(i).equals("range_idl_pwm")) {
- treppe->set_idle_pwm_max(arg(i).toInt(), VORGABE_PROZENT);
- }
- else if (argName(i).equals("range_tim_sta")) {
- }
- else if (argName(i).equals("range_tim_on")) {
-
- }
-
- }
- }
- send(200, "text/plain", "accepted");
- });
-
- this->on("/terminal", HTTP_POST, [this]() {
- // Serial.printf("got /terminal\n");
- if (tbuf_head) {
- send(200, "text/plain", tbuf);
- tbuf_head = 0;
- } else {
- send(202, "text/plain", "");
- }
- });
- }
-
- template <class... Args>
- void HTTPServer::logf(const char *format, Args... args) const {
- Serial.print(log_prefix);
- Serial.printf(format, args...);
- }
-
- void HTTPServer::logt(const char *format, ...) {
- va_list args;
- va_start(args, format);
- // append logging string to local buffer
- if (tbuf_head < TBUF_LEN) {
- tbuf_head +=
- vsnprintf(tbuf + tbuf_head, TBUF_LEN - tbuf_head, format, args);
- }
- va_end(args);
- }
|