LoPy to LoPy communication issue with button



  • Hi,

    I am new to the Pycom platform and I am trying to get a LoPy to communicate over LoRa with another LoPy when a button is pressed.

    I have tried the LoPy to LoPy example code and have this working fine: https://docs.pycom.io/tutorials/networks/lora/module-module/

    I now have a breadboard set up with a momentary pushbutton connected to digital pin 9 through the Expansion 3 board.

    The issue I am having is that when I push the button, I believe the LoPy is sending a LoRa signal as I am printing to the console after the packet is sent but the receiving LoPy is not receiving the signal.

    In its simplest form, the code below is how I am trying to send and receive the LoRa signal:

    from network import LoRa
    from machine import Pin
    import pycom
    import socket
    import time
    
    lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868)
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setblocking(False)
    pycom.heartbeat(False)
    
    activateButton = Pin('P9', mode=Pin.IN)
    
    print('Starting to send....')
    
    while True:
    
        if (activateButton() == 1):
            s.send('Hi')
            print('Signal sent')
    
        time.sleep(1)
    
    from network import LoRa
    import pycom
    import socket
    import time
    
    lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868)
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setblocking(False)
    pycom.heartbeat(False)
    
    print('Starting')
    while True:
        if s.recv(64) == b'Hi':
            print('Signal received')
    
        time.sleep(1)
    

    I have tried various other ways of coding the same thing. I have also tried to just modify the LoPy to LoPy example, which works, but instead of just sending a signal automatically I send it when I push the button. Once again this does not have the desired outcome on the receiving side.

    I have been at this for days now and have searched through community postings but cannot find anything that can point me in the right direction.

    From what I can gather, what I am doing is very simple and should work.

    I am also having an issue where by after sending 8-14 LoRa packets I get an EAGAIN error.

    Please let me know where I am going wrong.

    Thank you



  • Hi Guys,

    I seemed to have solved this by moving the time.sleep(1) of code into the if statement.

    This also solved the EAGAIN error that I was receiving.

    Thank you for the time you all took to reply.



  • I am also having an issue where by after sending 8-14 LoRa packets I get an EAGAIN error.

    I would really like to learn more about this error. I custom compiled a firmware for someone earlier this week to determine the cause of this as I cannot reproduce it, would you like to send it to you as well (here). You can use the firmware updater tool to flash from local file, it will provide some additional debug information in that area.

    Other than that, I have no issues running the example from the documentation (as you mention as well) https://docs.pycom.io/tutorials/networks/lora/module-module/ and am quite puzzled why yours does not work, as the code does work on my device. Please try the suggestion by @jcaron and maybe add some indication, like changing the color on the RGB LED when a LoRa packet is sent



  • @Alex-Ray One problem I always have with the simple Raw mode LoRa sensing from one device to the other using LoPy4 devices, that it will not work unless I push hard reset at the button on both devices after power on, and then run the code.
    Note that lora.reset() still causes a core dump, and besides that is an No-operation on LoPy4.



  • @Alex-Ray try logging the return value of the s.recv(64) call, to see if anything has been received, and if so, what.

    You may also want to explicitly set frequency, bandwidth, spreading factor, etc. I suppose the defaults should be the same in both sides, but it’s always better to know what they are.


Log in to reply
 

Pycom on Twitter