Help with radio feature
-
- Posts: 1
- Joined: Tue Sep 01, 2020 3:00 pm
Help with radio feature
Lets say i wanted to send something over to my friends micro:bit but i dont know his radio group, how would i make a system that tries radio group 1-255 until it send to the right one?
Re: Help with radio feature
The simplest way to do this is to just try each one individually. If you want to find out which is the correct one then you'll need to have the other one reply. Here's a simple example:
The problem is that you might not also know which channel and address the other device is using?
Code: Select all
from microbit import *
import radio
CHANNEL = 27
def scan_groups():
for group in range(256):
# Send a ping on the current group
radio.config(channel=CHANNEL, group=group)
radio.send('ping')
# Wait 100ms for a reply
t = running_time()
while running_time() - t < 100:
reply = radio.receive()
if reply == 'pong':
print('Reply on group', group)
return group
return -1