Skip to content

Commit

Permalink
fix: file case issue
Browse files Browse the repository at this point in the history
-  simplified config api
- fixed file case issue on linux
  • Loading branch information
ZanzyTHEbar committed Jun 24, 2023
1 parent 9361004 commit 1c9e893
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 59 deletions.
29 changes: 13 additions & 16 deletions NetworkManager/examples/customHTML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@
// data ? The config manager constructor takes two (optional) parameters: ? 1.
// The name of the project (used to create the config file name) ? 2. The
// hostname for your device on the network(used for mDNS, OTA, etc.)
ProjectConfig configManager("easynetwork", MDNS_HOSTNAME);
ConfigHandler configHandler(configManager);
ConfigHandler configHandler("easynetwork", MDNS_HOSTNAME);

// Note: The WiFi Handler is used to manage the WiFi connection
// Note: The WiFi Handler constructor takes four parameters:
// Note: 1. A pointer to the config manager
// Note: 2. A pointer to the WiFi State Manager
// Note: 3. The SSID of the WiFi network to connect to
// Note: 4. The password of the WiFi network to connect to
WiFiHandler network(configManager, WIFI_SSID, WIFI_PASSWORD, 1);
WiFiHandler network(configHandler.config, WIFI_SSID, WIFI_PASSWORD, 1);

// Note: The API Server is used to create a web server that can be used to send
// commands to the device ? The API Server constructor takes five parameters:
Expand All @@ -48,8 +47,11 @@ WiFiHandler network(configManager, WIFI_SSID, WIFI_PASSWORD, 1);
// http://easynetwork.local/api/mycommands/command/helloWorld
// http://easynetwork.local/api/mycommands/command/blink
// http://easynetwork.local/api/mycommands/command/params?Axes1=1&Axes2=2
APIServer server(80, configManager, "/api", "/wifimanager", "/mycommands");
OTA ota(configManager);
APIServer server(80, configHandler.config, "/api", "/wifimanager",
"/mycommands");

// Note: Not required if you are going to use the AsyncOTA feature
OTA ota(configHandler.config);

// Note: The mDNS Manager is used to create a mDNS service for the device
// Note: The mDNS Manager constructor takes seven parameters:
Expand All @@ -63,8 +65,8 @@ OTA ota(configManager);

//! service name and service protocol have to be
//! lowercase and begin with an underscore
MDNSHandler mDNS(configManager, "_easynetwork", "test", "_tcp", "_api_port",
"80");
MDNSHandler mDNS(configHandler.config, "_easynetwork", "test", "_tcp",
"_api_port", "80");

