-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add dashboard * change data handling * use root scope * tunneling frontend from external website * remove unused code
- Loading branch information
1 parent
a10339e
commit 5c48b09
Showing
4 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include "ESPAsyncTunnel.h" | ||
#include "mdns.h" | ||
|
||
/** | ||
* ClientRequestTunnel | ||
*/ | ||
ClientRequestTunnel::ClientRequestTunnel() { | ||
ESP_LOGD("[ClientRequestTunnel]","Constructor!"); | ||
} | ||
|
||
bool ClientRequestTunnel::open(String target, String url) { | ||
open(getForwardURL(target, url)); | ||
} | ||
|
||
bool ClientRequestTunnel::open(String url) { | ||
ESP_LOGD("[ClientRequestTunnel]","open"); | ||
this->url = url; | ||
this->http = new HTTPClient(); | ||
if (!http->begin(url)){ | ||
ESP_LOGE("[ClientRequestTunnel]","Unable to connect!"); | ||
ok = false; | ||
return ok; | ||
} | ||
ESP_LOGI("[ClientRequestTunnel]","Connected!"); | ||
this->http->collectHeaders(headerkeays, 1); | ||
this->httpCode = http->GET(); | ||
if(this->httpCode == HTTP_CODE_OK || this->httpCode == HTTP_CODE_MOVED_PERMANENTLY) { | ||
ok = true; | ||
ESP_LOGI("[ClientRequestTunnel]","HttpCode -> OK"); | ||
} else { | ||
ok = false; | ||
ESP_LOGE("[ClientRequestTunnel]","GET... failed, error: %s\n", http->errorToString(httpCode).c_str()); | ||
} | ||
return ok; | ||
} | ||
|
||
ClientRequestTunnel::~ClientRequestTunnel() { | ||
ESP_LOGD("[ClientRequestTunnel]","Destructor!"); | ||
if (http){ | ||
http->end(); | ||
delete(http); | ||
} | ||
} | ||
|
||
bool ClientRequestTunnel::isOK() { | ||
return this->ok; | ||
} | ||
|
||
int ClientRequestTunnel::getHttpCode() { | ||
return this->httpCode; | ||
} | ||
|
||
String ClientRequestTunnel::getString() { | ||
return http ? http->getString() : ""; | ||
} | ||
|
||
Stream* ClientRequestTunnel::getStream() { | ||
return (http && http->connected()) ? http->getStreamPtr() : NULL; | ||
} | ||
|
||
String ClientRequestTunnel::getContentType() { | ||
return http ? http->header(headerkeays[0]) : ""; | ||
} | ||
|
||
size_t ClientRequestTunnel::getSize() { | ||
return http ? http->getSize() : 0 ; | ||
} | ||
|
||
HTTPClient* ClientRequestTunnel::getHTTPClient() { | ||
return http; | ||
} | ||
|
||
String ClientRequestTunnel::getForwardURL(String target_address, String url) { | ||
String forward_path; | ||
if (target_address.isEmpty()){ | ||
forward_path = url; | ||
} else if (url.indexOf("http",0)==0) { | ||
// does it start with http ? | ||
int pos = url.indexOf("/",9); | ||
String requestd_path = url.substring(pos); | ||
forward_path = target_address + requestd_path; | ||
} else { | ||
forward_path = target_address + url; | ||
} | ||
|
||
ESP_LOGI("[ClientRequestTunnel]","%s -> %s\n", url.c_str(),forward_path.c_str()); | ||
return forward_path; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <Arduino.h> | ||
#include "HTTPClient.h" | ||
#include "ESPAsyncWebServer.h" | ||
|
||
#ifndef _ESPAsyncTunnel_H_ | ||
#define _ESPAsyncTunnel_H_ | ||
|
||
|
||
/** | ||
* Http Client which returns the data from a remove Server | ||
*/ | ||
class ClientRequestTunnel { | ||
public: | ||
ClientRequestTunnel(); | ||
bool open(String targetUrl, String url); | ||
bool open(String url); | ||
~ClientRequestTunnel(); | ||
String getString(); | ||
Stream* getStream(); | ||
String getContentType(); | ||
size_t getSize(); | ||
HTTPClient* getHTTPClient(); | ||
bool isOK(); | ||
int getHttpCode(); | ||
String getForwardURL(String target, String url); | ||
|
||
private: | ||
bool ok = false; | ||
HTTPClient *http; | ||
String url; | ||
const char* headerkeays[1] = {"Content-Type"}; | ||
int httpCode; | ||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
thanks to | ||
[Phil Schatzmann](https://github.com/pschatzmann/esp32_vue_example) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters