Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Advertise Service #2

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions controllers/bluetooth_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ def __init__(self):
self.server_socket.bind(('',bluetooth_port))
print('Waiting for new connection as <stadion> ...')
self.server_socket.listen(bluetooth_port)
uuid = "aad0d230-4288-421d-a531-58a9ef4e48ac"
bluetooth.advertise_service(self.server_socket,
"SpeedReportService",
service_id=uuid,
service_classes=[uuid, bluetooth.SERIAL_PORT_CLASS],
profiles=[bluetooth.SERIAL_PORT_PROFILE])
self.client_socket,self.device_address = self.server_socket.accept()
self.device_name = bluetooth.lookup_name(self.device_address[0], timeout=10)
print('Connection stablished with ' + self.device_name)
Expand Down
10 changes: 6 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from controllers.bluetooth_controller import BluetoothController
from controllers.lcd_display_controller import LCDDisplayController

from time import sleep

def main():
display_controller = LCDDisplayController()
Expand All @@ -13,8 +13,10 @@ def main():

while bluetooth_controller.isConnected():

response_msg = '2.0\n'
bluetooth_controller.send(response_msg)

received_data = bluetooth_controller.read()
response_msg = 'Received -> ' + received_data
display_controller.displayData(received_data)

if received_data == 'disconnect':
Expand All @@ -24,8 +26,8 @@ def main():

if received_data == 'exit':
exit()
bluetooth_controller.send(response_msg)

sleep(1)

display_controller.displayPowerOffMsg()
except Exception as e:
Expand Down