Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/espidf uvc support #76

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ESP/components/esp32-camera"]
path = ESP/components/esp32-camera
url = https://github.com/espressif/esp32-camera.git
3 changes: 3 additions & 0 deletions ESP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.16.0)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(TestingESPIDF)
1 change: 1 addition & 0 deletions ESP/components/esp32-camera
Submodule esp32-camera added at 7aa37d
9 changes: 9 additions & 0 deletions ESP/dependencies.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies:
idf:
component_hash: null
source:
type: idf
version: 4.4.7
manifest_hash: 3e6980bc5fca475de2a39d94c3ea3944c0528040d862609e810d1d8f5ea7f661
target: esp32s3
version: 1.0.0
11 changes: 8 additions & 3 deletions ESP/ini/dev_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[env]
platform = https://github.com/platformio/platform-espressif32.git
framework = arduino
framework = arduino, espidf
monitor_speed = 115200
custom_firmware_version = 2.6.0
monitor_rts = 0
Expand All @@ -22,15 +22,20 @@ lib_ldf_mode = deep+
;115200 is used for compatability - if you are on windows and want the code to flash faster use 921600
upload_speed = 921600
lib_deps =
# https://github.com/espressif/esp32-camera
esp32-camera
; # https://github.com/espressif/esp32-camera
espressif/esp32-camera
https://github.com/me-no-dev/ESPAsyncWebServer.git
https://github.com/me-no-dev/AsyncTCP.git
https://github.com/bblanchon/ArduinoJson.git
extra_scripts =
pre:tools/customname.py
post:tools/createzip.py
build_flags =
-I ../components/esp32-camera
; esp32-camera esp-idf settings
-D CONFIG_CAMERA_JPEG_MODE_FRAME_SIZE_AUTO
-D CONFIG_SCCB_CLK_FREQ=100000

