Moved cloudUrl into newsettings

This commit is contained in:
2021-12-29 05:42:08 +01:00
parent 3b73865000
commit c7fb30a870
5 changed files with 28 additions and 30 deletions

View File

@ -6,6 +6,17 @@
// esp-idf includes
#include <esp_log.h>
// 3rdparty lib includes
#include <espwifistack.h>
#include <esphttpdutils.h>
#include <fmt/core.h>
#include <tickchrono.h>
// local includes
#include "globals.h"
#include "utils.h"
#include "newsettings.h"
using namespace std::chrono_literals;
namespace {
@ -26,8 +37,7 @@ std::optional<espchrono::millis_clock::time_point> lastCloudSend;
void initCloud()
{
if (settings.cloudSettings.cloudEnabled &&
!stringSettings.cloudUrl.empty() &&
esphttpdutils::urlverify(stringSettings.cloudUrl))
!configs.cloudUrl.value.empty())
{
createCloud();
if (!cloudClient)
@ -156,8 +166,7 @@ void cloudCollect()
void cloudSend()
{
if (settings.cloudSettings.cloudEnabled &&
!stringSettings.cloudUrl.empty() &&
esphttpdutils::urlverify(stringSettings.cloudUrl))
!configs.cloudUrl.value.empty())
{
if (!cloudClient)
{
@ -222,7 +231,7 @@ void createCloud()
lastCreateTry = espchrono::millis_clock::now();
const esp_websocket_client_config_t config = {
.uri = stringSettings.cloudUrl.c_str(),
.uri = configs.cloudUrl.value.c_str(),
};
cloudClient = espcpputils::websocket_client{&config};

View File

@ -1,15 +1,11 @@
#pragma once
// system includes
#include <string>
// 3rdparty lib includes
#include <wrappers/websocket_client.h>
#include <espwifistack.h>
#include <esphttpdutils.h>
#include <fmt/core.h>
#include <tickchrono.h>
// local includes
#include "globals.h"
#include "utils.h"
#include <espchrono.h>
#ifdef FEATURE_CLOUD
extern espcpputils::websocket_client cloudClient;

View File

@ -86,7 +86,7 @@ public:
ConfigWrapper<bool> wifiApEnabled {true, DoReset, {}, "wifiApEnabled" };
ConfigWrapper<std::string> wifiApName {defaultHostname, DoReset, StringMinMaxSize<4, 32>, "wifiApName" };
ConfigWrapper<std::string> wifiApKey {"Passwort_123", DoReset, StringOr<StringEmpty, StringMinMaxSize<8, 64>>, "wifiApKey" };
ConfigWrapper<std::string> wifiApKey {"Passwort_123", DoReset, StringOr<StringEmpty, StringMinMaxSize<8, 64>>, "wifiApKey" };
ConfigWrapper<uint8_t> wifiApChannel {1, DoReset, {}, "wifiApChannel" };
ConfigWrapper<wifi_auth_mode_t> wifiApAuthmode{WIFI_AUTH_WPA2_PSK, DoReset, {}, "wifiApAuthmode" };
@ -103,11 +103,13 @@ public:
ConfigWrapper<std::string> bluetoothName {defaultHostname, DoReset, StringMinMaxSize<4, 32>, "bluetoothName" };
ConfigWrapper<bool> reverseBeep {false, DoReset, {}, "reverseBeep" };
ConfigWrapper<uint8_t> reverseBeepFreq0 {3, DoReset, {}, "revBeepFreq0" };
ConfigWrapper<uint8_t> reverseBeepFreq1 {0, DoReset, {}, "revBeepFreq1" };
ConfigWrapper<uint8_t> reverseBeepFreq0 {3, DoReset, {}, "revBeepFreq0" };
ConfigWrapper<uint8_t> reverseBeepFreq1 {0, DoReset, {}, "revBeepFreq1" };
ConfigWrapper<int16_t> reverseBeepDuration0{500, DoReset, {}, "revBeepDur0" };
ConfigWrapper<int16_t> reverseBeepDuration1{500, DoReset, {}, "revBeepDur1" };
ConfigWrapper<std::string> cloudUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "cloudUrl" };
#define NEW_SETTINGS(x) \
x(baseMacAddressOverride) \
x(hostname) \
@ -241,7 +243,9 @@ public:
x(reverseBeepFreq0) \
x(reverseBeepFreq1) \
x(reverseBeepDuration0) \
//x(reverseBeepDuration1)
x(reverseBeepDuration1) \
\
//x(cloudUrl)
template<typename T>
void callForEveryConfig(T &&callback)
@ -249,7 +253,7 @@ public:
#define HELPER(x) callback(x);
NEW_SETTINGS(HELPER)
#undef HELPER
callback(reverseBeepDuration1);
callback(cloudUrl);
}
auto getAllConfigParams()
@ -258,7 +262,7 @@ public:
#define HELPER(x) std::ref<ConfigWrapperInterface>(x),
NEW_SETTINGS(HELPER)
#undef HELPER
std::ref<ConfigWrapperInterface>(reverseBeepDuration1)
std::ref<ConfigWrapperInterface>(cloudUrl)
);
}
};

View File

@ -9,9 +9,6 @@ StringSettings makeDefaultStringSettings()
#endif
return {
#ifdef FEATURE_CLOUD
.cloudUrl = {},
#endif
#ifdef FEATURE_UDPCLOUD
.udpCloudUrl = {},
#endif

View File

@ -6,10 +6,6 @@
struct StringSettings
{
#ifdef FEATURE_CLOUD
std::string cloudUrl;
#endif
#ifdef FEATURE_UDPCLOUD
std::string udpCloudUrl;
#endif
@ -53,10 +49,6 @@ struct StringSettings
template<typename T>
void StringSettings::executeForEveryCommonSetting(T &&callable)
{
#ifdef FEATURE_CLOUD
callable("cloudUrl", cloudUrl);
#endif
#ifdef FEATURE_UDPCLOUD
callable("udpUrl", udpCloudUrl);
#endif