Skip to content

Commit 60a48b2

Browse files
committed
Added a 'wait' argument to control how long the radio waits for a new message.
1 parent 797e1cc commit 60a48b2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

adafruit_ble_radio.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,19 @@ def send_bytes(self, message):
142142
time.sleep(AD_DURATION)
143143
self.ble.stop_advertising()
144144

145-
def receive(self):
145+
def receive(self, **args):
146146
"""
147147
Returns a message received on the channel on which the radio is
148148
listening.
149149
150150
:return: A string representation of the received message, or else None.
151151
"""
152-
msg = self.receive_full()
152+
msg = self.receive_full(**args)
153153
if msg:
154154
return msg[0].decode("utf-8").replace("\x00", "")
155155
return None
156156

157-
def receive_full(self):
157+
def receive_full(self, wait=1):
158158
"""
159159
Returns a tuple containing three values representing a message received
160160
on the channel on which the radio is listening. If no message was
@@ -167,11 +167,14 @@ def receive_full(self):
167167
* a microsecond timestamp: the value returned by time.monotonic() when
168168
the message was received.
169169
170+
:param float wait: The length of time the radio listens for a
171+
broadcast
172+
170173
:return: A tuple representation of the received message, or else None.
171174
"""
172175
try:
173176
for entry in self.ble.start_scan(
174-
_RadioAdvertisement, minimum_rssi=-255, timeout=1, extended=True
177+
_RadioAdvertisement, minimum_rssi=-255, timeout=wait, extended=True
175178
):
176179
# Extract channel and unique message ID bytes.
177180
chan, uid = struct.unpack("<BB", entry.msg[:2])

0 commit comments

Comments
 (0)