Added Wifi Client Mode
This commit is contained in:
parent
6bc0e394ac
commit
349cfed864
@ -16,8 +16,12 @@ board_build.f_flash = 80000000L
|
|||||||
board_build.ldscript = eagle.flash.4m1m.ld
|
board_build.ldscript = eagle.flash.4m1m.ld
|
||||||
|
|
||||||
build_flags=
|
build_flags=
|
||||||
-D WIFI_SSID='"Dark Emergency CTF Timer"'
|
-D WIFI_CLIENT
|
||||||
-D WIFI_PASS='"CaptureTheFlag"'
|
-D WIFI_SSID='"BND_Scanner_#42"'
|
||||||
|
-D WIFI_PASS='"5xMYkerbLMdrsSdF3hpy5DM9"'
|
||||||
|
;-D WIFI_AP
|
||||||
|
;-D WIFI_SSID='"Dark Emergency CTF Timer"'
|
||||||
|
;-D WIFI_PASS='"CaptureTheFlag"'
|
||||||
-D FACTION_1_NAME='"GOF"'
|
-D FACTION_1_NAME='"GOF"'
|
||||||
-D FACTION_2_NAME='"MILIZ"'
|
-D FACTION_2_NAME='"MILIZ"'
|
||||||
-D FACTION_3_NAME='"KGG"'
|
-D FACTION_3_NAME='"KGG"'
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
#ifndef _DEFAULTS_H_
|
#ifndef _DEFAULTS_H_
|
||||||
#define _DEFAULTS_H_
|
#define _DEFAULTS_H_
|
||||||
|
|
||||||
|
#ifndef WIFI_CLIENT
|
||||||
|
#define WIFI_AP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(WIFI_CLIENT) && defined(WIFI_AP)
|
||||||
|
#error "You can't define AP and CLIENT at the same Time!"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef WIFI_SSID
|
#ifndef WIFI_SSID
|
||||||
#define WIFI_SSID "3 Factions CTF Timer"
|
#define WIFI_SSID "3 Factions CTF Timer"
|
||||||
#endif
|
#endif
|
||||||
|
24
src/main.cpp
24
src/main.cpp
@ -7,9 +7,11 @@
|
|||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
|
#include <WiFiMulti.h>
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
|
#include <ESP8266WiFiMulti.h>
|
||||||
#endif
|
#endif
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
@ -51,6 +53,10 @@ Adafruit_INA219 ina219;
|
|||||||
WiFiEventHandler stationConnectedHandler;
|
WiFiEventHandler stationConnectedHandler;
|
||||||
WiFiEventHandler stationDisconnectedHandler;
|
WiFiEventHandler stationDisconnectedHandler;
|
||||||
|
|
||||||
|
#ifdef WIFI_CLIENT
|
||||||
|
ESP8266WiFiMulti wifiMulti;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CAPTIVE
|
#ifdef CAPTIVE
|
||||||
DNSServer dnsServer;
|
DNSServer dnsServer;
|
||||||
#endif
|
#endif
|
||||||
@ -355,16 +361,32 @@ void setup()
|
|||||||
LittleFS.begin();
|
LittleFS.begin();
|
||||||
|
|
||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
|
|
||||||
|
#ifdef WIFI_AP
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
WiFi.softAP(WIFI_SSID, WIFI_PASS);
|
WiFi.softAP(WIFI_SSID, WIFI_PASS);
|
||||||
|
|
||||||
stationConnectedHandler = WiFi.onSoftAPModeStationConnected(&onStationConnected);
|
stationConnectedHandler = WiFi.onSoftAPModeStationConnected(&onStationConnected);
|
||||||
stationDisconnectedHandler = WiFi.onSoftAPModeStationDisconnected(&onStationDisconnected);
|
stationDisconnectedHandler = WiFi.onSoftAPModeStationDisconnected(&onStationDisconnected);
|
||||||
|
|
||||||
|
#else
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
wifiMulti.addAP(WIFI_SSID, WIFI_PASS);
|
||||||
|
|
||||||
|
Serial.println("Connecting Wifi...");
|
||||||
|
if (wifiMulti.run() == WL_CONNECTED)
|
||||||
|
{
|
||||||
|
Serial.println("");
|
||||||
|
Serial.println("WiFi connected");
|
||||||
|
Serial.println("IP address: ");
|
||||||
|
Serial.print(WiFi.localIP());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef CAPTIVE
|
#ifdef CAPTIVE
|
||||||
dnsServer.start(53, "*", WiFi.softAPIP());
|
dnsServer.start(53, "*", WiFi.softAPIP());
|
||||||
#endif
|
#endif
|
||||||
server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); //only when requested from AP
|
|
||||||
|
server.addHandler(new CaptiveRequestHandler());
|
||||||
server.begin();
|
server.begin();
|
||||||
|
|
||||||
FactionTicker.start();
|
FactionTicker.start();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user