- Attempt to fix NVS_OPEN error
This commit is contained in:
ZanzyTHEbar 2022-08-11 20:55:25 +01:00
parent b2e43c80e9
commit f685a464e5
6 changed files with 40 additions and 37 deletions

View File

@ -1,9 +1,8 @@
#include "project_config.hpp"
ProjectConfig::ProjectConfig() : Config("config"), _already_loaded(false)
{
begin();
}
Preferences preferences;
ProjectConfig::ProjectConfig() : Config(&preferences ,"config"), _already_loaded(false) {}
ProjectConfig::~ProjectConfig() {}
@ -11,8 +10,9 @@ ProjectConfig::~ProjectConfig() {}
*@brief Initializes the structures with blank data to prevent empty memory sectors and nullptr errors.
*@brief This is to be called in setup() before loading the config.
*/
void ProjectConfig::initStructures()
void ProjectConfig::initConfig()
{
begin();
this->config.device = {
"",
"",
@ -128,6 +128,4 @@ void ProjectConfig::setWifiConfig(const char *networkName, const char *ssid, con
this->notify(ObserverEvent::networksConfigUpdated);
}
log_d("Updating wifi config");
}
ProjectConfig projectConfig;
}

View File

@ -1,4 +1,6 @@
#pragma once
#ifndef PROJECT_CONFIG_HPP
#define PROJECT_CONFIG_HPP
#include <Arduino.h>
#include <preferencesAPI.hpp>
#include <vector>
@ -13,7 +15,7 @@ public:
void load();
void save();
void reset();
void initStructures();
void initConfig();
struct DeviceConfig_t
{
@ -58,4 +60,4 @@ private:
bool _already_loaded;
};
extern ProjectConfig projectConfig;
#endif // PROJECT_CONFIG_HPP

View File

@ -1,19 +1,20 @@
#include "serialmanager.hpp"
SerialManager::SerialManager() : serialManagerActive(false),
newData(false),
tempBuffer{0},
serialBuffer{0},
device_config_name{0},
device_config_OTAPassword{0},
device_config_OTAPort(0),
camera_config_vflip{0},
camera_config_href{0},
camera_config_framesize{0},
camera_config_quality{0},
wifi_config_name{0},
wifi_config_ssid{0},
wifi_config_password{0} {}
SerialManager::SerialManager(ProjectConfig *projectConfig) : projectConfig(projectConfig),
serialManagerActive(false),
newData(false),
tempBuffer{0},
serialBuffer{0},
device_config_name{0},
device_config_OTAPassword{0},
device_config_OTAPort(0),
camera_config_vflip{0},
camera_config_href{0},
camera_config_framesize{0},
camera_config_quality{0},
wifi_config_name{0},
wifi_config_ssid{0},
wifi_config_password{0} {}
SerialManager::~SerialManager() {}
@ -112,12 +113,10 @@ void SerialManager::handleSerial()
{
strcpy(tempBuffer, serialBuffer); // this temporary copy is necessary to protect the original data because strtok() used in parseData() replaces the commas with \0
parseData(); // split the data into tokens and store them in the data structure
projectConfig.setDeviceConfig(device_config_name, device_config_OTAPassword, &device_config_OTAPort, true); // set the values in the project config
projectConfig.setCameraConfig(&camera_config_vflip, &camera_config_framesize, &camera_config_href, &camera_config_quality, true); // set the values in the project config
projectConfig.setWifiConfig(wifi_config_name, wifi_config_ssid, wifi_config_password, true); // set the values in the project config
projectConfig.save(); // save the config to the EEPROM
projectConfig->setDeviceConfig(device_config_name, device_config_OTAPassword, &device_config_OTAPort, true); // set the values in the project config
projectConfig->setCameraConfig(&camera_config_vflip, &camera_config_framesize, &camera_config_href, &camera_config_quality, true); // set the values in the project config
projectConfig->setWifiConfig(wifi_config_name, wifi_config_ssid, wifi_config_password, true); // set the values in the project config
projectConfig->save(); // save the config to the EEPROM
newData = false; // reset new data
}
}
SerialManager serialManager;
}

View File

@ -1,4 +1,6 @@
#pragma once
#ifndef SERIAL_MANAGER_HPP
#define SERIAL_MANAGER_HPP
#include <Arduino.h>
#include "data/config/project_config.hpp"
@ -6,7 +8,7 @@
class SerialManager
{
public:
SerialManager();
SerialManager(ProjectConfig *projectConfig);
virtual ~SerialManager();
void handleSerial();
@ -37,6 +39,7 @@ private:
char serialBuffer[1000]; //! Need to find the appropriate size for this - count the maximum possible size of a message
char tempBuffer[sizeof(serialBuffer) / sizeof(serialBuffer[0])];
bool newData;
ProjectConfig *projectConfig;
};
extern SerialManager serialManager;
#endif // SERIAL_MANAGER_HPP

View File

@ -58,15 +58,15 @@ void WiFiHandler::setUpADHOC()
log_i("[INFO]: Configuring access point...\n");
WiFi.mode(WIFI_AP);
// You can remove the password parameter if you want the AP to be open.
Serial.printf("\r\nStarting AP. \r\nAP IP address: ");
IPAddress IP = WiFi.softAPIP();
Serial.printf("[INFO]: AP IP address: %s.\r\n", IP.toString().c_str());
// You can remove the password parameter if you want the AP to be open.
WiFi.softAP(WIFI_SSID, WIFI_PASSWORD, ADHOC_CHANNEL, 0, 3); // AP mode with password
WiFi.setTxPower(WIFI_POWER_11dBm);
stateManager->setState((ProgramStates::DeviceStates::WiFiState_e::WiFiState_ADHOC));
stateManager->setState(ProgramStates::DeviceStates::WiFiState_e::WiFiState_ADHOC);
}
// we can't assign wifiManager.resetSettings(); to reset, somehow it gets called straight away.

View File

@ -21,6 +21,7 @@ uint8_t CONTROL_SERVER_PORT = 81;
// it is used to create a unique pointer to a class and ensure exception safety
std::unique_ptr<ProjectConfig> deviceConfig = std::make_unique<ProjectConfig>();
OTA ota(&*deviceConfig);
std::unique_ptr<SerialManager> serialManager = std::make_unique<SerialManager>(&*deviceConfig);
std::unique_ptr<WiFiHandler> wifiHandler = std::make_unique<WiFiHandler>(&*deviceConfig, &wifiStateManager);
std::unique_ptr<LEDManager> ledManager = std::make_unique<LEDManager>(33);
std::shared_ptr<CameraHandler> cameraHandler = std::make_shared<CameraHandler>(&*deviceConfig); //! Create a shared pointer to the camera handler
@ -33,7 +34,7 @@ void setup()
Serial.begin(115200);
Serial.setDebugOutput(true);
ledManager->begin();
deviceConfig->initStructures();
deviceConfig->initConfig();
deviceConfig->load();
cameraHandler->setupCamera();
@ -76,5 +77,5 @@ void loop()
{
ota.HandleOTAUpdate();
ledManager->displayStatus();
serialManager.handleSerial();
serialManager->handleSerial();
}