Skip to content

Commit fa9577d

Browse files
committed
Fix adapters for ESP8266/ESP32
1 parent 72497bc commit fa9577d

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

ESP32WebThingAdapter.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#ifdef ESP32
1616

17-
#include <ESP8266WiFi.h> // TODO: maybe unnecessary?
1817
#include <WiFiClient.h>
1918
#include <ArduinoJson.h>
2019
#include <ESPAsyncWebServer.h>
@@ -24,9 +23,9 @@
2423
#define ESP32_MAX_PUT_BODY_SIZE 256
2524

2625

27-
class ESP32WebThingAdapter {
26+
class WebThingAdapter {
2827
public:
29-
ESP32WebThingAdapter(String _name): name(_name), server(80) {
28+
WebThingAdapter(String _name): name(_name), server(80) {
3029
}
3130

3231
void begin() {
@@ -42,27 +41,27 @@ class ESP32WebThingAdapter {
4241
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
4342
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods", "PUT, GET, OPTIONS");
4443

45-
this->server.onNotFound(std::bind(&ESP32WebThingAdapter::handleUnknown, this, std::placeholders::_1));
44+
this->server.onNotFound(std::bind(&WebThingAdapter::handleUnknown, this, std::placeholders::_1));
4645

47-
this->server.on("/", HTTP_GET, std::bind(&ESP32WebThingAdapter::handleThings, this, std::placeholders::_1));
46+
this->server.on("/", HTTP_GET, std::bind(&WebThingAdapter::handleThings, this, std::placeholders::_1));
4847

4948
ThingDevice* device = this->firstDevice;
5049
while (device != nullptr) {
5150
String deviceBase = "/things/" + device->id;
5251
ThingProperty* property = device->firstProperty;
5352
while (property != nullptr) {
5453
String propertyBase = deviceBase + "/properties/" + property->id;
55-
this->server.on(propertyBase.c_str(), HTTP_GET, std::bind(&ESP32WebThingAdapter::handleThingPropertyGet, this, std::placeholders::_1, property));
56-
this->server.on(propertyBase.c_str(), HTTP_PUT,
57-
std::bind(&ESP32WebThingAdapter::handleThingPropertyPut, this, std::placeholders::_1, property),
54+
this->server.on(propertyBase.c_str(), HTTP_GET, std::bind(&WebThingAdapter::handleThingPropertyGet, this, std::placeholders::_1, property));
55+
this->server.on(propertyBase.c_str(), HTTP_PUT,
56+
std::bind(&WebThingAdapter::handleThingPropertyPut, this, std::placeholders::_1, property),
5857
NULL,
59-
std::bind(&ESP32WebThingAdapter::handleBody, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5)
58+
std::bind(&WebThingAdapter::handleBody, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5)
6059
);
6160

6261
property = property->next;
6362
}
6463

65-
this->server.on(deviceBase.c_str(), HTTP_GET, std::bind(&ESP32WebThingAdapter::handleThing, this, std::placeholders::_1, device));
64+
this->server.on(deviceBase.c_str(), HTTP_GET, std::bind(&WebThingAdapter::handleThing, this, std::placeholders::_1, device));
6665

6766
device = device->next;
6867

@@ -71,6 +70,10 @@ class ESP32WebThingAdapter {
7170
this->server.begin();
7271
}
7372

73+
void update() {
74+
// non implemented, async web-server
75+
}
76+
7477
void addDevice(ThingDevice* device) {
7578
if (this->lastDevice == nullptr) {
7679
this->firstDevice = device;
@@ -216,7 +219,7 @@ class ESP32WebThingAdapter {
216219
b_has_body_data = false;
217220
memset(body_data,0,sizeof(body_data));
218221
}
219-
222+
220223
};
221224

222225
#endif // ESP32

ESP8266WebThingAdapter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#include <ESP8266mDNS.h>
2222
#include "Thing.h"
2323

24-
class ESP8266WebThingAdapter {
24+
class WebThingAdapter {
2525
public:
26-
ESP8266WebThingAdapter(String _name): name(_name), server(80) {
26+
WebThingAdapter(String _name): name(_name), server(80) {
2727
}
2828

2929
void begin() {

0 commit comments

Comments
 (0)