-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
228 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[app] | ||
title = BLE service | ||
version = 1.0 | ||
package.name = service | ||
package.domain = test.able | ||
source.dir = . | ||
source.include_exts = py,png,jpg,kv,atlas | ||
android.permissions = BLUETOOTH,BLUETOOTH_ADMIN,ACCESS_FINE_LOCATION,FOREGROUND_SERVICE | ||
requirements = kivy==2.0.0,plyer==2.0.0,python3,able_recipe | ||
services = Able:service.py:foreground | ||
|
||
[buildozer] | ||
warn_on_root = 1 | ||
# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output)) | ||
log_level = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Start advertising service.""" | ||
from able import BluetoothDispatcher, require_bluetooth_enabled | ||
from jnius import autoclass | ||
from kivy.app import App | ||
from kivy.lang import Builder | ||
|
||
|
||
kv = """ | ||
BoxLayout: | ||
Button: | ||
text: 'Start service' | ||
on_press: app.ble_dispatcher.start_service() | ||
Button: | ||
text: 'Stop service' | ||
on_press: app.ble_dispatcher.stop_service() | ||
""" | ||
|
||
|
||
class Dispatcher(BluetoothDispatcher): | ||
|
||
@property | ||
def service(self): | ||
return autoclass("test.able.service.ServiceAble") | ||
|
||
@property | ||
def activity(self): | ||
return autoclass("org.kivy.android.PythonActivity").mActivity | ||
|
||
# Need to turn on the adapter, before service is started | ||
@require_bluetooth_enabled | ||
def start_service(self): | ||
self.service.start( | ||
self.activity, | ||
# Pass UUID to advertise | ||
"bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb" | ||
) | ||
App.get_running_app().stop() # Can close the app, service will continue running | ||
|
||
def stop_service(self): | ||
self.service.stop(self.activity) | ||
|
||
|
||
class ServiceApp(App): | ||
|
||
def build(self): | ||
self.ble_dispatcher = Dispatcher() | ||
return Builder.load_string(kv) | ||
|
||
|
||
if __name__ == "__main__": | ||
ServiceApp().run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Service to advertise data, while not stopped.""" | ||
import time | ||
from os import environ | ||
|
||
from able import BluetoothDispatcher | ||
from able.advertising import ( | ||
Advertiser, | ||
AdvertiseData, | ||
ServiceUUID, | ||
) | ||
|
||
|
||
def main(): | ||
uuid = environ.get( | ||
"PYTHON_SERVICE_ARGUMENT", | ||
"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" | ||
) | ||
advertiser = Advertiser( | ||
ble=BluetoothDispatcher(), | ||
data=AdvertiseData(ServiceUUID(uuid)), | ||
) | ||
advertiser.start() | ||
while True: | ||
time.sleep(0xDEAD) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[app] | ||
title = BLE service | ||
version = 1.0 | ||
package.name = service | ||
package.domain = test.able | ||
source.dir = . | ||
source.include_exts = py,png,jpg,kv,atlas | ||
android.permissions = BLUETOOTH,BLUETOOTH_ADMIN,ACCESS_FINE_LOCATION,FOREGROUND_SERVICE | ||
requirements = kivy==2.0.0,plyer==2.0.0,python3,http://herethere.me:8080/able.zip | ||
services = Able:service.py:foreground | ||
|
||
[buildozer] | ||
warn_on_root = 1 | ||
# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output)) | ||
log_level = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Start advertising service.""" | ||
from able import BluetoothDispatcher, require_bluetooth_enabled | ||
from jnius import autoclass | ||
from kivy.app import App | ||
from kivy.lang import Builder | ||
|
||
|
||
kv = """ | ||
BoxLayout: | ||
Button: | ||
text: 'Start service' | ||
on_press: app.ble_dispatcher.start_service() | ||
Button: | ||
text: 'Stop service' | ||
on_press: app.ble_dispatcher.stop_service() | ||
""" | ||
|
||
|
||
class Dispatcher(BluetoothDispatcher): | ||
|
||
@property | ||
def service(self): | ||
return autoclass("test.able.service.ServiceAble") | ||
|
||
@property | ||
def activity(self): | ||
return autoclass("org.kivy.android.PythonActivity").mActivity | ||
|
||
# Need to turn on the adapter, before service is started | ||
@require_bluetooth_enabled | ||
def start_service(self): | ||
self.service.start( | ||
self.activity, | ||
# Pass UUID to advertise | ||
"bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb" | ||
) | ||
App.get_running_app().stop() # Can close the app, service will continue running | ||
|
||
def stop_service(self): | ||
self.service.stop(self.activity) | ||
|
||
|
||
class ServiceApp(App): | ||
|
||
def build(self): | ||
self.ble_dispatcher = Dispatcher() | ||
return Builder.load_string(kv) | ||
|
||
|
||
if __name__ == "__main__": | ||
ServiceApp().run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Service to advertise data, while not stopped.""" | ||
import time | ||
from os import environ | ||
|
||
from able import BluetoothDispatcher | ||
from able.advertising import ( | ||
Advertiser, | ||
AdvertiseData, | ||
ServiceUUID, | ||
) | ||
|
||
|
||
def main(): | ||
uuid = environ.get( | ||
"PYTHON_SERVICE_ARGUMENT", | ||
"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" | ||
) | ||
advertiser = Advertiser( | ||
ble=BluetoothDispatcher(), | ||
data=AdvertiseData(ServiceUUID(uuid)), | ||
) | ||
advertiser.start() | ||
while True: | ||
time.sleep(0xDEAD) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters