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

Prevent Rx/Tx clash by preventing receive_packet from reading while s… #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jsonpoindexter
Copy link

@jsonpoindexter jsonpoindexter commented Jul 22, 2020

…elf._lock is true

While using the uPyLoRaWAN with an asynchronous web server, MicroWebSrv2, I noticed that my Tx data was being corrupted which I believe is due to received_packet resetting the FiFo address (?). To prevent received_packet from executing during a Tx I added a check to see if a lock has been set.

Example web server / lora code

@WebRoute(POST, '/message')
def RequestHandler(microWebSrv2, request):
    # Send message over Lora
    lora.println('1234567890abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz')
    request.Response.ReturnOk()

if __name__ == '__main__':
    # Instanciates the MicroWebSrv2 class, 
    mws2 = MicroWebSrv2()
    # For embedded MicroPython, use a very light configuration,
    mws2.SetEmbeddedConfig()
    # Starts the server as easily as possible in managed mode,
    mws2.StartManaged()
    # Main program loop until keyboard interrupt,
    try:
        while mws2.IsRunning:
            if lora.received_packet():
                lora.blink_led()
                payload = lora.read_payload()
                print('lora recieved: ', payload)
                ...
                
    except KeyboardInterrupt:
        pass

    # End,
    mws2.Stop()

Full code: https://github.com/jsonpoindexter/ulora-ttgo-chat/blob/98c125402dc09cda549f147c66f7c66e4dac1646/main.py

When no lock is implemented in received_packet() the payload would be corrupted when receiving it on another device:

lora recieved: b'uvwxyz1234567890abcdefghijklmnopqrstuvwxyz\xaf\x19\x04^\x89\x07\xbc\xb2vC\x95\x8a\x1f\xc5\xba\xb9\xd9\x15\t@\x90\xb9\x98\xeesa-\xb0n\xdd'

When the transmitting device had if lora.received_packet(): removed/commented out the payload would be received intact.

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

Successfully merging this pull request may close these issues.

None yet

1 participant