-DENABLE_ADHOC=${wifi.enableadhoc}
-DADHOC_CHANNEL=${wifi.adhocchannel}
-DWIFI_CHANNEL=${wifi.channel}
Expand Down
4 changes: 2 additions & 2 deletions ESP/lib/src/data/config/project_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class ProjectConfig : public Preferences, public ISubject<ConfigState_e> {
ssid(std::move(ssid)),
password(std::move(password)),
channel(channel),
adhoc(adhoc),
power(power) {}
power(power),
adhoc(adhoc) {}
std::string name;
std::string ssid;
std::string password;
Expand Down
8 changes: 1 addition & 7 deletions ESP/lib/src/io/camera/cameraHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,7 @@ void CameraHandler::loadConfigData() {

int CameraHandler::setCameraResolution(framesize_t frameSize) {
if (camera_sensor->pixformat == PIXFORMAT_JPEG) {
try {
return camera_sensor->set_framesize(camera_sensor, frameSize);
} catch (...) {
// they sent us a malformed or unsupported frameSize - rather than crash -
// tell them about it
return -1;
}
return camera_sensor->set_framesize(camera_sensor, frameSize);
}
return -1;
}
Expand Down
17 changes: 12 additions & 5 deletions ESP/lib/src/network/api/baseAPI/baseAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,14 @@ void BaseAPI::getJsonConfig(AsyncWebServerRequest* request) {

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 hostname;
std::string service;
std::string ota_password;
std::string ota_login;
int ota_port;
int ota_port = 3232;

for (int i = 0; i < params; i++) {
AsyncWebParameter* param = request->getParam(i);
Expand Down Expand Up @@ -203,6 +199,11 @@ void BaseAPI::setDeviceConfig(AsyncWebServerRequest* request) {
projectConfig.setMDNSConfig(hostname, service, true);
request->send(200, MIMETYPE_JSON,
"{\"msg\":\"Done. Device Config has been set.\"}");

break;
}
default: {
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Request\"}");
}
}
}
Expand All @@ -225,6 +226,10 @@ void BaseAPI::setWiFiTXPower(AsyncWebServerRequest* request) {
projectConfig.wifiTxPowerConfigSave();
request->send(200, MIMETYPE_JSON,
"{\"msg\":\"Done. TX Power has been set.\"}");
break;
}
default: {
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Request\"}");
}
}
}
Expand All @@ -234,6 +239,7 @@ void BaseAPI::rebootDevice(AsyncWebServerRequest* request) {
case GET: {
request->send(200, MIMETYPE_JSON, "{\"msg\":\"Rebooting Device\"}");
OpenIrisTasks::ScheduleRestart(2000);
break;
}
default: {
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Request\"}");
Expand All @@ -248,6 +254,7 @@ void BaseAPI::factoryReset(AsyncWebServerRequest* request) {
log_d("Factory Reset");
projectConfig.reset();
request->send(200, MIMETYPE_JSON, "{\"msg\":\"Factory Reset\"}");
break;
}
default: {
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Request\"}");
Expand Down
40 changes: 20 additions & 20 deletions ESP/lib/src/network/api/baseAPI/baseAPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

//! Warning do not format this file with clang-format or it will break the code

#include <unordered_map>
#include <string>
#include <unordered_map>

Expand Down Expand Up @@ -43,7 +42,6 @@ constexpr int HTTP_ANY = 0b01111111;

class BaseAPI {
protected:
std::string api_url;
bool _authRequired;

static const char* MIMETYPE_HTML;
Expand All @@ -54,7 +52,6 @@ class BaseAPI {
/* static const char *MIMETYPE_ICO; */
static const char* MIMETYPE_JSON;

protected:
/* Commands */
void setWiFi(AsyncWebServerRequest* request);
void setWiFiTXPower(AsyncWebServerRequest* request);
Expand Down Expand Up @@ -100,33 +97,36 @@ class BaseAPI {
typedef std::unordered_map<std::string, WebRequestMethodComposite>
networkMethodsMap_t;

ProjectConfig &projectConfig;
/// @brief Local instance of the AsyncWebServer - so that we dont need to use new and delete
AsyncWebServer server;
/// @brief Local instance of the AsyncWebServer - so that we dont need to use
/// new and delete
AsyncWebServer server;
ProjectConfig& projectConfig;

#ifndef SIM_ENABLED
CameraHandler &camera;
CameraHandler& camera;
#endif // SIM_ENABLED
std::string api_url;

public :
BaseAPI(ProjectConfig& projectConfig,
public:
BaseAPI(ProjectConfig& projectConfig,
#ifndef SIM_ENABLED
CameraHandler& camera,
CameraHandler& camera,
#endif // SIM_ENABLED
const std::string& api_url,
const std::string& api_url,
#ifndef SIM_ENABLED
int port = 81
int port = 81
#else
int port = 80
int port = 80
#endif
);

virtual ~BaseAPI();
virtual void begin();
void checkAuthentication(AsyncWebServerRequest* request,
const char* login,
const char* password);
void beginOTA();
void notFound(AsyncWebServerRequest* request) const;
virtual ~BaseAPI();
virtual void begin();
void checkAuthentication(AsyncWebServerRequest* request,
const char* login,
const char* password);
void beginOTA();
void notFound(AsyncWebServerRequest* request) const;
};

#endif // BASEAPI_HPP
43 changes: 19 additions & 24 deletions ESP/lib/src/network/api/webserverHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ void APIServer::setup() {
"^\\%s\\/([a-zA-Z0-9]+)\\/command\\/([a-zA-Z0-9]+)$",
this->api_url.c_str());
log_d("API URL: %s", buffer);
server.on(buffer, 0b01111111, [&](AsyncWebServerRequest* request) {
handleRequest(request);
});
server.on(buffer, 0b01111111,
[&](AsyncWebServerRequest* request) { handleRequest(request); });
#ifndef SIM_ENABLED
//this->_authRequired = true;
// this->_authRequired = true;
#endif // SIM_ENABLED
beginOTA();
server.begin();
Expand Down Expand Up @@ -85,30 +84,26 @@ void APIServer::addRouteMap(const std::string& index,
}

void APIServer::handleRequest(AsyncWebServerRequest* request) {
try {
// Get the route
log_i("Request URL: %s", request->url().c_str());
log_i("Request: %s", request->pathArg(0).c_str());
log_i("Request: %s", request->pathArg(1).c_str());
// Get the route
log_i("Request URL: %s", request->url().c_str());
log_i("Request: %s", request->pathArg(0).c_str());
log_i("Request: %s", request->pathArg(1).c_str());

auto it_map = route_map.find(request->pathArg(0).c_str());
auto it_method = it_map->second.find(request->pathArg(1).c_str());
auto it_map = route_map.find(request->pathArg(0).c_str());
auto it_method = it_map->second.find(request->pathArg(1).c_str());

if (it_map != route_map.end()) {
if (it_method != it_map->second.end()) {
log_d("We are trying to execute the function");
(*this.*(it_method->second))(request);
} else {
log_e("Invalid Command");
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Command\"}");
return;
}
if (it_map != route_map.end()) {
if (it_method != it_map->second.end()) {
log_d("We are trying to execute the function");
(*this.*(it_method->second))(request);
} else {
log_e("Invalid Map Index");
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Map Index\"}");
log_e("Invalid Command");
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Command\"}");
return;
}
} catch (...) {
log_e("Error handling request");
} else {
log_e("Invalid Map Index");
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Map Index\"}");
return;
}
}
4 changes: 2 additions & 2 deletions ESP/lib/src/network/mDNS/MDNSManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ MDNSHandler::MDNSHandler(ProjectConfig& configManager)
bool MDNSHandler::startMDNS() {
const std::string service = "_openiristracker";
auto mdnsConfig = configManager.getMDNSConfig();
if (!MDNS.begin(mdnsConfig.hostname.c_str())) // lowercase only - as this will be the url
if (!MDNS.begin(mdnsConfig.hostname
.c_str())) // lowercase only - as this will be the url
{
mdnsStateManager.setState(MDNSState_e::MDNSState_Error);
log_e("Error initializing MDNS");
Expand All @@ -15,7 +16,6 @@ bool MDNSHandler::startMDNS() {

mdnsStateManager.setState(MDNSState_e::MDNSState_Starting);
MDNS.addService(service.c_str(), "_tcp", 80);
char port[20];
//! Add service needs leading _ on ESP32 implementation for some reason
//! (according to the docs)
MDNS.addServiceTxt(service.c_str(), "_tcp", "stream_port", "80");
Expand Down
Loading
Loading