-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbasiclight.py
More file actions
125 lines (107 loc) · 3.27 KB
/
basiclight.py
File metadata and controls
125 lines (107 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import logging
import json
import os
import pwnagotchi.plugins as plugins
import RPi.GPIO as GPIO
import time
LEDs = {"green": 17, "yellow": 22, "red": 27}
def Blink(LED, times=1):
count = 0
led_active = False
led_state = GPIO.LOW
if GPIO.input(LED) == GPIO.HIGH:
led_state = GPIO.HIGH
while count < times:
if led_active:
GPIO.output(LED, GPIO.LOW)
led_active = False
else:
count += 1
GPIO.output(LED, GPIO.HIGH)
led_active = True
time.sleep(0.5)
GPIO.output(LED, led_state)
class BasicLight(plugins.Plugin):
__GitHub__ = ""
__author__ = "(edited by: itsdarklikehell bauke.molenaar@gmail.com), github.com/shir0tetsuo"
__version__ = "1.0.0"
__license__ = "GPL3"
__description__ = "GPIO traffic-light signals."
__name__ = "BasicLight"
__help__ = "GPIO traffic-light signals."
__dependencies__ = {
"apt": ["none"],
"pip": ["scapy"],
}
__defaults__ = {
"enabled": False,
}
def __init__(self):
self.running = False
logging.debug(f"[{self.__class__.__name__}] plugin init")
self.title = ""
# Plugin load, switch Yellow high
def on_loaded(self):
global LEDs
GPIO.setmode(GPIO.BCM)
for LED in LEDs:
Lnum = LEDs[LED]
GPIO.setup(Lnum, GPIO.OUT)
GPIO.output(LEDs["yellow"], GPIO.HIGH)
GPIO.output(LEDs["green"], GPIO.LOW)
logging.info(f"[{self.__class__.__name__}] plugin loaded")
# On ready, switch Yellow low
def on_ready(self, agent):
global LEDs
logging.info(f"[{self.__class__.__name__}] plugin ready")
GPIO.output(LEDs["yellow"], GPIO.LOW)
GPIO.output(LEDs["green"], GPIO.HIGH)
self.running = True
############
# -X-
def on_ai_training_start(self, agent, epochs):
global LEDs
GPIO.output(LEDs["green"], GPIO.LOW)
# X--
def on_ai_training_end(self, agent):
global LEDs
GPIO.output(LEDs["green"], GPIO.HIGH)
# XX-
def on_sleep(self, agent, t):
global LEDs
count_sleep = t
flip = True
while count_sleep > 0:
if flip:
GPIO.output(LEDs["yellow"], GPIO.HIGH)
flip = False
else:
GPIO.output(LEDs["yellow"], GPIO.LOW)
flip = True
time.sleep(1)
count_sleep -= 1
GPIO.output(LEDs["yellow"], GPIO.LOW)
# X-X
def on_wait(self, agent, t):
global LEDs
Blink(LEDs["red"], 1)
# -X- (B)
def on_wifi_update(self, agent, access_points):
global LEDs
Blink(LEDs["yellow"], 1)
# X-- (B)
def on_handshake(self, agent, filename, access_point, client_station):
global LEDs
Blink(LEDs["yellow"], 3)
# --X (B)
def on_deauthentication(self, agent, access_point, client_station):
global LEDs
Blink(LEDs["red"], 3)
def on_unload(self, ui):
with ui._lock:
logging.info(f"[{self.__class__.__name__}] plugin unloaded")
def on_webhook(self, path, request):
logging.info(f"[{self.__class__.__name__}] webhook pressed")
global LEDs
Blink(LEDs["red"], 3)
pass