Skip to content

Commit

Permalink
feat: begin working on the API
Browse files Browse the repository at this point in the history
  • Loading branch information
ZanzyTHEbar committed Jun 20, 2023
1 parent d4f6fe2 commit 271a828
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#include "api.hpp"

API::API(APIServer& server, GreenHouseConfig& configManager)
: configManager(configManager), server(server) {}
API::API(ProjectConfig& projectConfig, GreenHouseConfig& configManager)
: projectConfig(projectConfig),
configManager(configManager),
server(80, projectConfig, "/control", "/wifimanager", "/tower") {}

API::~API() {}

void API::setupServer() {
server.begin();
}

void API::begin() {
// handle the WiFi connection state changes
switch (wifiStateManager.getCurrentState()) {
Expand Down Expand Up @@ -37,6 +35,18 @@ void API::begin() {
}
}

/**
* @brief Setup the API Server
* @note Add all the routes and handlers here
*/
void API::setupServer() {
server.updateCommandHandlers(
"/setDHT",
[this](AsyncWebServerRequest* request) { this->setDHT(request); });

server.begin();
}

void API::setDHT(AsyncWebServerRequest* request) {
switch (server._networkMethodsMap_enum[request->method()]) {
case APIServer::POST: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
#include <local/data/config/config.hpp>
class API {
private:
APIServer& server;
APIServer server;
ProjectConfig& projectConfig;
GreenHouseConfig& configManager;
void setupServer();

public:
API(APIServer& server, GreenHouseConfig& configManager);
API(ProjectConfig& projectConfig, GreenHouseConfig& configManager);
virtual ~API();
void begin();
void setTopic(AsyncWebServerRequest* request);
Expand Down
4 changes: 1 addition & 3 deletions Code/PlatformIO_Project/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ ConfigHandler configHandler(config);
GreenHouseConfig greenhouseConfig(config);

//* Network
APIServer server(80, config, "/control", "/wifimanager", "/tower");

WiFiHandler network(config, WIFI_SSID, WIFI_PASS, 1);
OTA ota(config);
MDNSHandler mDNS(config, "_tower", "data", "_tcp", "api_port", "80");
Expand All @@ -49,7 +47,7 @@ MQTTClient mqttClient;
BaseMQTT mqtt(greenhouseConfig, config, mqttClient);

//* API
API api(server, greenhouseConfig);
API api(config, greenhouseConfig);

//* Sensors
TowerTemp tower_temp(greenhouseConfig);
Expand Down

0 comments on commit 271a828

Please sign in to comment.