Skip to content

Commit cde6d01

Browse files
authored
Merge pull request #16 from mlupo/main
Added a 'wait' argument to control how long the radio waits to receive a message
2 parents 38de1b6 + 459ef05 commit cde6d01

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, timeout=1):
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(timeout=timeout)
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, timeout=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 timeout: The length of time (in seconds) the radio listens for a broadcast
171+
170172
:return: A tuple representation of the received message, or else None.
173+
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=timeout, 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)