32
32
import struct
33
33
import bleio
34
34
35
- from .advertising import AdvertisingData
35
+ from .advertising import Advertisement
36
36
37
37
class Beacon :
38
38
"""Base class for Beacon advertisers."""
39
- def __init__ (self , advertising_data , interval = 1.0 ):
40
- """Set up a beacon with the given AdvertisingData .
39
+ def __init__ (self , advertisement , interval = 1.0 ):
40
+ """Set up a beacon with the given Advertisement .
41
41
42
- :param AdvertisingData advertising_data : The advertising packet
42
+ :param Advertisement advertisement : The advertising packet
43
43
:param float interval: Advertising interval in seconds
44
44
"""
45
45
self .broadcaster = bleio .Broadcaster (interval )
46
- self .advertising_data = advertising_data
46
+ self .advertisement = advertisement
47
47
48
48
def start (self ):
49
49
"""Turn on beacon."""
50
- self .broadcaster .start_advertising (self .advertising_data .data )
50
+ self .broadcaster .start_advertising (self .advertisement .data )
51
51
52
52
def stop (self ):
53
53
"""Turn off beacon."""
@@ -81,8 +81,8 @@ def __init__(self, company_id, uuid, major, minor, rssi, interval=1.0):
81
81
b.start()
82
82
"""
83
83
84
- adv_data = AdvertisingData ()
85
- adv_data .add_mfr_specific_data (
84
+ adv = Advertisement ()
85
+ adv .add_mfr_specific_data (
86
86
company_id ,
87
87
b'' .join ((
88
88
# 0x02 means a beacon. 0x15 (=21) is length (16 + 2 + 2 + 1)
@@ -91,8 +91,8 @@ def __init__(self, company_id, uuid, major, minor, rssi, interval=1.0):
91
91
# iBeacon and similar expect big-endian UUIDS. Usually they are little-endian.
92
92
bytes (reversed (uuid .uuid128 )),
93
93
# major and minor are big-endian.
94
- struct .pack (">HHB " , major , minor , rssi ))))
95
- super ().__init__ (adv_data , interval = interval )
94
+ struct .pack (">HHb " , major , minor , rssi ))))
95
+ super ().__init__ (adv , interval = interval )
96
96
97
97
98
98
class EddystoneURLBeacon (Beacon ):
@@ -134,8 +134,8 @@ def __init__(self, url, tx_power=0, interval=1.0):
134
134
:param float interval: Advertising interval in seconds
135
135
"""
136
136
137
- adv_data = AdvertisingData ()
138
- adv_data .add_field (AdvertisingData .ALL_16_BIT_SERVICE_UUIDS , self ._EDDYSTONE_ID )
137
+ adv = Advertisement ()
138
+ adv .add_field (Advertisement .ALL_16_BIT_SERVICE_UUIDS , self ._EDDYSTONE_ID )
139
139
short_url = None
140
140
for idx , prefix in enumerate (self ._URL_SCHEMES ):
141
141
if url .startswith (prefix ):
@@ -148,9 +148,9 @@ def __init__(self, url, tx_power=0, interval=1.0):
148
148
short_url = short_url .replace (subst + '/' , chr (code ))
149
149
for code , subst in enumerate (self ._SUBSTITUTIONS , 7 ):
150
150
short_url = short_url .replace (subst , chr (code ))
151
- adv_data .add_field (AdvertisingData .SERVICE_DATA_16_BIT_UUID ,
152
- b'' .join ((self ._EDDYSTONE_ID ,
153
- b'\x10 ' ,
154
- struct .pack ("<BB " , tx_power , url_scheme_num ),
155
- bytes (short_url , 'ascii' ))))
156
- super ().__init__ (adv_data , interval )
151
+ adv .add_field (Advertisement .SERVICE_DATA_16_BIT_UUID ,
152
+ b'' .join ((self ._EDDYSTONE_ID ,
153
+ b'\x10 ' ,
154
+ struct .pack ("<bB " , tx_power , url_scheme_num ),
155
+ bytes (short_url , 'ascii' ))))
156
+ super ().__init__ (adv , interval )
0 commit comments