Open rhubarbdog opened 1 year ago
If both micro:bits are transmitting on the same channel at the same time, then it's normal to get some collisions. I assume if you broadcast with only one micro:bit at a time there are not packet losses?
but surely not like ethernet. the radio should listen that the airwaves are quiet, acquire the airwave, transmit, releasing the airwave on completion
it's not just 2 microbit's communicating at the same time. I have this repo https://github.com/rhubarbdog/microbit-hands-up
i have 2 pupil.py
micobit's and one teacher.py
. i press the button on the pupil microbits a second appart.
When i send out the results from the teacher.py
microbit the happy face isn't always shown
Right, but in your examples you can have two micro:bits transmitting data at exactly the same time and on the same channel, so the radio signals from each micro:bit can interfere with the other, and that can cause some data loss.
There is a few things you can try to reduce packet loses, for example, you could request acknowledgements and retransmit if an ack has not been received. There is a Networking With The micro:bit online book that contains useful information on this area: https://microbit.nominetresearch.uk/networking-book-online-python/retransmissions/retransmissions/
but i still loose packets in my second example https://github.com/rhubarbdog/microbit-hands-up and there are no transmission problems
also in the initial example counter.py
counts message that are neither "yap." or "message." and receives none neither does radio.receive()
throw an exception that a corrupt packet has been detected on the airwaves
microbit-hands-up fails because the length of str(id) is 35 but the message received is only 29 long.
radio.config(length=40)
makes it work.
On the microbit's i have the string str(machine.unique_id())
must be less than 32 long because i have had both success and failure with 2 microbit's running pupil.py
and one running teacher.py
. with both successful runs where all pupils get a happy face in the correct order and other times only some get a happy face
Thanks for the additional info @rhubarbdog. Would you be able to provide a minimum example where not more than one micro:bit is transmitting at the same time and a receiver still loses packets?
transmitting with program ... on one microbit
from microbit import *
import radio
radio.config(data_rate = radio.RATE_2MBIT)
radio.on()
while True:
if button_a.is_pressed():
for _ in range(100):
radio.send('message')
while button_a.is_pressed():
pass
sleep(1)
and receiving on another microbit with program
from microbit import *
import radio
radio.config(length = 10, queue = 100, data_rate = radio.RATE_2MBIT)
radio.on()
count = 0
while True:
receive = radio.receive()
if receive is None:
sleep(1)
else:
count = count + 1
if button_a.is_pressed():
display.scroll(str(count))
before i added the radio.config
argument queue = 100
packets were being dropped at data_rate
1 MBit when i change it to 2 Mbit most packets sometimes all are being dropped
Should "length = 10" be included in both configs?
Using 3 microbits, 2 transmitting and one counting packets, not all packets are being recieved by the counter.
yap.py
19682 received 318 droppedmessage.py
1822 received 178 droppedcounter.py.txt message.py.txt yap.py.txt
this may be related to https://github.com/bbcmicrobit/micropython/issues/755