Extended http_server to provide new endpoints:
/_mapping.txt, /player.json, /playlist_manager.json, /controller.json and /position.json to get the matching data as well as /cmd to send commands to.
This commit is contained in:
parent
4f9174d362
commit
20041dd483
@ -360,6 +360,8 @@ String Controller::json() {
|
|||||||
JsonObject rfid = json.createNestedObject("last_rfid");
|
JsonObject rfid = json.createNestedObject("last_rfid");
|
||||||
rfid["uid"] = _last_rfid_uid;
|
rfid["uid"] = _last_rfid_uid;
|
||||||
rfid["data"] = _last_rfid_data;
|
rfid["data"] = _last_rfid_data;
|
||||||
|
json["uptime"] = millis() / 1000;
|
||||||
|
json["free_heap"] = ESP.getFreeHeap();
|
||||||
return json.as<String>();
|
return json.as<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,15 @@ HTTPServer::HTTPServer(Player* p, Controller* c) {
|
|||||||
ws = new AsyncWebSocket("/ws");
|
ws = new AsyncWebSocket("/ws");
|
||||||
_server->addHandler(ws);
|
_server->addHandler(ws);
|
||||||
ws->onEvent([&](AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){this->_onEvent(server, client, type, arg, data, len);});
|
ws->onEvent([&](AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){this->_onEvent(server, client, type, arg, data, len);});
|
||||||
_server->on("/", [&](AsyncWebServerRequest* req) {req->send(SPIFFS, "/index.html", "text/html");});
|
|
||||||
|
_server->on("/", HTTP_GET, [&](AsyncWebServerRequest* req) {req->send(SPIFFS, "/index.html", "text/html");});
|
||||||
_server->on("/upload", HTTP_POST, [](AsyncWebServerRequest* req) {req->send(200); }, ([&](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){this->_handle_upload(request, filename, index, data, len, final);}));
|
_server->on("/upload", HTTP_POST, [](AsyncWebServerRequest* req) {req->send(200); }, ([&](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){this->_handle_upload(request, filename, index, data, len, final);}));
|
||||||
|
_server->on("/_mapping.txt", HTTP_GET, [&](AsyncWebServerRequest* req) {req->send(200, "text/plain", _controller->pm->create_mapping_txt());});
|
||||||
|
_server->on("/player.json", HTTP_GET, [&](AsyncWebServerRequest* req) {req->send(200, "application/json", _controller->player->json());});
|
||||||
|
_server->on("/playlist_manager.json", HTTP_GET, [&](AsyncWebServerRequest* req) {req->send(200, "application/json", _controller->pm->json());});
|
||||||
|
_server->on("/controller.json", HTTP_GET, [&](AsyncWebServerRequest* req) {req->send(200, "application/json", _controller->json());});
|
||||||
|
_server->on("/position.json", HTTP_GET, [&](AsyncWebServerRequest* req) {req->send(200, "application/json", _controller->player->position_json());});
|
||||||
|
_server->on("/cmd", HTTP_POST, [&](AsyncWebServerRequest *req) {req->send(200); }, NULL, [&](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {_controller->queue_command((char*)data);});
|
||||||
_server->begin();
|
_server->begin();
|
||||||
MDNS.addService("http", "tcp", 80);
|
MDNS.addService("http", "tcp", 80);
|
||||||
}
|
}
|
||||||
@ -133,4 +140,4 @@ void HTTPServer::_onEvent(AsyncWebSocket * server, AsyncWebSocketClient * client
|
|||||||
_controller->queue_command((char*)data);
|
_controller->queue_command((char*)data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user