Skip to content

Commit d4e3f9c

Browse files
committed
Dynamic ledPin switching
1 parent 6a67919 commit d4e3f9c

File tree

7 files changed

+30
-11
lines changed

7 files changed

+30
-11
lines changed

esp8266_deauther/Attack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,11 @@ void Attack::refreshLed() {
461461
}
462462
if (numberRunning >= 1 && settings.useLed) {
463463
if (debug) Serial.println("Attack LED : ON");
464-
digitalWrite(settings.ledPin, LOW);
464+
digitalWrite(settings.ledPin, !settings.pinStateOff);
465465
}
466466
else if (numberRunning == 0 || !settings.useLed) {
467467
if (debug) Serial.println("Attack LED : OFF");
468-
digitalWrite(settings.ledPin, HIGH);
468+
digitalWrite(settings.ledPin, settings.pinStateOff);
469469
}
470470
}
471471

esp8266_deauther/Attack.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extern "C" {
1818

1919
#define attacksNum 3
2020
#define macListLen 64
21+
#define PIN_STATE_OFF false
22+
#define PIN_STATE_ON true
2123

2224
extern void PrintHex8(uint8_t *data, uint8_t length);
2325
extern void getRandomVendorMac(uint8_t *buf);

esp8266_deauther/Settings.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ void Settings::syncMacInterface(){
2626
}
2727
}
2828

29+
void Settings::setLedPin(int newLedPin){
30+
prevLedPin = ledPin;
31+
if(newLedPin > 0 && newLedPin != prevLedPin){
32+
ledPin = newLedPin;
33+
pinMode(ledPin, OUTPUT);
34+
if(!prevLedPin == 0){
35+
digitalWrite(ledPin, digitalRead(prevLedPin));
36+
digitalWrite(prevLedPin, pinStateOff);
37+
pinMode(prevLedPin, INPUT);
38+
}else{
39+
digitalWrite(ledPin, pinStateOff);
40+
}
41+
}
42+
}
43+
2944
void Settings::load() {
3045

3146
if (EEPROM.read(checkNumAdr) != checkNum) {
@@ -72,7 +87,7 @@ void Settings::load() {
7287
multiAttacks = (bool)EEPROM.read(multiAttacksAdr);
7388
macInterval = eepromReadInt(macIntervalAdr);
7489
beaconInterval = (bool)EEPROM.read(beaconIntervalAdr);
75-
ledPin = (int)EEPROM.read(ledPinAdr);
90+
setLedPin((int)EEPROM.read(ledPinAdr));
7691
isSettingsLoaded = 1;
7792
}
7893

esp8266_deauther/Settings.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ class Settings
5656
void save();
5757
void send();
5858
void info();
59-
void syncMacInterface();
6059

6160
int ssidLen;
6261
String ssid = "";
@@ -76,11 +75,15 @@ class Settings
7675
bool multiAttacks;
7776
int macInterval;
7877
bool beaconInterval;
79-
int ledPin;
78+
int ledPin = 0;
79+
int prevLedPin = 0;
8080
Mac defaultMacAP;
8181
Mac macAP;
8282
bool isMacAPRand;
8383
bool isSettingsLoaded = 0;
84+
void syncMacInterface();
85+
void setLedPin(int newLedPin);
86+
bool pinStateOff = true; // When attack is off, pin state is HIGH
8487

8588
private:
8689
size_t getSize();

esp8266_deauther/data.h

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

esp8266_deauther/esp8266_deauther.ino

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ void saveSettings() {
445445
else settings.multiAttacks = true;
446446
}
447447

448-
if (server.hasArg("ledPin")) settings.ledPin = server.arg("ledPin").toInt();
448+
if (server.hasArg("ledPin")) settings.setLedPin(server.arg("ledPin").toInt());
449449
if(server.hasArg("macInterval")) settings.macInterval = server.arg("macInterval").toInt();
450450

451451
settings.save();
@@ -479,6 +479,8 @@ void setup() {
479479
nameList.load();
480480
ssidList.load();
481481

482+
attack.refreshLed();
483+
482484
delay(500); // Prevent bssid leak
483485

484486
startWifi();
@@ -568,9 +570,6 @@ void setup() {
568570
if(digitalRead(resetPin) == LOW) settings.reset();
569571
#endif
570572

571-
pinMode(settings.ledPin, OUTPUT);
572-
digitalWrite(settings.ledPin, HIGH);
573-
574573
if(debug){
575574
Serial.println("\nStarting...\n");
576575
#ifndef USE_DISPLAY

web_server/html/settings.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ <h2>Attack</h2>
137137
</div>
138138
<div class="row">
139139
<div class="col-6">
140-
<label for="ledPin">LED Pin (restart needed)</label>
140+
<label for="ledPin">LED Pin</label>
141141
</div>
142142
<div class="col-6">
143143
<input type="number" id="ledPin" min="0" max="18">

0 commit comments

Comments
 (0)