mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
Remove unused API methods, fix missing pinout issues, fix OTA not having a password set up correctly, fix missing default password in platformio file
This commit is contained in:
parent
adb7853c71
commit
4baf7a89c4
@ -16,6 +16,7 @@ void OTA::SetupOTA()
|
||||
}
|
||||
|
||||
ArduinoOTA.setPort(localConfig->OTAPort);
|
||||
ArduinoOTA.setPassword(localConfig->OTAPassword.c_str());
|
||||
|
||||
ArduinoOTA
|
||||
.onStart([]()
|
||||
@ -52,7 +53,7 @@ void OTA::SetupOTA()
|
||||
} });
|
||||
|
||||
log_i("Starting up basic OTA server");
|
||||
log_i("OTA will be live for 30s, after which it will be disabled until restart");
|
||||
log_i("OTA will be live for 5 minutes, after which it will be disabled until restart");
|
||||
ArduinoOTA.begin();
|
||||
_bootTimestamp = millis();
|
||||
}
|
||||
@ -61,9 +62,9 @@ void OTA::HandleOTAUpdate()
|
||||
{
|
||||
if (_isOtaEnabled)
|
||||
{
|
||||
if (_bootTimestamp + 30000 < millis())
|
||||
if (_bootTimestamp + (60000 * 5) < millis())
|
||||
{
|
||||
// we're disabling ota after first 30sec so that nothing bad happens during runtime
|
||||
// we're disabling ota after first 5 minutes so that nothing bad happens during runtime
|
||||
_isOtaEnabled = false;
|
||||
log_i("From now on, OTA is disabled");
|
||||
return;
|
||||
|
||||
@ -123,77 +123,39 @@ void BaseAPI::setWiFi(AsyncWebServerRequest *request)
|
||||
}
|
||||
}
|
||||
|
||||
//! TODO: ADD JSON handlers for the POST requests
|
||||
void BaseAPI::handleJson(AsyncWebServerRequest *request)
|
||||
void BaseAPI::getJsonConfig(AsyncWebServerRequest *request)
|
||||
{
|
||||
std::string type = request->pathArg(0).c_str();
|
||||
switch (_networkMethodsMap_enum[request->method()])
|
||||
{
|
||||
case POST:
|
||||
{
|
||||
switch (json_TypesMap.at(type))
|
||||
{
|
||||
case DATA:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case SETTINGS:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case CONFIG:
|
||||
{
|
||||
break;
|
||||
}
|
||||
default:
|
||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Request\"}");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GET:
|
||||
{
|
||||
switch (json_TypesMap.at(type))
|
||||
{
|
||||
case DATA:
|
||||
{
|
||||
projectConfig->getDeviceConfig()->data_json = true;
|
||||
Network_Utilities::my_delay(1);
|
||||
std::string temp = projectConfig->getDeviceConfig()->data_json_string;
|
||||
request->send(200, MIMETYPE_JSON, temp.c_str());
|
||||
temp = std::string();
|
||||
break;
|
||||
}
|
||||
case SETTINGS:
|
||||
{
|
||||
projectConfig->getDeviceConfig()->config_json = true;
|
||||
Network_Utilities::my_delay(1);
|
||||
std::string temp = projectConfig->getDeviceConfig()->config_json_string;
|
||||
request->send(200, MIMETYPE_JSON, temp.c_str());
|
||||
temp = std::string();
|
||||
break;
|
||||
}
|
||||
case CONFIG:
|
||||
{
|
||||
projectConfig->getDeviceConfig()->settings_json = true;
|
||||
Network_Utilities::my_delay(1);
|
||||
std::string temp = projectConfig->getDeviceConfig()->settings_json_string;
|
||||
request->send(200, MIMETYPE_JSON, temp.c_str());
|
||||
temp = std::string();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Request\"}");
|
||||
break;
|
||||
}
|
||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Request\"}");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Request\"}");
|
||||
break;
|
||||
}
|
||||
void BaseAPI::setDeviceConfig(AsyncWebServerRequest *request){
|
||||
switch (_networkMethodsMap_enum[request->method()]){
|
||||
case GET:
|
||||
{
|
||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Request\"}");
|
||||
break;
|
||||
}
|
||||
case POST: {
|
||||
int params = request->params();
|
||||
|
||||
std::string device_name;
|
||||
std::string ota_password;
|
||||
int ota_port;
|
||||
|
||||
for (int i = 0; i < params; i++){
|
||||
AsyncWebParameter *param = request->getParam(i);
|
||||
if (param->name() == "device_name"){
|
||||
device_name = param->value().c_str();
|
||||
}
|
||||
if (param->name() == "ota_port"){
|
||||
ota_port = atoi(param->value().c_str());
|
||||
}
|
||||
if (param->name() == "ota_password"){
|
||||
ota_password = param->value().c_str();
|
||||
}
|
||||
}
|
||||
projectConfig->setDeviceConfig(device_name, ota_password, &ota_port, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,49 +194,6 @@ void BaseAPI::factoryReset(AsyncWebServerRequest *request)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Remove a command handler from the API
|
||||
*
|
||||
* @param request
|
||||
* @return \c void
|
||||
*/
|
||||
void BaseAPI::deleteRoute(AsyncWebServerRequest *request)
|
||||
{
|
||||
log_i("Request: %s", request->url().c_str());
|
||||
int params = request->params();
|
||||
auto it_map = route_map.find(request->pathArg(0).c_str());
|
||||
log_i("Request: %s", request->pathArg(0).c_str());
|
||||
if (it_map != route_map.end())
|
||||
{
|
||||
auto it = it_map->second.find(request->pathArg(1).c_str());
|
||||
if (it != it_map->second.end())
|
||||
{
|
||||
switch (_networkMethodsMap_enum[request->method()])
|
||||
{
|
||||
case DELETE:
|
||||
{
|
||||
route_map.erase(it_map->first);
|
||||
request->send(200, MIMETYPE_JSON, "{\"msg\":\"OK - Command handler removed\"}");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Request\"}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
request->send(404);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
request->send(404);
|
||||
}
|
||||
}
|
||||
|
||||
//*********************************************************************************************
|
||||
//! Camera Command Functions
|
||||
//*********************************************************************************************
|
||||
@ -335,141 +254,6 @@ void BaseAPI::setCamera(AsyncWebServerRequest *request)
|
||||
}
|
||||
}
|
||||
|
||||
//! TODO: Optimize this!!
|
||||
void BaseAPI::getCameraStatus(AsyncWebServerRequest *request)
|
||||
{
|
||||
static char json_response[1024];
|
||||
|
||||
sensor_t *s = esp_camera_sensor_get();
|
||||
if (s == NULL)
|
||||
{
|
||||
request->send(501);
|
||||
return;
|
||||
}
|
||||
char *p = json_response;
|
||||
*p++ = '{';
|
||||
|
||||
p += sprintf(p, "\"framesize\":%u,", s->status.framesize);
|
||||
p += sprintf(p, "\"quality\":%u,", s->status.quality);
|
||||
p += sprintf(p, "\"brightness\":%d,", s->status.brightness);
|
||||
p += sprintf(p, "\"contrast\":%d,", s->status.contrast);
|
||||
p += sprintf(p, "\"saturation\":%d,", s->status.saturation);
|
||||
p += sprintf(p, "\"sharpness\":%d,", s->status.sharpness);
|
||||
p += sprintf(p, "\"special_effect\":%u,", s->status.special_effect);
|
||||
p += sprintf(p, "\"wb_mode\":%u,", s->status.wb_mode);
|
||||
p += sprintf(p, "\"awb\":%u,", s->status.awb);
|
||||
p += sprintf(p, "\"awb_gain\":%u,", s->status.awb_gain);
|
||||
p += sprintf(p, "\"aec\":%u,", s->status.aec);
|
||||
p += sprintf(p, "\"aec2\":%u,", s->status.aec2);
|
||||
p += sprintf(p, "\"denoise\":%u,", s->status.denoise);
|
||||
p += sprintf(p, "\"ae_level\":%d,", s->status.ae_level);
|
||||
p += sprintf(p, "\"aec_value\":%u,", s->status.aec_value);
|
||||
p += sprintf(p, "\"agc\":%u,", s->status.agc);
|
||||
p += sprintf(p, "\"agc_gain\":%u,", s->status.agc_gain);
|
||||
p += sprintf(p, "\"gainceiling\":%u,", s->status.gainceiling);
|
||||
p += sprintf(p, "\"bpc\":%u,", s->status.bpc);
|
||||
p += sprintf(p, "\"wpc\":%u,", s->status.wpc);
|
||||
p += sprintf(p, "\"raw_gma\":%u,", s->status.raw_gma);
|
||||
p += sprintf(p, "\"lenc\":%u,", s->status.lenc);
|
||||
p += sprintf(p, "\"hmirror\":%u,", s->status.hmirror);
|
||||
p += sprintf(p, "\"vflip\":%u,", s->status.vflip);
|
||||
p += sprintf(p, "\"dcw\":%u,", s->status.dcw);
|
||||
p += sprintf(p, "\"colorbar\":%u", s->status.colorbar);
|
||||
*p++ = '}';
|
||||
*p++ = 0;
|
||||
|
||||
AsyncWebServerResponse *response = request->beginResponse(200, MIMETYPE_JSON, json_response);
|
||||
response->addHeader("Access-Control-Allow-Origin", "*");
|
||||
request->send(response);
|
||||
}
|
||||
|
||||
//! TODO: Optimize this!!
|
||||
//! Change this to a hashmap and a switch-case to remove the string comparisons and if statements
|
||||
void BaseAPI::setCameraVar(AsyncWebServerRequest *request)
|
||||
{
|
||||
if (!request->hasArg("var") || !request->hasArg("val"))
|
||||
{
|
||||
request->send(404);
|
||||
return;
|
||||
}
|
||||
String var = request->arg("var");
|
||||
const char *variable = var.c_str();
|
||||
int val = atoi(request->arg("val").c_str());
|
||||
|
||||
sensor_t *s = esp_camera_sensor_get();
|
||||
if (s == NULL)
|
||||
{
|
||||
request->send(501);
|
||||
return;
|
||||
}
|
||||
|
||||
int res = 0;
|
||||
if (!strcmp(variable, "framesize"))
|
||||
res = s->set_framesize(s, (framesize_t)val);
|
||||
else if (!strcmp(variable, "quality"))
|
||||
res = s->set_quality(s, val);
|
||||
else if (!strcmp(variable, "contrast"))
|
||||
res = s->set_contrast(s, val);
|
||||
else if (!strcmp(variable, "brightness"))
|
||||
res = s->set_brightness(s, val);
|
||||
else if (!strcmp(variable, "saturation"))
|
||||
res = s->set_saturation(s, val);
|
||||
else if (!strcmp(variable, "sharpness"))
|
||||
res = s->set_sharpness(s, val);
|
||||
else if (!strcmp(variable, "gainceiling"))
|
||||
res = s->set_gainceiling(s, (gainceiling_t)val);
|
||||
else if (!strcmp(variable, "colorbar"))
|
||||
res = s->set_colorbar(s, val);
|
||||
else if (!strcmp(variable, "awb"))
|
||||
res = s->set_whitebal(s, val);
|
||||
else if (!strcmp(variable, "agc"))
|
||||
res = s->set_gain_ctrl(s, val);
|
||||
else if (!strcmp(variable, "aec"))
|
||||
res = s->set_exposure_ctrl(s, val);
|
||||
else if (!strcmp(variable, "hmirror"))
|
||||
res = s->set_hmirror(s, val);
|
||||
else if (!strcmp(variable, "vflip"))
|
||||
res = s->set_vflip(s, val);
|
||||
else if (!strcmp(variable, "awb_gain"))
|
||||
res = s->set_awb_gain(s, val);
|
||||
else if (!strcmp(variable, "agc_gain"))
|
||||
res = s->set_agc_gain(s, val);
|
||||
else if (!strcmp(variable, "aec_value"))
|
||||
res = s->set_aec_value(s, val);
|
||||
else if (!strcmp(variable, "aec2"))
|
||||
res = s->set_aec2(s, val);
|
||||
else if (!strcmp(variable, "denoise"))
|
||||
res = s->set_denoise(s, val);
|
||||
else if (!strcmp(variable, "dcw"))
|
||||
res = s->set_dcw(s, val);
|
||||
else if (!strcmp(variable, "bpc"))
|
||||
res = s->set_bpc(s, val);
|
||||
else if (!strcmp(variable, "wpc"))
|
||||
res = s->set_wpc(s, val);
|
||||
else if (!strcmp(variable, "raw_gma"))
|
||||
res = s->set_raw_gma(s, val);
|
||||
else if (!strcmp(variable, "lenc"))
|
||||
res = s->set_lenc(s, val);
|
||||
else if (!strcmp(variable, "special_effect"))
|
||||
res = s->set_special_effect(s, val);
|
||||
else if (!strcmp(variable, "wb_mode"))
|
||||
res = s->set_wb_mode(s, val);
|
||||
else if (!strcmp(variable, "ae_level"))
|
||||
res = s->set_ae_level(s, val);
|
||||
|
||||
else
|
||||
{
|
||||
log_e("unknown setting %s", var.c_str());
|
||||
request->send(404);
|
||||
return;
|
||||
}
|
||||
log_d("Got setting %s with value %d. Res: %d", var.c_str(), val, res);
|
||||
|
||||
AsyncWebServerResponse *response = request->beginResponse(200);
|
||||
response->addHeader("Access-Control-Allow-Origin", "*");
|
||||
request->send(response);
|
||||
}
|
||||
|
||||
void BaseAPI::restartCamera(AsyncWebServerRequest *request)
|
||||
{
|
||||
bool mode = (bool)atoi(request->arg("mode").c_str());
|
||||
|
||||
@ -33,27 +33,6 @@ class BaseAPI
|
||||
protected:
|
||||
std::string api_url;
|
||||
|
||||
enum JSON_TYPES
|
||||
{
|
||||
CONFIG,
|
||||
SETTINGS,
|
||||
DATA,
|
||||
STATUS,
|
||||
COMMANDS,
|
||||
WIFI,
|
||||
WIFIAP,
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, JSON_TYPES> json_TypesMap = {
|
||||
{"config", CONFIG},
|
||||
{"settings", SETTINGS},
|
||||
{"data", DATA},
|
||||
{"status", STATUS},
|
||||
{"commands", COMMANDS},
|
||||
{"wifi", WIFI},
|
||||
{"wifiap", WIFIAP},
|
||||
};
|
||||
|
||||
static const char *MIMETYPE_HTML;
|
||||
/* static const char *MIMETYPE_CSS; */
|
||||
/* static const char *MIMETYPE_JS; */
|
||||
@ -65,14 +44,12 @@ protected:
|
||||
protected:
|
||||
/* Commands */
|
||||
void setWiFi(AsyncWebServerRequest *request);
|
||||
void handleJson(AsyncWebServerRequest *request);
|
||||
void getJsonConfig(AsyncWebServerRequest *request);
|
||||
void factoryReset(AsyncWebServerRequest *request);
|
||||
void setDeviceConfig(AsyncWebServerRequest *request);
|
||||
void rebootDevice(AsyncWebServerRequest *request);
|
||||
void deleteRoute(AsyncWebServerRequest *request);
|
||||
|
||||
/* Camera Handlers */
|
||||
void getCameraStatus(AsyncWebServerRequest *request);
|
||||
void setCameraVar(AsyncWebServerRequest *request);
|
||||
void setCamera(AsyncWebServerRequest *request);
|
||||
void restartCamera(AsyncWebServerRequest *request);
|
||||
|
||||
|
||||
@ -35,9 +35,9 @@ void APIServer::setupServer()
|
||||
{
|
||||
routes.emplace("wifi", &APIServer::setWiFi);
|
||||
routes.emplace("resetConfig", &APIServer::factoryReset);
|
||||
routes.emplace("setDevice", &APIServer::setDeviceConfig);
|
||||
routes.emplace("rebootDevice", &APIServer::rebootDevice);
|
||||
routes.emplace("setJson", &APIServer::handleJson);
|
||||
routes.emplace("deleteRoute", &APIServer::deleteRoute);
|
||||
routes.emplace("getStoredConfig", &APIServer::getJsonConfig);
|
||||
// Camera Routes
|
||||
routes.emplace("setCamera", &APIServer::setCamera);
|
||||
routes.emplace("restartCamera", &APIServer::restartCamera);
|
||||
|
||||
@ -19,7 +19,7 @@ password="" ; your wifi network password goes here
|
||||
channel=1 ; wifi channel
|
||||
ap_ssid="EyeTrackVR" ; your AP wifi network name goes here
|
||||
ap_password="test" ; Place your AP Wifi password here
|
||||
OTAPassword="" ; if empty, no password will be required
|
||||
OTAPassword="12345678"
|
||||
OTAServerPort=3232
|
||||
enableADHOC=0 ; 0 = disable, 1 = enable
|
||||
adhocChannel=1 ; channel to use for adhoc network
|
||||
@ -100,6 +100,23 @@ build_flags =
|
||||
-DBOARD_HAS_PSRAM ; enable psram
|
||||
-DASYNCWEBSERVER_REGEX ; enable regex in asyncwebserver
|
||||
-mfix-esp32-psram-cache-issue ; fix for psram
|
||||
; CAMERA PINOUT DEFINITIONS
|
||||
-DPWDN_GPIO_NUM=${pinoutsESPCAM.PWDN_GPIO_NUM} ; Set the PWDN pin
|
||||
-DRESET_GPIO_NUM=${pinoutsESPCAM.RESET_GPIO_NUM} ; Set the RESET pin
|
||||
-DXCLK_GPIO_NUM=${pinoutsESPCAM.XCLK_GPIO_NUM} ; Set the XCLK pin
|
||||
-DSIOD_GPIO_NUM=${pinoutsESPCAM.SIOD_GPIO_NUM} ; Set the SIOD pin
|
||||
-DSIOC_GPIO_NUM=${pinoutsESPCAM.SIOC_GPIO_NUM} ; Set the SIOC pin
|
||||
-DY9_GPIO_NUM=${pinoutsESPCAM.Y9_GPIO_NUM} ; Set the Y9 pin
|
||||
-DY8_GPIO_NUM=${pinoutsESPCAM.Y8_GPIO_NUM} ; Set the Y8 pin
|
||||
-DY7_GPIO_NUM=${pinoutsESPCAM.Y7_GPIO_NUM} ; Set the Y7 pin
|
||||
-DY6_GPIO_NUM=${pinoutsESPCAM.Y6_GPIO_NUM} ; Set the Y6 pin
|
||||
-DY5_GPIO_NUM=${pinoutsESPCAM.Y5_GPIO_NUM} ; Set the Y5 pin
|
||||
-DY4_GPIO_NUM=${pinoutsESPCAM.Y4_GPIO_NUM} ; Set the Y4 pin
|
||||
-DY3_GPIO_NUM=${pinoutsESPCAM.Y3_GPIO_NUM} ; Set the Y3 pin
|
||||
-DY2_GPIO_NUM=${pinoutsESPCAM.Y2_GPIO_NUM} ; Set the Y2 pin
|
||||
-DVSYNC_GPIO_NUM=${pinoutsESPCAM.VSYNC_GPIO_NUM} ; Set the VSYNC pin
|
||||
-DHREF_GPIO_NUM=${pinoutsESPCAM.HREF_GPIO_NUM} ; Set the HREF pin
|
||||
-DPCLK_GPIO_NUM=${pinoutsESPCAM.PCLK_GPIO_NUM} ; Set the PCLK pin
|
||||
|
||||
;build_unflags = -Os ; disable optimization for size
|
||||
lib_ldf_mode = deep+
|
||||
@ -131,25 +148,6 @@ lib_deps = ${common.lib_deps}
|
||||
build_type = ${common.build_type}
|
||||
extra_scripts = ${common.extra_scripts}
|
||||
build_flags = ${common.build_flags}
|
||||
|
||||
; CAMERA PINOUT DEFINITIONS
|
||||
-DPWDN_GPIO_NUM=${pinoutsESPCAM.PWDN_GPIO_NUM} ; Set the PWDN pin
|
||||
-DRESET_GPIO_NUM=${pinoutsESPCAM.RESET_GPIO_NUM} ; Set the RESET pin
|
||||
-DXCLK_GPIO_NUM=${pinoutsESPCAM.XCLK_GPIO_NUM} ; Set the XCLK pin
|
||||
-DSIOD_GPIO_NUM=${pinoutsESPCAM.SIOD_GPIO_NUM} ; Set the SIOD pin
|
||||
-DSIOC_GPIO_NUM=${pinoutsESPCAM.SIOC_GPIO_NUM} ; Set the SIOC pin
|
||||
-DY9_GPIO_NUM=${pinoutsESPCAM.Y9_GPIO_NUM} ; Set the Y9 pin
|
||||
-DY8_GPIO_NUM=${pinoutsESPCAM.Y8_GPIO_NUM} ; Set the Y8 pin
|
||||
-DY7_GPIO_NUM=${pinoutsESPCAM.Y7_GPIO_NUM} ; Set the Y7 pin
|
||||
-DY6_GPIO_NUM=${pinoutsESPCAM.Y6_GPIO_NUM} ; Set the Y6 pin
|
||||
-DY5_GPIO_NUM=${pinoutsESPCAM.Y5_GPIO_NUM} ; Set the Y5 pin
|
||||
-DY4_GPIO_NUM=${pinoutsESPCAM.Y4_GPIO_NUM} ; Set the Y4 pin
|
||||
-DY3_GPIO_NUM=${pinoutsESPCAM.Y3_GPIO_NUM} ; Set the Y3 pin
|
||||
-DY2_GPIO_NUM=${pinoutsESPCAM.Y2_GPIO_NUM} ; Set the Y2 pin
|
||||
-DVSYNC_GPIO_NUM=${pinoutsESPCAM.VSYNC_GPIO_NUM} ; Set the VSYNC pin
|
||||
-DHREF_GPIO_NUM=${pinoutsESPCAM.HREF_GPIO_NUM} ; Set the HREF pin
|
||||
-DPCLK_GPIO_NUM=${pinoutsESPCAM.PCLK_GPIO_NUM} ; Set the PCLK pin
|
||||
|
||||
-DDEBUG_MODE=1 ; Set the debug mode
|
||||
|
||||
[env:esp32Cam_release]
|
||||
|
||||
@ -1 +1 @@
|
||||
114
|
||||
248
|
||||
Loading…
Reference in New Issue
Block a user