def start_beacon(self): """ Start beacon advertising """ if not self.dongle.powered: self.dongle.powered = True ad_manager = advertisement.AdvertisingManager(self.dongle.path) ad_manager.register_advertisement(self.broadcaster, {}) try: tools.start_mainloop() except KeyboardInterrupt: tools.stop_mainloop() ad_manager.unregister_advertisement(self.broadcaster) finally: pass
lights.set_pixel(1, 1, 255, 0, 0) sleep(0.1) lights.show() lights.clear() sleep(0.1) print('set up characteristics') ubit_btn_b = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'E95DDA90-251D-470A-A062-FA1922DFA9A8')[0]) ubit_btn_b.add_characteristic_cb(on_button_b) ubit_btn_b.start_notify() ubit_btn_a = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'E95DDA91-251D-470A-A062-FA1922DFA9A8')[0]) ubit_btn_a.add_characteristic_cb(on_button_a) ubit_btn_a.start_notify() ubit_speed = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'E95DFB24-251D-470A-A062-FA1922DFA9A8')[0]) ubit_speed.write_value((160).to_bytes(2, byteorder='little')) ubit_accel = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'E95DCA4B-251D-470A-A062-FA1922DFA9A8')[0]) ubit_accel.add_characteristic_cb(on_accel_change) ubit_accel.start_notify() tools.start_mainloop()
def start_bt(self): # self.light.StartNotify() tools.start_mainloop()
to load a web page from it actually hosts the web page on the device and services it up from the BLE characteristic </p> </body> </html>""" html_ord = [] for char in html_string: html_ord.append(ord(char)) app = localGATT.Application() srv = localGATT.Service(1, FAT_SERVICE, True) fat_html = localGATT.Characteristic(1, HTML_CHRC, srv, html_ord, False, ["read"]) fat_html.service = srv.path app.add_managed_object(srv) app.add_managed_object(fat_html) srv_mng = GATT.GattManager("/org/bluez/hci0") srv_mng.register_application(app, {}) if __name__ == "__main__": ad_manager, advertiser = advertise_beacon() build_fat_service() try: tools.start_mainloop() except KeyboardInterrupt: tools.stop_mainloop() ad_manager.unregister_advertisement(advertiser) finally: pass
def start_bt(self): tools.start_mainloop()