class CustomConfig : public CustomConfigInterface {
void save() override {
Expand Down Expand Up @@ -154,11 +156,6 @@ void setupServer() {
server.custom_html_files.emplace_back("/hello", "/helloWorld.html", "GET");
server.custom_html_files.emplace_back("/goodbye", "/goodbye.html", "POST");

// Note: This is an example of how to add a custom API commands
// Note: The first parameter is the url endpoint
// Note: The second parameter is the function to call

// Note: The function can be a lambda function or a normal function
server.addAPICommand("blink", blink);
server.addAPICommand("helloWorld", printHelloWorld);
server.addAPICommand("params", grabParams);
Expand All @@ -175,11 +172,11 @@ void setup() {
pinMode(4, OUTPUT);
Serial.println("\nHello, EasyNetworkManager!");

configManager.attach(configHandler);
configHandler.config.attach(configHandler);
//* Optionally register a custom config - this will be saved and loaded
configManager.registerUserConfig(&customConfig);
configManager.attach(network);
configManager.attach(
configHandler.config.registerUserConfig(&customConfig);
configHandler.config.attach(network);
configHandler.config.attach(
mDNS); // attach the config manager to the mdns object - this will
// update the config when mdns hostname changes

Expand Down
30 changes: 13 additions & 17 deletions NetworkManager/examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@
// data ? The config manager constructor takes two (optional) parameters: ? 1.
// The name of the project (used to create the config file name) ? 2. The
// hostname for your device on the network(used for mDNS, OTA, etc.)
ProjectConfig configManager("easynetwork", MDNS_HOSTNAME);
ConfigHandler configHandler(configManager);
ConfigHandler configHandler("easynetwork", MDNS_HOSTNAME);

// Note: The WiFi Handler is used to manage the WiFi connection
// Note: The WiFi Handler constructor takes four parameters:
// Note: 1. A pointer to the config manager
// Note: 2. A pointer to the WiFi State Manager
// Note: 3. The SSID of the WiFi network to connect to
// Note: 4. The password of the WiFi network to connect to
WiFiHandler network(configManager, WIFI_SSID, WIFI_PASSWORD, 1);
WiFiHandler network(configHandler.config, WIFI_SSID, WIFI_PASSWORD, 1);

// Note: The API Server is used to create a web server that can be used to send
// commands to the device ? The API Server constructor takes five parameters:
Expand All @@ -48,8 +47,11 @@ WiFiHandler network(configManager, WIFI_SSID, WIFI_PASSWORD, 1);
// http://easynetwork.local/api/mycommands/command/helloWorld
// http://easynetwork.local/api/mycommands/command/blink
// http://easynetwork.local/api/mycommands/command/params?Axes1=1&Axes2=2
APIServer server(80, configManager, "/api", "/wifimanager", "/mycommands");
OTA ota(configManager);
APIServer server(80, configHandler.config, "/api", "/wifimanager",
"/mycommands");

// Note: Not required if you are going to use the AsyncOTA feature
OTA ota(configHandler.config);

// Note: The mDNS Manager is used to create a mDNS service for the device
// Note: The mDNS Manager constructor takes seven parameters:
Expand All @@ -63,8 +65,8 @@ OTA ota(configManager);

//! service name and service protocol have to be
//! lowercase and begin with an underscore
MDNSHandler mDNS(configManager, "_easynetwork", "test", "_tcp", "_api_port",
"80");
MDNSHandler mDNS(configHandler.config, "_easynetwork", "test", "_tcp",
"_api_port", "80");

class CustomConfig : public CustomConfigInterface {
void save() override {
Expand Down Expand Up @@ -146,12 +148,6 @@ void setupServer() {
// add command handlers to the API server
// you can add as many as you want - you can also add methods.
log_d("[SETUP]: Starting API Server");

// Note: This is an example of how to add a custom API commands
// Note: The first parameter is the url endpoint
// Note: The second parameter is the function to call

// Note: The function can be a lambda function or a normal function
server.addAPICommand("blink", blink);
server.addAPICommand("helloWorld", printHelloWorld);
server.addAPICommand("params", grabParams);
Expand All @@ -168,11 +164,11 @@ void setup() {
pinMode(4, OUTPUT);
Serial.println("\nHello, EasyNetworkManager!");

configManager.attach(configHandler);
configHandler.config.attach(configHandler);
//* Optionally register a custom config - this will be saved and loaded
configManager.registerUserConfig(&customConfig);
configManager.attach(network);
configManager.attach(
configHandler.config.registerUserConfig(&customConfig);
configHandler.config.attach(network);
configHandler.config.attach(
mDNS); // attach the config manager to the mdns object - this will
// update the config when mdns hostname changes

Expand Down
15 changes: 7 additions & 8 deletions NetworkManager/include/data/config/config_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

class ConfigHandler : public IObserver<Event_e> {
public:
ConfigHandler(ProjectConfig& config);
~ConfigHandler();
void begin();
void update(Event_e event) override;
std::string getName() override;

private:
ProjectConfig& config;
ConfigHandler(const std::string& configName = std::string(),
const std::string& mdnsName = std::string());
virtual ~ConfigHandler();
virtual void begin();
virtual void update(Event_e event) override;
virtual std::string getName() override;
ProjectConfig config;
};
2 changes: 1 addition & 1 deletion NetworkManager/include/network/mdns/mdns_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "data/config/project_config.hpp"
#include "data/statemanager/state_manager.hpp"
#include "utilities/Observer.hpp"
#include "utilities/observer.hpp"

class MDNSHandler : public IObserver<Event_e> {
private:
Expand Down
19 changes: 5 additions & 14 deletions NetworkManager/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,20 @@
"platforms": [
"espressif8266"
]
},
{
"owner": "leftcoast",
"name": "LC_baseTools",
"version": "@^1.5"
},
{
"name": "ArduinoJSON",
"version": "https://github.com/bblanchon/ArduinoJson"
}
],
"headers": [
"EasyNetworkManager.hpp",
"EasyNetworkManager.h",
"api/webserverHandler.hpp",
"data/config/project_config.hpp",
"data/statemanager/StateManager.hpp",
"data/statemanager/state_manager.hpp",
"utilities/enuminheritance.hpp",
"utilities/makeunique.hpp",
"utilities/Observer.hpp",
"network/mDNS/MDNSManager.hpp",
"network/ota/OTA.hpp",
"network/wifihandler/wifihandler.hpp"
"utilities/observer.hpp",
"network/mdns/mdns_manager.hpp",
"network/ota/ota.hpp",
"network/wifihandler/wifi_handler.hpp"
],
"export": {
"include": [
Expand Down
4 changes: 3 additions & 1 deletion NetworkManager/src/data/config/config_handler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "data/config/config_handler.hpp"

ConfigHandler::ConfigHandler(ProjectConfig& config) : config(config) {}
ConfigHandler::ConfigHandler(const std::string& configName,
const std::string& mdnsName)
: config(std::move(configName), std::move(mdnsName)) {}

ConfigHandler::~ConfigHandler() {}

Expand Down
4 changes: 2 additions & 2 deletions NetworkManager/wokwi.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[wokwi]
version = 1
elf = ".pio/build/esp32dev_debug/EasyNetworkManager-v4.1.1-esp32dev_debug-fe8a2bd-main.elf"
firmware = ".pio/build/esp32dev_debug/EasyNetworkManager-v4.1.1-esp32dev_debug-fe8a2bd-main.bin"
elf = ".pio/build/esp32dev_debug/EasyNetworkManager-v4.2.1-esp32dev_debug-9361004-main.elf"
firmware = ".pio/build/esp32dev_debug/EasyNetworkManager-v4.2.1-esp32dev_debug-9361004-main.bin"
[[net.forward]]
from = "localhost:8180"
to = "target:80"

0 comments on commit 1c9e893

Please sign in to comment.