Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

radio packets are being dropped #144

Open
rhubarbdog opened this issue Dec 20, 2022 · 11 comments
Open

radio packets are being dropped #144

rhubarbdog opened this issue Dec 20, 2022 · 11 comments

Comments

@rhubarbdog
Copy link

rhubarbdog commented Dec 20, 2022

Using 3 microbits, 2 transmitting and one counting packets, not all packets are being recieved by the counter.

yap.py 19682 received 318 dropped
message.py 1822 received 178 dropped

counter.py.txt
message.py.txt
yap.py.txt

this may be related to bbcmicrobit/micropython#755

@microbit-carlos
Copy link
Contributor

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?

@rhubarbdog
Copy link
Author

rhubarbdog commented Dec 20, 2022

but surely not like ethernet. the radio should listen that the airwaves are quiet, acquire the airwave, transmit, releasing the airwave on completion

@rhubarbdog
Copy link
Author

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

@microbit-carlos
Copy link
Contributor

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/

@rhubarbdog
Copy link
Author

but i still loose packets in my second example https://github.com/rhubarbdog/microbit-hands-up and there are no transmission problems

@rhubarbdog
Copy link
Author

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

@martinwork
Copy link
Collaborator

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.

@rhubarbdog
Copy link
Author

rhubarbdog commented Dec 20, 2022

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

@microbit-carlos
Copy link
Contributor

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?

@rhubarbdog
Copy link
Author

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

@martinwork
Copy link
Collaborator

Should "length = 10" be included in both configs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants