Use esp32_firewall_api as package
This commit is contained in:
parent
28a0753d3a
commit
929aaf39a3
7 changed files with 28 additions and 22 deletions
6
.gitmodules
vendored
6
.gitmodules
vendored
|
@ -1,9 +1,3 @@
|
||||||
[submodule "ESP32Firewall/components/arduino"]
|
[submodule "ESP32Firewall/components/arduino"]
|
||||||
path = ESP32Firewall/components/arduino
|
path = ESP32Firewall/components/arduino
|
||||||
url = https://github.com/espressif/arduino-esp32.git
|
url = https://github.com/espressif/arduino-esp32.git
|
||||||
[submodule "ESP32Firewall/esp_firewall_api"]
|
|
||||||
path = ESP32Firewall/lib/esp_firewall_api
|
|
||||||
url = https://github.com/flohoss/esp_firewall_api
|
|
||||||
[submodule "ESP32Firewall/lib/esp_firewall_api"]
|
|
||||||
path = ESP32Firewall/lib/esp_firewall_api
|
|
||||||
url = https://github.com/flohoss/esp_firewall_api
|
|
||||||
|
|
1
ESP32Firewall/.gitignore
vendored
1
ESP32Firewall/.gitignore
vendored
|
@ -2,4 +2,3 @@
|
||||||
.vscode
|
.vscode
|
||||||
include/theSecrets.h
|
include/theSecrets.h
|
||||||
components/arduino
|
components/arduino
|
||||||
lib/esp_firewall_api
|
|
||||||
|
|
|
@ -16,6 +16,8 @@ platform = espressif32
|
||||||
board = az-delivery-devkit-v4
|
board = az-delivery-devkit-v4
|
||||||
framework = espidf
|
framework = espidf
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
lib_compat_mode = off
|
||||||
build_flags =
|
build_flags =
|
||||||
'-Iinclude'
|
'-Iinclude'
|
||||||
'-DESP_IDF_LWIP_HOOK_FILENAME="lwip_hooks.h"'
|
'-DESP_IDF_LWIP_HOOK_FILENAME="lwip_hooks.h"'
|
||||||
|
lib_deps = https://github.com/flohoss/esp32_firewall_api
|
||||||
|
|
|
@ -3,6 +3,12 @@
|
||||||
#include "WiFi.h"
|
#include "WiFi.h"
|
||||||
#include "lwip_hooks.h"
|
#include "lwip_hooks.h"
|
||||||
|
|
||||||
|
#include "Firewall.hpp"
|
||||||
|
#include "API.hpp"
|
||||||
|
|
||||||
|
fw::Firewall *firewall;
|
||||||
|
fw::API *firewallApi;
|
||||||
|
|
||||||
int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif)
|
int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif)
|
||||||
{
|
{
|
||||||
const struct ip_hdr *iphdr;
|
const struct ip_hdr *iphdr;
|
||||||
|
@ -16,8 +22,15 @@ int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initFirewall(const String ip)
|
||||||
|
{
|
||||||
|
firewall = new fw::Firewall();
|
||||||
|
firewallApi = new fw::API(firewall, username, password, ip);
|
||||||
|
}
|
||||||
|
|
||||||
void handle_wifi_events(WiFiEvent_t event, WiFiEventInfo_t info)
|
void handle_wifi_events(WiFiEvent_t event, WiFiEventInfo_t info)
|
||||||
{
|
{
|
||||||
|
String ip;
|
||||||
Serial.print("[WiFi] ");
|
Serial.print("[WiFi] ");
|
||||||
switch (event)
|
switch (event)
|
||||||
{
|
{
|
||||||
|
@ -31,8 +44,10 @@ void handle_wifi_events(WiFiEvent_t event, WiFiEventInfo_t info)
|
||||||
Serial.println("disconnected");
|
Serial.println("disconnected");
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
||||||
|
ip = WiFi.localIP().toString();
|
||||||
Serial.print("IP: ");
|
Serial.print("IP: ");
|
||||||
Serial.println(WiFi.localIP().toString().c_str());
|
Serial.println(ip);
|
||||||
|
initFirewall(ip);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Serial.print("other event: ");
|
Serial.print("other event: ");
|
||||||
|
@ -40,8 +55,9 @@ void handle_wifi_events(WiFiEvent_t event, WiFiEventInfo_t info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_wifi()
|
void setup()
|
||||||
{
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.onEvent(handle_wifi_events, ARDUINO_EVENT_MAX);
|
WiFi.onEvent(handle_wifi_events, ARDUINO_EVENT_MAX);
|
||||||
WiFi.begin(ssid, psk);
|
WiFi.begin(ssid, psk);
|
||||||
|
@ -50,13 +66,8 @@ void setup_wifi()
|
||||||
WiFi.config(((u32_t)0x0UL), ((u32_t)0x0UL), ((u32_t)0x0UL));
|
WiFi.config(((u32_t)0x0UL), ((u32_t)0x0UL), ((u32_t)0x0UL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
Serial.begin(115200);
|
|
||||||
setup_wifi();
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
sleep(60);
|
// https://docs.espressif.com/projects/arduino-esp32/en/latest/esp-idf_component.html
|
||||||
|
sleep(1);
|
||||||
}
|
}
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
namespace fw
|
namespace fw
|
||||||
{
|
{
|
||||||
API::API(fw::Firewall *firewall, const char *cert, const char *key, const char *username, const char *password, const uint16_t port)
|
API::API(fw::Firewall *firewall, const char *cert, const char *key, const char *username, const char *password, const String ip, const uint16_t port)
|
||||||
{
|
{
|
||||||
this->firewall = firewall;
|
this->firewall = firewall;
|
||||||
this->api_ip = WiFi.localIP().toString();
|
this->api_ip = ip;
|
||||||
this->api_port = port;
|
this->api_port = port;
|
||||||
if (this->setup_auth(username, password) == ERROR)
|
if (this->setup_auth(username, password) == ERROR)
|
||||||
endless_loop();
|
endless_loop();
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace fw
|
||||||
class API
|
class API
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
API(Firewall *, const char *cert, const char *key, const char *username, const char *password, const uint16_t port = 8080);
|
API(Firewall *, const char *cert, const char *key, const char *username, const char *password, const String ip, const uint16_t port = 8080);
|
||||||
~API();
|
~API();
|
||||||
void handle_client();
|
void handle_client();
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ void setup()
|
||||||
Serial.print("[WiFi] IP: ");
|
Serial.print("[WiFi] IP: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
firewall = new fw::Firewall();
|
firewall = new fw::Firewall();
|
||||||
firewallApi = new fw::API(firewall, cert, key, username, password);
|
firewallApi = new fw::API(firewall, cert, key, username, password, WiFi.localIP().toString());
|
||||||
wifiServer.begin();
|
wifiServer.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue