14
14
15
15
#ifdef ESP32
16
16
17
- #include < ESP8266WiFi.h> // TODO: maybe unnecessary?
18
17
#include < WiFiClient.h>
19
18
#include < ArduinoJson.h>
20
19
#include < ESPAsyncWebServer.h>
24
23
#define ESP32_MAX_PUT_BODY_SIZE 256
25
24
26
25
27
- class ESP32WebThingAdapter {
26
+ class WebThingAdapter {
28
27
public:
29
- ESP32WebThingAdapter (String _name): name(_name), server(80 ) {
28
+ WebThingAdapter (String _name): name(_name), server(80 ) {
30
29
}
31
30
32
31
void begin () {
@@ -42,27 +41,27 @@ class ESP32WebThingAdapter {
42
41
DefaultHeaders::Instance ().addHeader (" Access-Control-Allow-Origin" , " *" );
43
42
DefaultHeaders::Instance ().addHeader (" Access-Control-Allow-Methods" , " PUT, GET, OPTIONS" );
44
43
45
- this ->server .onNotFound (std::bind (&ESP32WebThingAdapter ::handleUnknown, this , std::placeholders::_1));
44
+ this ->server .onNotFound (std::bind (&WebThingAdapter ::handleUnknown, this , std::placeholders::_1));
46
45
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));
48
47
49
48
ThingDevice* device = this ->firstDevice ;
50
49
while (device != nullptr ) {
51
50
String deviceBase = " /things/" + device->id ;
52
51
ThingProperty* property = device->firstProperty ;
53
52
while (property != nullptr ) {
54
53
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),
58
57
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)
60
59
);
61
60
62
61
property = property->next ;
63
62
}
64
63
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));
66
65
67
66
device = device->next ;
68
67
@@ -71,6 +70,10 @@ class ESP32WebThingAdapter {
71
70
this ->server .begin ();
72
71
}
73
72
73
+ void update () {
74
+ // non implemented, async web-server
75
+ }
76
+
74
77
void addDevice (ThingDevice* device) {
75
78
if (this ->lastDevice == nullptr ) {
76
79
this ->firstDevice = device;
@@ -216,7 +219,7 @@ class ESP32WebThingAdapter {
216
219
b_has_body_data = false ;
217
220
memset (body_data,0 ,sizeof (body_data));
218
221
}
219
-
222
+
220
223
};
221
224
222
225
#endif // ESP32
0 commit comments