Commit a483e3b3 authored by PhiBo's avatar PhiBo 🚀

Add new request dispatcher

parent e05d78f9
#include <ArduinoJson.h>
#include "sensor_node.h"
#include "sensor_node_file.h"
void handleAPIHostname()
{
......@@ -117,8 +118,73 @@ void handleInfoWiFiSTA()
server->send(200, "application/json", buffer);
}
void handleNotFound(){
void handleNotFound()
{
uint8_t sensor_id;
String uri = server->uri();
String tmp;
if (uri.equals("/")) {
handleRoot();
return;
}
if (uri.equals("/action/register")) {
handleRegister();
return;
}
if (uri.equals("/action/restart")) {
handleRestart();
return;
}
if (uri.equals("/action/save")) {
handleSave();
return;
}
if (uri.equals("/config/api/hostname")) {
handleAPIHostname();
return;
}
if (uri.equals("/config/api/port")) {
handleAPIPort();
return;
}
if (uri.startsWith("/config/sensor/")) {
tmp = uri.substring(15, 4);
sensor_id = tmp.toInt();
handleConfigSensor();
return;
}
if (uri.equals("/config/wifi/sta/ssid")) {
handleSSID();
return;
}
if (uri.equals("/config/wifi/sta/password")) {
handlePassword();
return;
}
if (uri.equals("/info/wifi/ssids")) {
handleScanSSID();
return;
}
if (uri.equals("/info/wifi/sta")) {
handleInfoWiFiSTA();
return;
}
if (uri.equals("/setup")) {
server->setContentLength(sizeof(PAGE_setup));
server->sendHeader("Content-Encoding", "gzip");
server->send(200, "text/html", "");
submitFile(PAGE_setup, sizeof(PAGE_setup));
return;
}
if (uri.equals("/setup/js.js")) {
server->setContentLength(sizeof(FILE_js));
server->sendHeader("Content-Encoding", "gzip");
server->send(200, "application/javascript", "");
submitFile(FILE_js, sizeof(FILE_js));
return;
}
String message = "File Not Found\n\n";
message += "URI: ";
message += server->uri();
......
#include "ArduRPC.h"
#include "sensor_node.h"
#include "sensor_node_file.h"
//#include <ESP8266mDNS.h>
// the serial port, it's also possible to use software serial
......@@ -62,31 +61,6 @@ void setup() {
connectWiFiClient(20);
server->on("/", handleRoot);
server->on("/action/register", handleRegister);
server->on("/action/restart", handleRestart);
server->on("/action/save", handleSave);
server->on("/config/api/hostname", handleAPIHostname);
server->on("/config/api/port", handleAPIPort);
server->on("/config/wifi/sta/ssid", handleSSID);
server->on("/config/wifi/sta/password", handlePassword);
server->on("/config/sensor", handleConfigSensor);
server->on("/info/wifi/ssids", handleScanSSID);
server->on("/info/wifi/sta", handleInfoWiFiSTA);
server->on("/setup", []() {
server->setContentLength(sizeof(PAGE_setup));
server->sendHeader("Content-Encoding", "gzip");
server->send(200, "text/html", "");
submitFile(PAGE_setup, sizeof(PAGE_setup));
});
server->on("/setup/js.js", []() {
server->setContentLength(sizeof(FILE_js));
server->sendHeader("Content-Encoding", "gzip");
server->send(200, "application/javascript", "");
submitFile(FILE_js, sizeof(FILE_js));
});
server->onNotFound(handleNotFound);
server->begin();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment