mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
remove ESP8266 references
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
#include <APStatus.h>
|
#include <APStatus.h>
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
APStatus::APStatus(AsyncWebServer * server, SecurityManager * securityManager, APSettingsService * apSettingsService)
|
APStatus::APStatus(AsyncWebServer * server, SecurityManager * securityManager, APSettingsService * apSettingsService)
|
||||||
: _apSettingsService(apSettingsService) {
|
: _apSettingsService(apSettingsService) {
|
||||||
server->on(AP_STATUS_SERVICE_PATH,
|
server->on(AP_STATUS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&APStatus::apStatus, this, _1), AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
HTTP_GET,
|
|
||||||
securityManager->wrapRequest(std::bind(&APStatus::apStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void APStatus::apStatus(AsyncWebServerRequest * request) {
|
void APStatus::apStatus(AsyncWebServerRequest * request) {
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
#ifndef APStatus_h
|
#ifndef APStatus_h
|
||||||
#define APStatus_h
|
#define APStatus_h
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
#elif defined(ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <ESPAsyncTCP.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <AsyncJson.h>
|
#include <AsyncJson.h>
|
||||||
|
|||||||
@@ -15,14 +15,13 @@ String ArduinoJsonJWT::getSecret() {
|
|||||||
/*
|
/*
|
||||||
* ESP32 uses mbedtls, ESP2866 uses bearssl.
|
* ESP32 uses mbedtls, ESP2866 uses bearssl.
|
||||||
*
|
*
|
||||||
* Both come with decent HMAC implmentations supporting sha256, as well as others.
|
* Both come with decent HMAC implementations supporting sha256, as well as others.
|
||||||
*
|
*
|
||||||
* No need to pull in additional crypto libraries - lets use what we already have.
|
* No need to pull in additional crypto libraries - lets use what we already have.
|
||||||
*/
|
*/
|
||||||
String ArduinoJsonJWT::sign(String & payload) {
|
String ArduinoJsonJWT::sign(String & payload) {
|
||||||
unsigned char hmacResult[32];
|
unsigned char hmacResult[32];
|
||||||
{
|
{
|
||||||
#ifdef ESP32
|
|
||||||
mbedtls_md_context_t ctx;
|
mbedtls_md_context_t ctx;
|
||||||
mbedtls_md_type_t md_type = MBEDTLS_MD_SHA256;
|
mbedtls_md_type_t md_type = MBEDTLS_MD_SHA256;
|
||||||
mbedtls_md_init(&ctx);
|
mbedtls_md_init(&ctx);
|
||||||
@@ -31,14 +30,6 @@ String ArduinoJsonJWT::sign(String & payload) {
|
|||||||
mbedtls_md_hmac_update(&ctx, (unsigned char *)payload.c_str(), payload.length());
|
mbedtls_md_hmac_update(&ctx, (unsigned char *)payload.c_str(), payload.length());
|
||||||
mbedtls_md_hmac_finish(&ctx, hmacResult);
|
mbedtls_md_hmac_finish(&ctx, hmacResult);
|
||||||
mbedtls_md_free(&ctx);
|
mbedtls_md_free(&ctx);
|
||||||
#elif defined(ESP8266)
|
|
||||||
br_hmac_key_context keyCtx;
|
|
||||||
br_hmac_key_init(&keyCtx, &br_sha256_vtable, _secret.c_str(), _secret.length());
|
|
||||||
br_hmac_context hmacCtx;
|
|
||||||
br_hmac_init(&hmacCtx, &keyCtx, 0);
|
|
||||||
br_hmac_update(&hmacCtx, payload.c_str(), payload.length());
|
|
||||||
br_hmac_out(&hmacCtx, hmacResult);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return encode((char *)hmacResult, 32);
|
return encode((char *)hmacResult, 32);
|
||||||
}
|
}
|
||||||
@@ -94,13 +85,8 @@ void ArduinoJsonJWT::parseJWT(String jwt, JsonDocument & jsonDocument) {
|
|||||||
String ArduinoJsonJWT::encode(const char * cstr, int inputLen) {
|
String ArduinoJsonJWT::encode(const char * cstr, int inputLen) {
|
||||||
// prepare encoder
|
// prepare encoder
|
||||||
base64_encodestate _state;
|
base64_encodestate _state;
|
||||||
#ifdef ESP32
|
|
||||||
base64_init_encodestate(&_state);
|
base64_init_encodestate(&_state);
|
||||||
size_t encodedLength = base64_encode_expected_len(inputLen) + 1;
|
size_t encodedLength = base64_encode_expected_len(inputLen) + 1;
|
||||||
#elif defined(ESP8266)
|
|
||||||
base64_init_encodestate_nonewlines(&_state);
|
|
||||||
size_t encodedLength = base64_encode_expected_len_nonewlines(inputLen) + 1;
|
|
||||||
#endif
|
|
||||||
// prepare buffer of correct length, returning an empty string on failure
|
// prepare buffer of correct length, returning an empty string on failure
|
||||||
char * buffer = (char *)malloc(encodedLength * sizeof(char));
|
char * buffer = (char *)malloc(encodedLength * sizeof(char));
|
||||||
if (buffer == nullptr) {
|
if (buffer == nullptr) {
|
||||||
|
|||||||
@@ -5,12 +5,7 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <libb64/cdecode.h>
|
#include <libb64/cdecode.h>
|
||||||
#include <libb64/cencode.h>
|
#include <libb64/cencode.h>
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
#include <mbedtls/md.h>
|
#include <mbedtls/md.h>
|
||||||
#elif defined(ESP8266)
|
|
||||||
#include <bearssl/bearssl_hmac.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class ArduinoJsonJWT {
|
class ArduinoJsonJWT {
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
#include <AuthenticationService.h>
|
#include <AuthenticationService.h>
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
#if FT_ENABLED(FT_SECURITY)
|
#if FT_ENABLED(FT_SECURITY)
|
||||||
|
|
||||||
AuthenticationService::AuthenticationService(AsyncWebServer * server, SecurityManager * securityManager)
|
AuthenticationService::AuthenticationService(AsyncWebServer * server, SecurityManager * securityManager)
|
||||||
: _securityManager(securityManager)
|
: _securityManager(securityManager)
|
||||||
, _signInHandler(SIGN_IN_PATH, std::bind(&AuthenticationService::signIn, this, std::placeholders::_1, std::placeholders::_2)) {
|
, _signInHandler(SIGN_IN_PATH, std::bind(&AuthenticationService::signIn, this, _1, _2)) {
|
||||||
server->on(VERIFY_AUTHORIZATION_PATH, HTTP_GET, std::bind(&AuthenticationService::verifyAuthorization, this, std::placeholders::_1));
|
server->on(VERIFY_AUTHORIZATION_PATH, HTTP_GET, std::bind(&AuthenticationService::verifyAuthorization, this, _1));
|
||||||
_signInHandler.setMethod(HTTP_POST);
|
_signInHandler.setMethod(HTTP_POST);
|
||||||
_signInHandler.setMaxContentLength(MAX_AUTHENTICATION_SIZE);
|
_signInHandler.setMaxContentLength(MAX_AUTHENTICATION_SIZE);
|
||||||
server->addHandler(&_signInHandler);
|
server->addHandler(&_signInHandler);
|
||||||
|
|||||||
@@ -6,11 +6,7 @@
|
|||||||
class ESPUtils {
|
class ESPUtils {
|
||||||
public:
|
public:
|
||||||
static String defaultDeviceValue(String prefix = "") {
|
static String defaultDeviceValue(String prefix = "") {
|
||||||
#ifdef ESP32
|
|
||||||
return prefix + String((uint32_t)ESP.getEfuseMac(), HEX);
|
return prefix + String((uint32_t)ESP.getEfuseMac(), HEX);
|
||||||
#elif defined(ESP8266)
|
|
||||||
return prefix + String(ESP.getChipId(), HEX);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ void FactoryResetService::handleRequest(AsyncWebServerRequest * request) {
|
|||||||
* Delete function assumes that all files are stored flat, within the config directory.
|
* Delete function assumes that all files are stored flat, within the config directory.
|
||||||
*/
|
*/
|
||||||
void FactoryResetService::factoryReset() {
|
void FactoryResetService::factoryReset() {
|
||||||
#ifdef ESP32
|
|
||||||
/*
|
/*
|
||||||
* Based on LITTLEFS. Modified by proddy
|
* Based on LITTLEFS. Modified by proddy
|
||||||
* Could be replaced with fs.rmdir(FS_CONFIG_DIRECTORY) in IDF 4.2
|
* Could be replaced with fs.rmdir(FS_CONFIG_DIRECTORY) in IDF 4.2
|
||||||
@@ -28,14 +27,5 @@ void FactoryResetService::factoryReset() {
|
|||||||
file.close();
|
file.close();
|
||||||
fs->remove(pathStr);
|
fs->remove(pathStr);
|
||||||
}
|
}
|
||||||
#elif defined(ESP8266)
|
|
||||||
Dir configDirectory = fs->openDir(FS_CONFIG_DIRECTORY);
|
|
||||||
while (configDirectory.next()) {
|
|
||||||
String path = FS_CONFIG_DIRECTORY;
|
|
||||||
path.concat("/");
|
|
||||||
path.concat(configDirectory.fileName());
|
|
||||||
fs->remove(path);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
RestartService::restartNow();
|
RestartService::restartNow();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
#ifndef FactoryResetService_h
|
#ifndef FactoryResetService_h
|
||||||
#define FactoryResetService_h
|
#define FactoryResetService_h
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
#elif defined(ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <ESPAsyncTCP.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <SecurityManager.h>
|
#include <SecurityManager.h>
|
||||||
#include <RestartService.h>
|
#include <RestartService.h>
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#include <FeaturesService.h>
|
#include <FeaturesService.h>
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
FeaturesService::FeaturesService(AsyncWebServer * server) {
|
FeaturesService::FeaturesService(AsyncWebServer * server) {
|
||||||
server->on(FEATURES_SERVICE_PATH, HTTP_GET, std::bind(&FeaturesService::features, this, std::placeholders::_1));
|
server->on(FEATURES_SERVICE_PATH, HTTP_GET, std::bind(&FeaturesService::features, this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeaturesService::features(AsyncWebServerRequest * request) {
|
void FeaturesService::features(AsyncWebServerRequest * request) {
|
||||||
|
|||||||
@@ -3,14 +3,8 @@
|
|||||||
|
|
||||||
#include <Features.h>
|
#include <Features.h>
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
#elif defined(ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <ESPAsyncTCP.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <AsyncJson.h>
|
#include <AsyncJson.h>
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
#define HTTP_ENDPOINT_ORIGIN_ID "http"
|
#define HTTP_ENDPOINT_ORIGIN_ID "http"
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class HttpGetEndpoint {
|
class HttpGetEndpoint {
|
||||||
public:
|
public:
|
||||||
@@ -24,20 +26,14 @@ class HttpGetEndpoint {
|
|||||||
: _stateReader(stateReader)
|
: _stateReader(stateReader)
|
||||||
, _statefulService(statefulService)
|
, _statefulService(statefulService)
|
||||||
, _bufferSize(bufferSize) {
|
, _bufferSize(bufferSize) {
|
||||||
server->on(servicePath.c_str(),
|
server->on(servicePath.c_str(), HTTP_GET, securityManager->wrapRequest(std::bind(&HttpGetEndpoint::fetchSettings, this, _1), authenticationPredicate));
|
||||||
HTTP_GET,
|
|
||||||
securityManager->wrapRequest(std::bind(&HttpGetEndpoint::fetchSettings, this, std::placeholders::_1), authenticationPredicate));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpGetEndpoint(JsonStateReader<T> stateReader,
|
HttpGetEndpoint(JsonStateReader<T> stateReader, StatefulService<T> * statefulService, AsyncWebServer * server, const String & servicePath, size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
||||||
StatefulService<T> * statefulService,
|
|
||||||
AsyncWebServer * server,
|
|
||||||
const String & servicePath,
|
|
||||||
size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
|
||||||
: _stateReader(stateReader)
|
: _stateReader(stateReader)
|
||||||
, _statefulService(statefulService)
|
, _statefulService(statefulService)
|
||||||
, _bufferSize(bufferSize) {
|
, _bufferSize(bufferSize) {
|
||||||
server->on(servicePath.c_str(), HTTP_GET, std::bind(&HttpGetEndpoint::fetchSettings, this, std::placeholders::_1));
|
server->on(servicePath.c_str(), HTTP_GET, std::bind(&HttpGetEndpoint::fetchSettings, this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -69,25 +65,17 @@ class HttpPostEndpoint {
|
|||||||
: _stateReader(stateReader)
|
: _stateReader(stateReader)
|
||||||
, _stateUpdater(stateUpdater)
|
, _stateUpdater(stateUpdater)
|
||||||
, _statefulService(statefulService)
|
, _statefulService(statefulService)
|
||||||
, _updateHandler(servicePath,
|
, _updateHandler(servicePath, securityManager->wrapCallback(std::bind(&HttpPostEndpoint::updateSettings, this, _1, _2), authenticationPredicate), bufferSize)
|
||||||
securityManager->wrapCallback(std::bind(&HttpPostEndpoint::updateSettings, this, std::placeholders::_1, std::placeholders::_2),
|
|
||||||
authenticationPredicate),
|
|
||||||
bufferSize)
|
|
||||||
, _bufferSize(bufferSize) {
|
, _bufferSize(bufferSize) {
|
||||||
_updateHandler.setMethod(HTTP_POST);
|
_updateHandler.setMethod(HTTP_POST);
|
||||||
server->addHandler(&_updateHandler);
|
server->addHandler(&_updateHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpPostEndpoint(JsonStateReader<T> stateReader,
|
HttpPostEndpoint(JsonStateReader<T> stateReader, JsonStateUpdater<T> stateUpdater, StatefulService<T> * statefulService, AsyncWebServer * server, const String & servicePath, size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
||||||
JsonStateUpdater<T> stateUpdater,
|
|
||||||
StatefulService<T> * statefulService,
|
|
||||||
AsyncWebServer * server,
|
|
||||||
const String & servicePath,
|
|
||||||
size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
|
||||||
: _stateReader(stateReader)
|
: _stateReader(stateReader)
|
||||||
, _stateUpdater(stateUpdater)
|
, _stateUpdater(stateUpdater)
|
||||||
, _statefulService(statefulService)
|
, _statefulService(statefulService)
|
||||||
, _updateHandler(servicePath, std::bind(&HttpPostEndpoint::updateSettings, this, std::placeholders::_1, std::placeholders::_2), bufferSize)
|
, _updateHandler(servicePath, std::bind(&HttpPostEndpoint::updateSettings, this, _1, _2), bufferSize)
|
||||||
, _bufferSize(bufferSize) {
|
, _bufferSize(bufferSize) {
|
||||||
_updateHandler.setMethod(HTTP_POST);
|
_updateHandler.setMethod(HTTP_POST);
|
||||||
server->addHandler(&_updateHandler);
|
server->addHandler(&_updateHandler);
|
||||||
@@ -137,12 +125,7 @@ class HttpEndpoint : public HttpGetEndpoint<T>, public HttpPostEndpoint<T> {
|
|||||||
, HttpPostEndpoint<T>(stateReader, stateUpdater, statefulService, server, servicePath, securityManager, authenticationPredicate, bufferSize) {
|
, HttpPostEndpoint<T>(stateReader, stateUpdater, statefulService, server, servicePath, securityManager, authenticationPredicate, bufferSize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpEndpoint(JsonStateReader<T> stateReader,
|
HttpEndpoint(JsonStateReader<T> stateReader, JsonStateUpdater<T> stateUpdater, StatefulService<T> * statefulService, AsyncWebServer * server, const String & servicePath, size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
||||||
JsonStateUpdater<T> stateUpdater,
|
|
||||||
StatefulService<T> * statefulService,
|
|
||||||
AsyncWebServer * server,
|
|
||||||
const String & servicePath,
|
|
||||||
size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
|
||||||
: HttpGetEndpoint<T>(stateReader, statefulService, server, servicePath, bufferSize)
|
: HttpGetEndpoint<T>(stateReader, statefulService, server, servicePath, bufferSize)
|
||||||
, HttpPostEndpoint<T>(stateReader, stateUpdater, statefulService, server, servicePath, bufferSize) {
|
, HttpPostEndpoint<T>(stateReader, stateUpdater, statefulService, server, servicePath, bufferSize) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <StatefulService.h>
|
#include <StatefulService.h>
|
||||||
#include <AsyncMqttClient.h>
|
#include <AsyncMqttClient.h>
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
#define MQTT_ORIGIN_ID "mqtt"
|
#define MQTT_ORIGIN_ID "mqtt"
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@@ -31,11 +33,7 @@ class MqttConnector {
|
|||||||
template <class T>
|
template <class T>
|
||||||
class MqttPub : virtual public MqttConnector<T> {
|
class MqttPub : virtual public MqttConnector<T> {
|
||||||
public:
|
public:
|
||||||
MqttPub(JsonStateReader<T> stateReader,
|
MqttPub(JsonStateReader<T> stateReader, StatefulService<T> * statefulService, AsyncMqttClient * mqttClient, const String & pubTopic = "", size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
||||||
StatefulService<T> * statefulService,
|
|
||||||
AsyncMqttClient * mqttClient,
|
|
||||||
const String & pubTopic = "",
|
|
||||||
size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
|
||||||
: MqttConnector<T>(statefulService, mqttClient, bufferSize)
|
: MqttConnector<T>(statefulService, mqttClient, bufferSize)
|
||||||
, _stateReader(stateReader)
|
, _stateReader(stateReader)
|
||||||
, _pubTopic(pubTopic) {
|
, _pubTopic(pubTopic) {
|
||||||
@@ -76,22 +74,11 @@ class MqttPub : virtual public MqttConnector<T> {
|
|||||||
template <class T>
|
template <class T>
|
||||||
class MqttSub : virtual public MqttConnector<T> {
|
class MqttSub : virtual public MqttConnector<T> {
|
||||||
public:
|
public:
|
||||||
MqttSub(JsonStateUpdater<T> stateUpdater,
|
MqttSub(JsonStateUpdater<T> stateUpdater, StatefulService<T> * statefulService, AsyncMqttClient * mqttClient, const String & subTopic = "", size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
||||||
StatefulService<T> * statefulService,
|
|
||||||
AsyncMqttClient * mqttClient,
|
|
||||||
const String & subTopic = "",
|
|
||||||
size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
|
||||||
: MqttConnector<T>(statefulService, mqttClient, bufferSize)
|
: MqttConnector<T>(statefulService, mqttClient, bufferSize)
|
||||||
, _stateUpdater(stateUpdater)
|
, _stateUpdater(stateUpdater)
|
||||||
, _subTopic(subTopic) {
|
, _subTopic(subTopic) {
|
||||||
MqttConnector<T>::_mqttClient->onMessage(std::bind(&MqttSub::onMqttMessage,
|
MqttConnector<T>::_mqttClient->onMessage(std::bind(&MqttSub::onMqttMessage, this, _1, _2, _3, _4, _5, _6));
|
||||||
this,
|
|
||||||
std::placeholders::_1,
|
|
||||||
std::placeholders::_2,
|
|
||||||
std::placeholders::_3,
|
|
||||||
std::placeholders::_4,
|
|
||||||
std::placeholders::_5,
|
|
||||||
std::placeholders::_6));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSubTopic(const String & subTopic) {
|
void setSubTopic(const String & subTopic) {
|
||||||
|
|||||||
@@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
#include "../../src/emsesp_stub.hpp" // proddy added
|
#include "../../src/emsesp_stub.hpp" // proddy added
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
MqttStatus::MqttStatus(AsyncWebServer * server, MqttSettingsService * mqttSettingsService, SecurityManager * securityManager)
|
MqttStatus::MqttStatus(AsyncWebServer * server, MqttSettingsService * mqttSettingsService, SecurityManager * securityManager)
|
||||||
: _mqttSettingsService(mqttSettingsService) {
|
: _mqttSettingsService(mqttSettingsService) {
|
||||||
server->on(MQTT_STATUS_SERVICE_PATH,
|
server->on(MQTT_STATUS_SERVICE_PATH,
|
||||||
HTTP_GET,
|
HTTP_GET,
|
||||||
securityManager->wrapRequest(std::bind(&MqttStatus::mqttStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED));
|
securityManager->wrapRequest(std::bind(&MqttStatus::mqttStatus, this, _1), AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MqttStatus::mqttStatus(AsyncWebServerRequest * request) {
|
void MqttStatus::mqttStatus(AsyncWebServerRequest * request) {
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
#ifndef MqttStatus_h
|
#ifndef MqttStatus_h
|
||||||
#define MqttStatus_h
|
#define MqttStatus_h
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
#elif defined(ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <ESPAsyncTCP.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <MqttSettingsService.h>
|
#include <MqttSettingsService.h>
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <AsyncJson.h>
|
#include <AsyncJson.h>
|
||||||
|
|||||||
@@ -2,15 +2,17 @@
|
|||||||
|
|
||||||
#include "../../src/emsesp_stub.hpp" // proddy added
|
#include "../../src/emsesp_stub.hpp" // proddy added
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
NTPSettingsService::NTPSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
NTPSettingsService::NTPSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
||||||
: _httpEndpoint(NTPSettings::read, NTPSettings::update, this, server, NTP_SETTINGS_SERVICE_PATH, securityManager)
|
: _httpEndpoint(NTPSettings::read, NTPSettings::update, this, server, NTP_SETTINGS_SERVICE_PATH, securityManager)
|
||||||
, _fsPersistence(NTPSettings::read, NTPSettings::update, this, fs, NTP_SETTINGS_FILE)
|
, _fsPersistence(NTPSettings::read, NTPSettings::update, this, fs, NTP_SETTINGS_FILE)
|
||||||
, _timeHandler(TIME_PATH, securityManager->wrapCallback(std::bind(&NTPSettingsService::configureTime, this, std::placeholders::_1, std::placeholders::_2), AuthenticationPredicates::IS_ADMIN)) {
|
, _timeHandler(TIME_PATH, securityManager->wrapCallback(std::bind(&NTPSettingsService::configureTime, this, _1, _2), AuthenticationPredicates::IS_ADMIN)) {
|
||||||
_timeHandler.setMethod(HTTP_POST);
|
_timeHandler.setMethod(HTTP_POST);
|
||||||
_timeHandler.setMaxContentLength(MAX_TIME_SIZE);
|
_timeHandler.setMaxContentLength(MAX_TIME_SIZE);
|
||||||
server->addHandler(&_timeHandler);
|
server->addHandler(&_timeHandler);
|
||||||
|
|
||||||
WiFi.onEvent(std::bind(&NTPSettingsService::WiFiEvent, this, std::placeholders::_1));
|
WiFi.onEvent(std::bind(&NTPSettingsService::WiFiEvent, this, _1));
|
||||||
|
|
||||||
addUpdateHandler([&](const String & originId) { configureNTP(); }, false);
|
addUpdateHandler([&](const String & originId) { configureNTP(); }, false);
|
||||||
}
|
}
|
||||||
@@ -24,6 +26,7 @@ void NTPSettingsService::begin() {
|
|||||||
void NTPSettingsService::WiFiEvent(WiFiEvent_t event) {
|
void NTPSettingsService::WiFiEvent(WiFiEvent_t event) {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||||
|
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
||||||
emsesp::EMSESP::logger().info(F("WiFi connection dropped, stopping NTP"));
|
emsesp::EMSESP::logger().info(F("WiFi connection dropped, stopping NTP"));
|
||||||
connected_ = false;
|
connected_ = false;
|
||||||
configureNTP();
|
configureNTP();
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#include <NTPStatus.h>
|
#include <NTPStatus.h>
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
NTPStatus::NTPStatus(AsyncWebServer * server, SecurityManager * securityManager) {
|
NTPStatus::NTPStatus(AsyncWebServer * server, SecurityManager * securityManager) {
|
||||||
server->on(NTP_STATUS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&NTPStatus::ntpStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED));
|
server->on(NTP_STATUS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&NTPStatus::ntpStatus, this, _1), AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -2,15 +2,10 @@
|
|||||||
#define NTPStatus_h
|
#define NTPStatus_h
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#ifdef ESP32
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
#include <lwip/apps/sntp.h>
|
#include <lwip/apps/sntp.h>
|
||||||
#elif defined(ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <ESPAsyncTCP.h>
|
|
||||||
#include <sntp.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <AsyncJson.h>
|
#include <AsyncJson.h>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include <NetworkSettingsService.h>
|
#include <NetworkSettingsService.h>
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
NetworkSettingsService::NetworkSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
NetworkSettingsService::NetworkSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
||||||
: _httpEndpoint(NetworkSettings::read, NetworkSettings::update, this, server, NETWORK_SETTINGS_SERVICE_PATH, securityManager)
|
: _httpEndpoint(NetworkSettings::read, NetworkSettings::update, this, server, NETWORK_SETTINGS_SERVICE_PATH, securityManager)
|
||||||
, _fsPersistence(NetworkSettings::read, NetworkSettings::update, this, fs, NETWORK_SETTINGS_FILE)
|
, _fsPersistence(NetworkSettings::read, NetworkSettings::update, this, fs, NETWORK_SETTINGS_FILE)
|
||||||
@@ -17,7 +19,7 @@ NetworkSettingsService::NetworkSettingsService(AsyncWebServer * server, FS * fs,
|
|||||||
WiFi.mode(WIFI_MODE_MAX);
|
WiFi.mode(WIFI_MODE_MAX);
|
||||||
WiFi.mode(WIFI_MODE_NULL);
|
WiFi.mode(WIFI_MODE_NULL);
|
||||||
|
|
||||||
WiFi.onEvent(std::bind(&NetworkSettingsService::WiFiEvent, this, std::placeholders::_1));
|
WiFi.onEvent(std::bind(&NetworkSettingsService::WiFiEvent, this, _1));
|
||||||
|
|
||||||
addUpdateHandler([&](const String & originId) { reconfigureWiFiConnection(); }, false);
|
addUpdateHandler([&](const String & originId) { reconfigureWiFiConnection(); }, false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
#include "../../src/emsesp_stub.hpp" // proddy added
|
#include "../../src/emsesp_stub.hpp" // proddy added
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
NetworkStatus::NetworkStatus(AsyncWebServer * server, SecurityManager * securityManager) {
|
NetworkStatus::NetworkStatus(AsyncWebServer * server, SecurityManager * securityManager) {
|
||||||
server->on(NETWORK_STATUS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&NetworkStatus::networkStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED));
|
server->on(NETWORK_STATUS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&NetworkStatus::networkStatus, this, _1), AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkStatus::networkStatus(AsyncWebServerRequest * request) {
|
void NetworkStatus::networkStatus(AsyncWebServerRequest * request) {
|
||||||
|
|||||||
@@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
#include "../../src/emsesp_stub.hpp" // proddy added
|
#include "../../src/emsesp_stub.hpp" // proddy added
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
OTASettingsService::OTASettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
OTASettingsService::OTASettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
||||||
: _httpEndpoint(OTASettings::read, OTASettings::update, this, server, OTA_SETTINGS_SERVICE_PATH, securityManager)
|
: _httpEndpoint(OTASettings::read, OTASettings::update, this, server, OTA_SETTINGS_SERVICE_PATH, securityManager)
|
||||||
, _fsPersistence(OTASettings::read, OTASettings::update, this, fs, OTA_SETTINGS_FILE)
|
, _fsPersistence(OTASettings::read, OTASettings::update, this, fs, OTA_SETTINGS_FILE)
|
||||||
, _arduinoOTA(nullptr) {
|
, _arduinoOTA(nullptr) {
|
||||||
WiFi.onEvent(std::bind(&OTASettingsService::onStationModeGotIP, this, std::placeholders::_1, std::placeholders::_2), WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP);
|
WiFi.onEvent(std::bind(&OTASettingsService::WiFiEvent, this, _1, _2));
|
||||||
addUpdateHandler([&](const String & originId) { configureArduinoOTA(); }, false);
|
addUpdateHandler([&](const String & originId) { configureArduinoOTA(); }, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,12 +25,11 @@ void OTASettingsService::loop() {
|
|||||||
|
|
||||||
void OTASettingsService::configureArduinoOTA() {
|
void OTASettingsService::configureArduinoOTA() {
|
||||||
if (_arduinoOTA) {
|
if (_arduinoOTA) {
|
||||||
#ifdef ESP32
|
|
||||||
_arduinoOTA->end();
|
_arduinoOTA->end();
|
||||||
#endif
|
|
||||||
delete _arduinoOTA;
|
delete _arduinoOTA;
|
||||||
_arduinoOTA = nullptr;
|
_arduinoOTA = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_state.enabled) {
|
if (_state.enabled) {
|
||||||
_arduinoOTA = new ArduinoOTAClass;
|
_arduinoOTA = new ArduinoOTAClass;
|
||||||
_arduinoOTA->setPort(_state.port);
|
_arduinoOTA->setPort(_state.port);
|
||||||
@@ -62,6 +63,13 @@ void OTASettingsService::configureArduinoOTA() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OTASettingsService::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info) {
|
void OTASettingsService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
|
switch (event) {
|
||||||
|
case SYSTEM_EVENT_STA_GOT_IP:
|
||||||
|
case SYSTEM_EVENT_ETH_GOT_IP:
|
||||||
configureArduinoOTA();
|
configureArduinoOTA();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class OTASettingsService : public StatefulService<OTASettings> {
|
|||||||
ArduinoOTAClass * _arduinoOTA;
|
ArduinoOTAClass * _arduinoOTA;
|
||||||
|
|
||||||
void configureArduinoOTA();
|
void configureArduinoOTA();
|
||||||
void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info);
|
void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // end OTASettingsService_h
|
#endif // end OTASettingsService_h
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include <RestartService.h>
|
#include <RestartService.h>
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
RestartService::RestartService(AsyncWebServer * server, SecurityManager * securityManager) {
|
RestartService::RestartService(AsyncWebServer * server, SecurityManager * securityManager) {
|
||||||
server->on(RESTART_SERVICE_PATH,
|
server->on(RESTART_SERVICE_PATH, HTTP_POST, securityManager->wrapRequest(std::bind(&RestartService::restart, this, _1), AuthenticationPredicates::IS_ADMIN));
|
||||||
HTTP_POST,
|
|
||||||
securityManager->wrapRequest(std::bind(&RestartService::restart, this, std::placeholders::_1), AuthenticationPredicates::IS_ADMIN));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RestartService::restart(AsyncWebServerRequest * request) {
|
void RestartService::restart(AsyncWebServerRequest * request) {
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
#ifndef RestartService_h
|
#ifndef RestartService_h
|
||||||
#define RestartService_h
|
#define RestartService_h
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
#elif defined(ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <ESPAsyncTCP.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <SecurityManager.h>
|
#include <SecurityManager.h>
|
||||||
|
|||||||
@@ -6,10 +6,8 @@
|
|||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#ifdef ESP32
|
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/semphr.h>
|
#include <freertos/semphr.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEFAULT_BUFFER_SIZE
|
#ifndef DEFAULT_BUFFER_SIZE
|
||||||
#define DEFAULT_BUFFER_SIZE 1024
|
#define DEFAULT_BUFFER_SIZE 1024
|
||||||
@@ -45,16 +43,10 @@ template <class T>
|
|||||||
class StatefulService {
|
class StatefulService {
|
||||||
public:
|
public:
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
#ifdef ESP32
|
|
||||||
StatefulService(Args &&... args)
|
StatefulService(Args &&... args)
|
||||||
: _state(std::forward<Args>(args)...)
|
: _state(std::forward<Args>(args)...)
|
||||||
, _accessMutex(xSemaphoreCreateRecursiveMutex()) {
|
, _accessMutex(xSemaphoreCreateRecursiveMutex()) {
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
StatefulService(Args &&... args)
|
|
||||||
: _state(std::forward<Args>(args)...) {
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
update_handler_id_t addUpdateHandler(StateUpdateCallback cb, bool allowRemove = true) {
|
update_handler_id_t addUpdateHandler(StateUpdateCallback cb, bool allowRemove = true) {
|
||||||
if (!cb) {
|
if (!cb) {
|
||||||
@@ -131,21 +123,15 @@ class StatefulService {
|
|||||||
T _state;
|
T _state;
|
||||||
|
|
||||||
inline void beginTransaction() {
|
inline void beginTransaction() {
|
||||||
#ifdef ESP32
|
|
||||||
xSemaphoreTakeRecursive(_accessMutex, portMAX_DELAY);
|
xSemaphoreTakeRecursive(_accessMutex, portMAX_DELAY);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void endTransaction() {
|
inline void endTransaction() {
|
||||||
#ifdef ESP32
|
|
||||||
xSemaphoreGiveRecursive(_accessMutex);
|
xSemaphoreGiveRecursive(_accessMutex);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef ESP32
|
|
||||||
SemaphoreHandle_t _accessMutex;
|
SemaphoreHandle_t _accessMutex;
|
||||||
#endif
|
|
||||||
std::list<StateUpdateHandlerInfo_t> _updateHandlers;
|
std::list<StateUpdateHandlerInfo_t> _updateHandlers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,10 @@
|
|||||||
#include <UploadFirmwareService.h>
|
#include <UploadFirmwareService.h>
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
UploadFirmwareService::UploadFirmwareService(AsyncWebServer * server, SecurityManager * securityManager)
|
UploadFirmwareService::UploadFirmwareService(AsyncWebServer * server, SecurityManager * securityManager)
|
||||||
: _securityManager(securityManager) {
|
: _securityManager(securityManager) {
|
||||||
server->on(UPLOAD_FIRMWARE_PATH,
|
server->on(UPLOAD_FIRMWARE_PATH, HTTP_POST, std::bind(&UploadFirmwareService::uploadComplete, this, _1), std::bind(&UploadFirmwareService::handleUpload, this, _1, _2, _3, _4, _5, _6));
|
||||||
HTTP_POST,
|
|
||||||
std::bind(&UploadFirmwareService::uploadComplete, this, std::placeholders::_1),
|
|
||||||
std::bind(&UploadFirmwareService::handleUpload,
|
|
||||||
this,
|
|
||||||
std::placeholders::_1,
|
|
||||||
std::placeholders::_2,
|
|
||||||
std::placeholders::_3,
|
|
||||||
std::placeholders::_4,
|
|
||||||
std::placeholders::_5,
|
|
||||||
std::placeholders::_6));
|
|
||||||
#ifdef ESP8266
|
|
||||||
Update.runAsync(true);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UploadFirmwareService::handleUpload(AsyncWebServerRequest * request, const String & filename, size_t index, uint8_t * data, size_t len, bool final) {
|
void UploadFirmwareService::handleUpload(AsyncWebServerRequest * request, const String & filename, size_t index, uint8_t * data, size_t len, bool final) {
|
||||||
@@ -72,9 +61,5 @@ void UploadFirmwareService::handleError(AsyncWebServerRequest * request, int cod
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UploadFirmwareService::handleEarlyDisconnect() {
|
void UploadFirmwareService::handleEarlyDisconnect() {
|
||||||
#ifdef ESP32
|
|
||||||
Update.abort();
|
Update.abort();
|
||||||
#elif defined(ESP8266)
|
|
||||||
Update.end();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,9 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
#include <Update.h>
|
#include <Update.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
#elif defined(ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <ESPAsyncTCP.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <SecurityManager.h>
|
#include <SecurityManager.h>
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
#define WEB_SOCKET_ORIGIN "websocket"
|
#define WEB_SOCKET_ORIGIN "websocket"
|
||||||
#define WEB_SOCKET_ORIGIN_CLIENT_ID_PREFIX "websocket:"
|
#define WEB_SOCKET_ORIGIN_CLIENT_ID_PREFIX "websocket:"
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class WebSocketConnector {
|
class WebSocketConnector {
|
||||||
protected:
|
protected:
|
||||||
@@ -18,27 +20,15 @@ class WebSocketConnector {
|
|||||||
AsyncWebSocket _webSocket;
|
AsyncWebSocket _webSocket;
|
||||||
size_t _bufferSize;
|
size_t _bufferSize;
|
||||||
|
|
||||||
WebSocketConnector(StatefulService<T> * statefulService,
|
WebSocketConnector(StatefulService<T> * statefulService, AsyncWebServer * server, const char * webSocketPath, SecurityManager * securityManager, AuthenticationPredicate authenticationPredicate, size_t bufferSize)
|
||||||
AsyncWebServer * server,
|
|
||||||
const char * webSocketPath,
|
|
||||||
SecurityManager * securityManager,
|
|
||||||
AuthenticationPredicate authenticationPredicate,
|
|
||||||
size_t bufferSize)
|
|
||||||
: _statefulService(statefulService)
|
: _statefulService(statefulService)
|
||||||
, _server(server)
|
, _server(server)
|
||||||
, _webSocket(webSocketPath)
|
, _webSocket(webSocketPath)
|
||||||
, _bufferSize(bufferSize) {
|
, _bufferSize(bufferSize) {
|
||||||
_webSocket.setFilter(securityManager->filterRequest(authenticationPredicate));
|
_webSocket.setFilter(securityManager->filterRequest(authenticationPredicate));
|
||||||
_webSocket.onEvent(std::bind(&WebSocketConnector::onWSEvent,
|
_webSocket.onEvent(std::bind(&WebSocketConnector::onWSEvent, this, _1, _2, _3, _4, _5, _6));
|
||||||
this,
|
|
||||||
std::placeholders::_1,
|
|
||||||
std::placeholders::_2,
|
|
||||||
std::placeholders::_3,
|
|
||||||
std::placeholders::_4,
|
|
||||||
std::placeholders::_5,
|
|
||||||
std::placeholders::_6));
|
|
||||||
_server->addHandler(&_webSocket);
|
_server->addHandler(&_webSocket);
|
||||||
_server->on(webSocketPath, HTTP_GET, std::bind(&WebSocketConnector::forbidden, this, std::placeholders::_1));
|
_server->on(webSocketPath, HTTP_GET, std::bind(&WebSocketConnector::forbidden, this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocketConnector(StatefulService<T> * statefulService, AsyncWebServer * server, const char * webSocketPath, size_t bufferSize)
|
WebSocketConnector(StatefulService<T> * statefulService, AsyncWebServer * server, const char * webSocketPath, size_t bufferSize)
|
||||||
@@ -46,14 +36,7 @@ class WebSocketConnector {
|
|||||||
, _server(server)
|
, _server(server)
|
||||||
, _webSocket(webSocketPath)
|
, _webSocket(webSocketPath)
|
||||||
, _bufferSize(bufferSize) {
|
, _bufferSize(bufferSize) {
|
||||||
_webSocket.onEvent(std::bind(&WebSocketConnector::onWSEvent,
|
_webSocket.onEvent(std::bind(&WebSocketConnector::onWSEvent, this, _1, _2, _3, _4, _5, _6));
|
||||||
this,
|
|
||||||
std::placeholders::_1,
|
|
||||||
std::placeholders::_2,
|
|
||||||
std::placeholders::_3,
|
|
||||||
std::placeholders::_4,
|
|
||||||
std::placeholders::_5,
|
|
||||||
std::placeholders::_6));
|
|
||||||
_server->addHandler(&_webSocket);
|
_server->addHandler(&_webSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,11 +67,7 @@ class WebSocketTx : virtual public WebSocketConnector<T> {
|
|||||||
WebSocketConnector<T>::_statefulService->addUpdateHandler([&](const String & originId) { transmitData(nullptr, originId); }, false);
|
WebSocketConnector<T>::_statefulService->addUpdateHandler([&](const String & originId) { transmitData(nullptr, originId); }, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocketTx(JsonStateReader<T> stateReader,
|
WebSocketTx(JsonStateReader<T> stateReader, StatefulService<T> * statefulService, AsyncWebServer * server, const char * webSocketPath, size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
||||||
StatefulService<T> * statefulService,
|
|
||||||
AsyncWebServer * server,
|
|
||||||
const char * webSocketPath,
|
|
||||||
size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
|
||||||
: WebSocketConnector<T>(statefulService, server, webSocketPath, bufferSize)
|
: WebSocketConnector<T>(statefulService, server, webSocketPath, bufferSize)
|
||||||
, _stateReader(stateReader) {
|
, _stateReader(stateReader) {
|
||||||
WebSocketConnector<T>::_statefulService->addUpdateHandler([&](const String & originId) { transmitData(nullptr, originId); }, false);
|
WebSocketConnector<T>::_statefulService->addUpdateHandler([&](const String & originId) { transmitData(nullptr, originId); }, false);
|
||||||
@@ -161,11 +140,7 @@ class WebSocketRx : virtual public WebSocketConnector<T> {
|
|||||||
, _stateUpdater(stateUpdater) {
|
, _stateUpdater(stateUpdater) {
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocketRx(JsonStateUpdater<T> stateUpdater,
|
WebSocketRx(JsonStateUpdater<T> stateUpdater, StatefulService<T> * statefulService, AsyncWebServer * server, const char * webSocketPath, size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
||||||
StatefulService<T> * statefulService,
|
|
||||||
AsyncWebServer * server,
|
|
||||||
const char * webSocketPath,
|
|
||||||
size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
|
||||||
: WebSocketConnector<T>(statefulService, server, webSocketPath, bufferSize)
|
: WebSocketConnector<T>(statefulService, server, webSocketPath, bufferSize)
|
||||||
, _stateUpdater(stateUpdater) {
|
, _stateUpdater(stateUpdater) {
|
||||||
}
|
}
|
||||||
@@ -207,12 +182,7 @@ class WebSocketTxRx : public WebSocketTx<T>, public WebSocketRx<T> {
|
|||||||
, WebSocketRx<T>(stateUpdater, statefulService, server, webSocketPath, securityManager, authenticationPredicate, bufferSize) {
|
, WebSocketRx<T>(stateUpdater, statefulService, server, webSocketPath, securityManager, authenticationPredicate, bufferSize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocketTxRx(JsonStateReader<T> stateReader,
|
WebSocketTxRx(JsonStateReader<T> stateReader, JsonStateUpdater<T> stateUpdater, StatefulService<T> * statefulService, AsyncWebServer * server, const char * webSocketPath, size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
||||||
JsonStateUpdater<T> stateUpdater,
|
|
||||||
StatefulService<T> * statefulService,
|
|
||||||
AsyncWebServer * server,
|
|
||||||
const char * webSocketPath,
|
|
||||||
size_t bufferSize = DEFAULT_BUFFER_SIZE)
|
|
||||||
: WebSocketConnector<T>(statefulService, server, webSocketPath, bufferSize)
|
: WebSocketConnector<T>(statefulService, server, webSocketPath, bufferSize)
|
||||||
, WebSocketTx<T>(stateReader, statefulService, server, webSocketPath, bufferSize)
|
, WebSocketTx<T>(stateReader, statefulService, server, webSocketPath, bufferSize)
|
||||||
, WebSocketRx<T>(stateUpdater, statefulService, server, webSocketPath, bufferSize) {
|
, WebSocketRx<T>(stateUpdater, statefulService, server, webSocketPath, bufferSize) {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
#include <WiFiScanner.h>
|
#include <WiFiScanner.h>
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
WiFiScanner::WiFiScanner(AsyncWebServer * server, SecurityManager * securityManager) {
|
WiFiScanner::WiFiScanner(AsyncWebServer * server, SecurityManager * securityManager) {
|
||||||
server->on(SCAN_NETWORKS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&WiFiScanner::scanNetworks, this, std::placeholders::_1), AuthenticationPredicates::IS_ADMIN));
|
server->on(SCAN_NETWORKS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&WiFiScanner::scanNetworks, this, _1), AuthenticationPredicates::IS_ADMIN));
|
||||||
server->on(LIST_NETWORKS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&WiFiScanner::listNetworks, this, std::placeholders::_1), AuthenticationPredicates::IS_ADMIN));
|
server->on(LIST_NETWORKS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&WiFiScanner::listNetworks, this, _1), AuthenticationPredicates::IS_ADMIN));
|
||||||
};
|
};
|
||||||
|
|
||||||
void WiFiScanner::scanNetworks(AsyncWebServerRequest * request) {
|
void WiFiScanner::scanNetworks(AsyncWebServerRequest * request) {
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
#ifndef WiFiScanner_h
|
#ifndef WiFiScanner_h
|
||||||
#define WiFiScanner_h
|
#define WiFiScanner_h
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
#elif defined(ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <ESPAsyncTCP.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <AsyncJson.h>
|
#include <AsyncJson.h>
|
||||||
@@ -26,10 +21,6 @@ class WiFiScanner {
|
|||||||
private:
|
private:
|
||||||
void scanNetworks(AsyncWebServerRequest * request);
|
void scanNetworks(AsyncWebServerRequest * request);
|
||||||
void listNetworks(AsyncWebServerRequest * request);
|
void listNetworks(AsyncWebServerRequest * request);
|
||||||
|
|
||||||
#ifdef ESP8266
|
|
||||||
uint8_t convertEncryptionType(uint8_t encryptionType);
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // end WiFiScanner_h
|
#endif // end WiFiScanner_h
|
||||||
|
|||||||
@@ -18,10 +18,12 @@
|
|||||||
|
|
||||||
#include "emsesp.h"
|
#include "emsesp.h"
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
WebAPIService::WebAPIService(AsyncWebServer * server) {
|
WebAPIService::WebAPIService(AsyncWebServer * server) {
|
||||||
server->on(EMSESP_API_SERVICE_PATH, HTTP_GET, std::bind(&WebAPIService::webAPIService, this, std::placeholders::_1));
|
server->on(EMSESP_API_SERVICE_PATH, HTTP_GET, std::bind(&WebAPIService::webAPIService, this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// e.g. http://ems-esp/api?device=boiler&cmd=wwtemp&data=20&id=1
|
// e.g. http://ems-esp/api?device=boiler&cmd=wwtemp&data=20&id=1
|
||||||
|
|||||||
@@ -23,15 +23,10 @@ namespace emsesp {
|
|||||||
using namespace std::placeholders; // for `_1` etc
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
WebDevicesService::WebDevicesService(AsyncWebServer * server, SecurityManager * securityManager)
|
WebDevicesService::WebDevicesService(AsyncWebServer * server, SecurityManager * securityManager)
|
||||||
: _device_dataHandler(DEVICE_DATA_SERVICE_PATH,
|
: _device_dataHandler(DEVICE_DATA_SERVICE_PATH, securityManager->wrapCallback(std::bind(&WebDevicesService::device_data, this, _1, _2), AuthenticationPredicates::IS_AUTHENTICATED)) {
|
||||||
securityManager->wrapCallback(std::bind(&WebDevicesService::device_data, this, _1, _2), AuthenticationPredicates::IS_AUTHENTICATED)) {
|
server->on(EMSESP_DEVICES_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&WebDevicesService::all_devices, this, _1), AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
server->on(EMSESP_DEVICES_SERVICE_PATH,
|
|
||||||
HTTP_GET,
|
|
||||||
securityManager->wrapRequest(std::bind(&WebDevicesService::all_devices, this, _1), AuthenticationPredicates::IS_AUTHENTICATED));
|
|
||||||
|
|
||||||
server->on(SCAN_DEVICES_SERVICE_PATH,
|
server->on(SCAN_DEVICES_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&WebDevicesService::scan_devices, this, _1), AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
HTTP_GET,
|
|
||||||
securityManager->wrapRequest(std::bind(&WebDevicesService::scan_devices, this, _1), AuthenticationPredicates::IS_AUTHENTICATED));
|
|
||||||
|
|
||||||
_device_dataHandler.setMethod(HTTP_POST);
|
_device_dataHandler.setMethod(HTTP_POST);
|
||||||
_device_dataHandler.setMaxContentLength(256);
|
_device_dataHandler.setMaxContentLength(256);
|
||||||
|
|||||||
@@ -18,12 +18,14 @@
|
|||||||
|
|
||||||
#include "emsesp.h"
|
#include "emsesp.h"
|
||||||
|
|
||||||
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
WebStatusService::WebStatusService(AsyncWebServer * server, SecurityManager * securityManager) {
|
WebStatusService::WebStatusService(AsyncWebServer * server, SecurityManager * securityManager) {
|
||||||
// rest endpoint for web page
|
// rest endpoint for web page
|
||||||
server->on(EMSESP_STATUS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&WebStatusService::webStatusService, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED));
|
server->on(EMSESP_STATUS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&WebStatusService::webStatusService, this, _1), AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
WiFi.onEvent(std::bind(&WebStatusService::WiFiEvent, this, std::placeholders::_1, std::placeholders::_2));
|
WiFi.onEvent(std::bind(&WebStatusService::WiFiEvent, this, _1, _2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// handles both WiFI and Ethernet
|
// handles both WiFI and Ethernet
|
||||||
|
|||||||
Reference in New Issue
Block a user