Include ESP8266 example

This commit is contained in:
Florian Hoss 2022-07-29 10:50:40 +02:00
parent 8dcf7c5e4d
commit 1d9b34f9ff
5 changed files with 144 additions and 0 deletions

View file

@ -0,0 +1,53 @@
#include <Arduino.h>
#include "theSecrets.h"
#include "theCerts.h"
#include "ESP8266WiFi.h"
#include "esp8266/Firewall.hpp"
#include "esp8266/API.hpp"
fw::Firewall *firewall;
fw::API *firewallApi;
WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
WiFiEventHandler wifiGotIpHandler;
void initFirewall(const String ip)
{
firewall = new fw::Firewall();
firewallApi = new fw::API(firewall, cert, key, username, password, ip);
}
void onConnect(const WiFiEventStationModeConnected &event)
{
Serial.println("[WiFi] connected");
}
void onDisconnect(const WiFiEventStationModeDisconnected &event)
{
Serial.println("[WiFi] disconnected");
WiFi.reconnect();
}
void onGotIp(const WiFiEventStationModeGotIP &event)
{
initFirewall(WiFi.localIP().toString());
}
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
wifiConnectHandler = WiFi.onStationModeConnected(onConnect);
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onDisconnect);
wifiGotIpHandler = WiFi.onStationModeGotIP(onGotIp);
WiFi.begin(ssid, psk);
Serial.println("[WiFi] connecting...");
}
void loop()
{
if (firewallApi != NULL)
firewallApi->handle_client();
}