-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathflipperLink.py
98 lines (84 loc) · 3.08 KB
/
flipperLink.py
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
import logging
import os
import sys
import time
import types
import subprocess
import signal
import subprocess
from threading import Lock
import bluetooth
import pwnagotchi.plugins as plugins
import pwnagotchi.ui.fonts as fonts
from pwnagotchi.ui.components import LabeledValue
from pwnagotchi.ui.view import BLACK
from pwnagotchi.utils import StatusFile
class FlipperLink(plugins.Plugin):
__GitHub__ = ""
__author__ = "(edited by: itsdarklikehell [email protected]), Allordacia"
__version__ = "1.0.0"
__license__ = "MIT"
__description__ = "A plugin that will add functionality for pwnagotchi to connect to the Flipper Zero."
__name__ = "FlipperLink"
__help__ = "A plugin that will add functionality for pwnagotchi to connect to the Flipper Zero."
__dependencies__ = {"pip": ["scapy"]}
__defaults__ = {
"enabled": False,
}
def __init__(self):
self.running = False
def on_loaded(self):
self.flipper_connected = False
self.flipper_connected = self.check_flipper()
logging.info(self.flipper_connected)
logging.info(f"[{self.__class__.__name__}] plugin loaded")
def on_ready(self, agent):
logging.info(f"[{self.__class__.__name__}] plugin loaded")
def on_ui_setup(self, ui):
# Add elements to the UI
ui.add_element(
"flipperlink",
LabeledValue(
color=BLACK,
label="Flipper: ",
value=self.flipper_connected,
position=(2, ui.height() - 30),
label_font=fonts.Bold,
text_font=fonts.Medium,
),
)
def on_unload(self, ui):
with ui._lock:
try:
ui.remove_element("flipperlink")
logging.info(f"[{self.__class__.__name__}] plugin unloaded")
except Exception as e:
logging.error(f"[{self.__class__.__name__}] unload: %s" % e)
def on_ui_update(self, ui):
# Update the UI
if self.flipper_connected == True:
ui.set("flipperlink", value="Connected")
else:
self.flipper_connected = self.check_flipper()
if self.flipper_connected == True:
ui.set("flipperlink", value="Connected")
else:
ui.set("flipperlink", value="Not Connected")
def check_flipper(self):
flipper_connected = False
try:
nearby_devices = bluetooth.discover_devices()
for bdaddr in nearby_devices:
if bdaddr == self.options["mac"]:
flipper_connected = True
logging.info(
"Flipper device found with MAC address: %s", bdaddr)
break
except bluetooth.BluetoothError as e:
logging.error(
"Bluetooth error while searching for Flipper device: %s", e)
except Exception as e:
logging.error(
"Unexpected error while searching for Flipper device: %s", e)
return flipper_connected
return flipper_connected