Skip to content

Commit 3b4bfaa

Browse files
committed
remove ESP8266 references
1 parent 2b6a986 commit 3b4bfaa

32 files changed

+89
-234
lines changed

lib/framework/APStatus.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include <APStatus.h>
22

3+
using namespace std::placeholders; // for `_1` etc
4+
35
APStatus::APStatus(AsyncWebServer * server, SecurityManager * securityManager, APSettingsService * apSettingsService)
46
: _apSettingsService(apSettingsService) {
5-
server->on(AP_STATUS_SERVICE_PATH,
6-
HTTP_GET,
7-
securityManager->wrapRequest(std::bind(&APStatus::apStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED));
7+
server->on(AP_STATUS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&APStatus::apStatus, this, _1), AuthenticationPredicates::IS_AUTHENTICATED));
88
}
99

1010
void APStatus::apStatus(AsyncWebServerRequest * request) {

lib/framework/APStatus.h

-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
#ifndef APStatus_h
22
#define APStatus_h
33

4-
#ifdef ESP32
54
#include <WiFi.h>
65
#include <AsyncTCP.h>
7-
#elif defined(ESP8266)
8-
#include <ESP8266WiFi.h>
9-
#include <ESPAsyncTCP.h>
10-
#endif
116

127
#include <ArduinoJson.h>
138
#include <AsyncJson.h>

lib/framework/ArduinoJsonJWT.cpp

+1-15
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ String ArduinoJsonJWT::getSecret() {
1515
/*
1616
* ESP32 uses mbedtls, ESP2866 uses bearssl.
1717
*
18-
* Both come with decent HMAC implmentations supporting sha256, as well as others.
18+
* Both come with decent HMAC implementations supporting sha256, as well as others.
1919
*
2020
* No need to pull in additional crypto libraries - lets use what we already have.
2121
*/
2222
String ArduinoJsonJWT::sign(String & payload) {
2323
unsigned char hmacResult[32];
2424
{
25-
#ifdef ESP32
2625
mbedtls_md_context_t ctx;
2726
mbedtls_md_type_t md_type = MBEDTLS_MD_SHA256;
2827
mbedtls_md_init(&ctx);
@@ -31,14 +30,6 @@ String ArduinoJsonJWT::sign(String & payload) {
3130
mbedtls_md_hmac_update(&ctx, (unsigned char *)payload.c_str(), payload.length());
3231
mbedtls_md_hmac_finish(&ctx, hmacResult);
3332
mbedtls_md_free(&ctx);
34-
#elif defined(ESP8266)
35-
br_hmac_key_context keyCtx;
36-
br_hmac_key_init(&keyCtx, &br_sha256_vtable, _secret.c_str(), _secret.length());
37-
br_hmac_context hmacCtx;
38-
br_hmac_init(&hmacCtx, &keyCtx, 0);
39-
br_hmac_update(&hmacCtx, payload.c_str(), payload.length());
40-
br_hmac_out(&hmacCtx, hmacResult);
41-
#endif
4233
}
4334
return encode((char *)hmacResult, 32);
4435
}
@@ -94,13 +85,8 @@ void ArduinoJsonJWT::parseJWT(String jwt, JsonDocument & jsonDocument) {
9485
String ArduinoJsonJWT::encode(const char * cstr, int inputLen) {
9586
// prepare encoder
9687
base64_encodestate _state;
97-
#ifdef ESP32
9888
base64_init_encodestate(&_state);
9989
size_t encodedLength = base64_encode_expected_len(inputLen) + 1;
100-
#elif defined(ESP8266)
101-
base64_init_encodestate_nonewlines(&_state);
102-
size_t encodedLength = base64_encode_expected_len_nonewlines(inputLen) + 1;
103-
#endif
10490
// prepare buffer of correct length, returning an empty string on failure
10591
char * buffer = (char *)malloc(encodedLength * sizeof(char));
10692
if (buffer == nullptr) {

lib/framework/ArduinoJsonJWT.h

-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
#include <ArduinoJson.h>
66
#include <libb64/cdecode.h>
77
#include <libb64/cencode.h>
8-
9-
#ifdef ESP32
108
#include <mbedtls/md.h>
11-
#elif defined(ESP8266)
12-
#include <bearssl/bearssl_hmac.h>
13-
#endif
149

1510
class ArduinoJsonJWT {
1611
private:

lib/framework/AuthenticationService.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#include <AuthenticationService.h>
22

3+
using namespace std::placeholders; // for `_1` etc
4+
35
#if FT_ENABLED(FT_SECURITY)
46

57
AuthenticationService::AuthenticationService(AsyncWebServer * server, SecurityManager * securityManager)
68
: _securityManager(securityManager)
7-
, _signInHandler(SIGN_IN_PATH, std::bind(&AuthenticationService::signIn, this, std::placeholders::_1, std::placeholders::_2)) {
8-
server->on(VERIFY_AUTHORIZATION_PATH, HTTP_GET, std::bind(&AuthenticationService::verifyAuthorization, this, std::placeholders::_1));
9+
, _signInHandler(SIGN_IN_PATH, std::bind(&AuthenticationService::signIn, this, _1, _2)) {
10+
server->on(VERIFY_AUTHORIZATION_PATH, HTTP_GET, std::bind(&AuthenticationService::verifyAuthorization, this, _1));
911
_signInHandler.setMethod(HTTP_POST);
1012
_signInHandler.setMaxContentLength(MAX_AUTHENTICATION_SIZE);
1113
server->addHandler(&_signInHandler);

lib/framework/ESPUtils.h

-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
class ESPUtils {
77
public:
88
static String defaultDeviceValue(String prefix = "") {
9-
#ifdef ESP32
109
return prefix + String((uint32_t)ESP.getEfuseMac(), HEX);
11-
#elif defined(ESP8266)
12-
return prefix + String(ESP.getChipId(), HEX);
13-
#endif
1410
}
1511
};
1612

lib/framework/FactoryResetService.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ void FactoryResetService::handleRequest(AsyncWebServerRequest * request) {
1616
* Delete function assumes that all files are stored flat, within the config directory.
1717
*/
1818
void FactoryResetService::factoryReset() {
19-
#ifdef ESP32
2019
/*
2120
* Based on LITTLEFS. Modified by proddy
2221
* Could be replaced with fs.rmdir(FS_CONFIG_DIRECTORY) in IDF 4.2
@@ -28,14 +27,5 @@ void FactoryResetService::factoryReset() {
2827
file.close();
2928
fs->remove(pathStr);
3029
}
31-
#elif defined(ESP8266)
32-
Dir configDirectory = fs->openDir(FS_CONFIG_DIRECTORY);
33-
while (configDirectory.next()) {
34-
String path = FS_CONFIG_DIRECTORY;
35-
path.concat("/");
36-
path.concat(configDirectory.fileName());
37-
fs->remove(path);
38-
}
39-
#endif
4030
RestartService::restartNow();
4131
}

lib/framework/FactoryResetService.h

-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
#ifndef FactoryResetService_h
22
#define FactoryResetService_h
33

4-
#ifdef ESP32
54
#include <WiFi.h>
65
#include <AsyncTCP.h>
7-
#elif defined(ESP8266)
8-
#include <ESP8266WiFi.h>
9-
#include <ESPAsyncTCP.h>
10-
#endif
11-
126
#include <ESPAsyncWebServer.h>
137
#include <SecurityManager.h>
148
#include <RestartService.h>

lib/framework/FeaturesService.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include <FeaturesService.h>
22

3+
using namespace std::placeholders; // for `_1` etc
4+
35
FeaturesService::FeaturesService(AsyncWebServer * server) {
4-
server->on(FEATURES_SERVICE_PATH, HTTP_GET, std::bind(&FeaturesService::features, this, std::placeholders::_1));
6+
server->on(FEATURES_SERVICE_PATH, HTTP_GET, std::bind(&FeaturesService::features, this, _1));
57
}
68

79
void FeaturesService::features(AsyncWebServerRequest * request) {

lib/framework/FeaturesService.h

-6
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@
33

44
#include <Features.h>
55

6-
#ifdef ESP32
76
#include <WiFi.h>
87
#include <AsyncTCP.h>
9-
#elif defined(ESP8266)
10-
#include <ESP8266WiFi.h>
11-
#include <ESPAsyncTCP.h>
12-
#endif
13-
148
#include <ArduinoJson.h>
159
#include <AsyncJson.h>
1610
#include <ESPAsyncWebServer.h>

lib/framework/HttpEndpoint.h

+9-26
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#define HTTP_ENDPOINT_ORIGIN_ID "http"
1313

14+
using namespace std::placeholders; // for `_1` etc
15+
1416
template <class T>
1517
class HttpGetEndpoint {
1618
public:
@@ -24,20 +26,14 @@ class HttpGetEndpoint {
2426
: _stateReader(stateReader)
2527
, _statefulService(statefulService)
2628
, _bufferSize(bufferSize) {
27-
server->on(servicePath.c_str(),
28-
HTTP_GET,
29-
securityManager->wrapRequest(std::bind(&HttpGetEndpoint::fetchSettings, this, std::placeholders::_1), authenticationPredicate));
29+
server->on(servicePath.c_str(), HTTP_GET, securityManager->wrapRequest(std::bind(&HttpGetEndpoint::fetchSettings, this, _1), authenticationPredicate));
3030
}
3131

32-
HttpGetEndpoint(JsonStateReader<T> stateReader,
33-
StatefulService<T> * statefulService,
34-
AsyncWebServer * server,
35-
const String & servicePath,
36-
size_t bufferSize = DEFAULT_BUFFER_SIZE)
32+
HttpGetEndpoint(JsonStateReader<T> stateReader, StatefulService<T> * statefulService, AsyncWebServer * server, const String & servicePath, size_t bufferSize = DEFAULT_BUFFER_SIZE)
3733
: _stateReader(stateReader)
3834
, _statefulService(statefulService)
3935
, _bufferSize(bufferSize) {
40-
server->on(servicePath.c_str(), HTTP_GET, std::bind(&HttpGetEndpoint::fetchSettings, this, std::placeholders::_1));
36+
server->on(servicePath.c_str(), HTTP_GET, std::bind(&HttpGetEndpoint::fetchSettings, this, _1));
4137
}
4238

4339
protected:
@@ -69,25 +65,17 @@ class HttpPostEndpoint {
6965
: _stateReader(stateReader)
7066
, _stateUpdater(stateUpdater)
7167
, _statefulService(statefulService)
72-
, _updateHandler(servicePath,
73-
securityManager->wrapCallback(std::bind(&HttpPostEndpoint::updateSettings, this, std::placeholders::_1, std::placeholders::_2),
74-
authenticationPredicate),
75-
bufferSize)
68+
, _updateHandler(servicePath, securityManager->wrapCallback(std::bind(&HttpPostEndpoint::updateSettings, this, _1, _2), authenticationPredicate), bufferSize)
7669
, _bufferSize(bufferSize) {
7770
_updateHandler.setMethod(HTTP_POST);
7871
server->addHandler(&_updateHandler);
7972
}
8073

81-
HttpPostEndpoint(JsonStateReader<T> stateReader,
82-
JsonStateUpdater<T> stateUpdater,
83-
StatefulService<T> * statefulService,
84-
AsyncWebServer * server,
85-
const String & servicePath,
86-
size_t bufferSize = DEFAULT_BUFFER_SIZE)
74+
HttpPostEndpoint(JsonStateReader<T> stateReader, JsonStateUpdater<T> stateUpdater, StatefulService<T> * statefulService, AsyncWebServer * server, const String & servicePath, size_t bufferSize = DEFAULT_BUFFER_SIZE)
8775
: _stateReader(stateReader)
8876
, _stateUpdater(stateUpdater)
8977
, _statefulService(statefulService)
90-
, _updateHandler(servicePath, std::bind(&HttpPostEndpoint::updateSettings, this, std::placeholders::_1, std::placeholders::_2), bufferSize)
78+
, _updateHandler(servicePath, std::bind(&HttpPostEndpoint::updateSettings, this, _1, _2), bufferSize)
9179
, _bufferSize(bufferSize) {
9280
_updateHandler.setMethod(HTTP_POST);
9381
server->addHandler(&_updateHandler);
@@ -137,12 +125,7 @@ class HttpEndpoint : public HttpGetEndpoint<T>, public HttpPostEndpoint<T> {
137125
, HttpPostEndpoint<T>(stateReader, stateUpdater, statefulService, server, servicePath, securityManager, authenticationPredicate, bufferSize) {
138126
}
139127

140-
HttpEndpoint(JsonStateReader<T> stateReader,
141-
JsonStateUpdater<T> stateUpdater,
142-
StatefulService<T> * statefulService,
143-
AsyncWebServer * server,
144-
const String & servicePath,
145-
size_t bufferSize = DEFAULT_BUFFER_SIZE)
128+
HttpEndpoint(JsonStateReader<T> stateReader, JsonStateUpdater<T> stateUpdater, StatefulService<T> * statefulService, AsyncWebServer * server, const String & servicePath, size_t bufferSize = DEFAULT_BUFFER_SIZE)
146129
: HttpGetEndpoint<T>(stateReader, statefulService, server, servicePath, bufferSize)
147130
, HttpPostEndpoint<T>(stateReader, stateUpdater, statefulService, server, servicePath, bufferSize) {
148131
}

lib/framework/MqttPubSub.h

+5-18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <StatefulService.h>
55
#include <AsyncMqttClient.h>
66

7+
using namespace std::placeholders; // for `_1` etc
8+
79
#define MQTT_ORIGIN_ID "mqtt"
810

911
template <class T>
@@ -31,11 +33,7 @@ class MqttConnector {
3133
template <class T>
3234
class MqttPub : virtual public MqttConnector<T> {
3335
public:
34-
MqttPub(JsonStateReader<T> stateReader,
35-
StatefulService<T> * statefulService,
36-
AsyncMqttClient * mqttClient,
37-
const String & pubTopic = "",
38-
size_t bufferSize = DEFAULT_BUFFER_SIZE)
36+
MqttPub(JsonStateReader<T> stateReader, StatefulService<T> * statefulService, AsyncMqttClient * mqttClient, const String & pubTopic = "", size_t bufferSize = DEFAULT_BUFFER_SIZE)
3937
: MqttConnector<T>(statefulService, mqttClient, bufferSize)
4038
, _stateReader(stateReader)
4139
, _pubTopic(pubTopic) {
@@ -76,22 +74,11 @@ class MqttPub : virtual public MqttConnector<T> {
7674
template <class T>
7775
class MqttSub : virtual public MqttConnector<T> {
7876
public:
79-
MqttSub(JsonStateUpdater<T> stateUpdater,
80-
StatefulService<T> * statefulService,
81-
AsyncMqttClient * mqttClient,
82-
const String & subTopic = "",
83-
size_t bufferSize = DEFAULT_BUFFER_SIZE)
77+
MqttSub(JsonStateUpdater<T> stateUpdater, StatefulService<T> * statefulService, AsyncMqttClient * mqttClient, const String & subTopic = "", size_t bufferSize = DEFAULT_BUFFER_SIZE)
8478
: MqttConnector<T>(statefulService, mqttClient, bufferSize)
8579
, _stateUpdater(stateUpdater)
8680
, _subTopic(subTopic) {
87-
MqttConnector<T>::_mqttClient->onMessage(std::bind(&MqttSub::onMqttMessage,
88-
this,
89-
std::placeholders::_1,
90-
std::placeholders::_2,
91-
std::placeholders::_3,
92-
std::placeholders::_4,
93-
std::placeholders::_5,
94-
std::placeholders::_6));
81+
MqttConnector<T>::_mqttClient->onMessage(std::bind(&MqttSub::onMqttMessage, this, _1, _2, _3, _4, _5, _6));
9582
}
9683

9784
void setSubTopic(const String & subTopic) {

lib/framework/MqttStatus.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
#include "../../src/emsesp_stub.hpp" // proddy added
44

5+
using namespace std::placeholders; // for `_1` etc
6+
57
MqttStatus::MqttStatus(AsyncWebServer * server, MqttSettingsService * mqttSettingsService, SecurityManager * securityManager)
68
: _mqttSettingsService(mqttSettingsService) {
79
server->on(MQTT_STATUS_SERVICE_PATH,
810
HTTP_GET,
9-
securityManager->wrapRequest(std::bind(&MqttStatus::mqttStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED));
11+
securityManager->wrapRequest(std::bind(&MqttStatus::mqttStatus, this, _1), AuthenticationPredicates::IS_AUTHENTICATED));
1012
}
1113

1214
void MqttStatus::mqttStatus(AsyncWebServerRequest * request) {

lib/framework/MqttStatus.h

-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
#ifndef MqttStatus_h
22
#define MqttStatus_h
33

4-
#ifdef ESP32
54
#include <WiFi.h>
65
#include <AsyncTCP.h>
7-
#elif defined(ESP8266)
8-
#include <ESP8266WiFi.h>
9-
#include <ESPAsyncTCP.h>
10-
#endif
11-
126
#include <MqttSettingsService.h>
137
#include <ArduinoJson.h>
148
#include <AsyncJson.h>

lib/framework/NTPSettingsService.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
#include "../../src/emsesp_stub.hpp" // proddy added
44

5+
using namespace std::placeholders; // for `_1` etc
6+
57
NTPSettingsService::NTPSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
68
: _httpEndpoint(NTPSettings::read, NTPSettings::update, this, server, NTP_SETTINGS_SERVICE_PATH, securityManager)
79
, _fsPersistence(NTPSettings::read, NTPSettings::update, this, fs, NTP_SETTINGS_FILE)
8-
, _timeHandler(TIME_PATH, securityManager->wrapCallback(std::bind(&NTPSettingsService::configureTime, this, std::placeholders::_1, std::placeholders::_2), AuthenticationPredicates::IS_ADMIN)) {
10+
, _timeHandler(TIME_PATH, securityManager->wrapCallback(std::bind(&NTPSettingsService::configureTime, this, _1, _2), AuthenticationPredicates::IS_ADMIN)) {
911
_timeHandler.setMethod(HTTP_POST);
1012
_timeHandler.setMaxContentLength(MAX_TIME_SIZE);
1113
server->addHandler(&_timeHandler);
1214

13-
WiFi.onEvent(std::bind(&NTPSettingsService::WiFiEvent, this, std::placeholders::_1));
15+
WiFi.onEvent(std::bind(&NTPSettingsService::WiFiEvent, this, _1));
1416

1517
addUpdateHandler([&](const String & originId) { configureNTP(); }, false);
1618
}
@@ -24,6 +26,7 @@ void NTPSettingsService::begin() {
2426
void NTPSettingsService::WiFiEvent(WiFiEvent_t event) {
2527
switch (event) {
2628
case SYSTEM_EVENT_STA_DISCONNECTED:
29+
case SYSTEM_EVENT_ETH_DISCONNECTED:
2730
emsesp::EMSESP::logger().info(F("WiFi connection dropped, stopping NTP"));
2831
connected_ = false;
2932
configureNTP();

lib/framework/NTPStatus.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include <NTPStatus.h>
22

3+
using namespace std::placeholders; // for `_1` etc
4+
35
NTPStatus::NTPStatus(AsyncWebServer * server, SecurityManager * securityManager) {
4-
server->on(NTP_STATUS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&NTPStatus::ntpStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED));
6+
server->on(NTP_STATUS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&NTPStatus::ntpStatus, this, _1), AuthenticationPredicates::IS_AUTHENTICATED));
57
}
68

79
/*

lib/framework/NTPStatus.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@
22
#define NTPStatus_h
33

44
#include <time.h>
5-
#ifdef ESP32
5+
66
#include <WiFi.h>
77
#include <AsyncTCP.h>
88
#include <lwip/apps/sntp.h>
9-
#elif defined(ESP8266)
10-
#include <ESP8266WiFi.h>
11-
#include <ESPAsyncTCP.h>
12-
#include <sntp.h>
13-
#endif
149

1510
#include <ArduinoJson.h>
1611
#include <AsyncJson.h>

0 commit comments

Comments
 (0)