File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -214,4 +214,4 @@ class BaseCloudStorage {
214214 }
215215};
216216
217- typedef BaseCloudStorage<http::Esp8266Request > CloudStorage;
217+ typedef BaseCloudStorage<http::GenericEspRequest > CloudStorage;
Original file line number Diff line number Diff line change 11#pragma once
22
33#include " Client.h"
4- #include " Esp8266RequestImpl .h"
4+ #include " GenericEspRequestImpl .h"
55
66namespace http {
7- typedef Request<Esp8266RequestImpl> Esp8266Request ;
7+ typedef Request<GenericEspRequestImpl> GenericEspRequest ;
88};
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include " RequestInterface.h"
4+ #include < HTTPClient.h>
5+
6+ namespace http {
7+ class GenericEspRequestImpl : public RequestInterface {
8+ public:
9+ GenericEspRequestImpl () : RequestInterface() {}
10+
11+ void setUrl (String url) override {
12+ _http.begin (url);
13+ }
14+
15+ void setMethod (Method m) override {
16+ _method = m;
17+ }
18+
19+ void setBody (String body) override {
20+ this ->_body = body;
21+ }
22+
23+ void addHeader (String key, String value) override {
24+ _http.addHeader (key, value);
25+ }
26+
27+ Response execute () override {
28+ int httpCode = -1 ;
29+ if (this ->_method == Method::GET) httpCode = this ->_http .sendRequest (" GET" , this ->_body );
30+ else if (this ->_method == Method::POST) httpCode = this ->_http .sendRequest (" POST" , this ->_body );
31+
32+ Response response;
33+ response.statusCode = httpCode;
34+
35+ if (httpCode == 200 ) response.body = this ->_http .getString ();
36+ else response.body = this ->_http .errorToString (httpCode);
37+
38+ this ->_http .end ();
39+
40+ return response;
41+ }
42+
43+ virtual ~GenericEspRequestImpl () {}
44+
45+ private:
46+ Method _method;
47+ String _body, _url;
48+ HTTPClient _http;
49+ };
50+ };
Original file line number Diff line number Diff line change 11#pragma once
22
3- #include < ESP8266WiFi .h>
4- #include < ESP8266WiFiMulti .h>
3+ #include < WiFi .h>
4+ #include < WiFiMulti .h>
55
66namespace WifiConnection {
7- ESP8266WiFiMulti WiFiMulti;
7+ WiFiMulti wifiMulti ;
88
99 // Sets wifi mode to STA and tries to connect to a network
1010 void tryConnect (String ssid, String pass) {
1111 WiFi.mode (WIFI_STA);
12- WiFiMulti .addAP (ssid.c_str (), pass.c_str ());
12+ wifiMulti .addAP (ssid.c_str (), pass.c_str ());
1313 }
1414
1515 // Method for checking if currently connected to wifi
1616 boolean isConnected () {
17- return WiFiMulti .run () == WL_CONNECTED;
17+ return wifiMulti .run () == WL_CONNECTED;
1818 }
1919};
You can’t perform that action at this time.
0 commit comments