Use esp32_firewall_api as package

This commit is contained in:
Florian Hoss 2022-07-26 12:49:46 +02:00
parent 28a0753d3a
commit 929aaf39a3
7 changed files with 28 additions and 22 deletions

View file

@ -2,4 +2,3 @@
.vscode
include/theSecrets.h
components/arduino
lib/esp_firewall_api

View file

@ -16,6 +16,8 @@ platform = espressif32
board = az-delivery-devkit-v4
framework = espidf
monitor_speed = 115200
lib_compat_mode = off
build_flags =
'-I include'
'-D ESP_IDF_LWIP_HOOK_FILENAME="lwip_hooks.h"'
'-Iinclude'
'-DESP_IDF_LWIP_HOOK_FILENAME="lwip_hooks.h"'
lib_deps = https://github.com/flohoss/esp32_firewall_api

View file

@ -3,6 +3,12 @@
#include "WiFi.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)
{
const struct ip_hdr *iphdr;
@ -16,8 +22,15 @@ int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif)
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)
{
String ip;
Serial.print("[WiFi] ");
switch (event)
{
@ -31,8 +44,10 @@ void handle_wifi_events(WiFiEvent_t event, WiFiEventInfo_t info)
Serial.println("disconnected");
break;
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
ip = WiFi.localIP().toString();
Serial.print("IP: ");
Serial.println(WiFi.localIP().toString().c_str());
Serial.println(ip);
initFirewall(ip);
break;
default:
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.onEvent(handle_wifi_events, ARDUINO_EVENT_MAX);
WiFi.begin(ssid, psk);
@ -50,13 +66,8 @@ void setup_wifi()
WiFi.config(((u32_t)0x0UL), ((u32_t)0x0UL), ((u32_t)0x0UL));
}
void setup()
{
Serial.begin(115200);
setup_wifi();
}
void loop()
{
sleep(60);
// https://docs.espressif.com/projects/arduino-esp32/en/latest/esp-idf_component.html
sleep(1);
}