Lopy4 issue receiving in a tight loop



  • I have the following bit of code.

    from network import LoRa
    import socket
    import time
    import pycom
    
    # Please pick the region that matches where you are using the device
    pycom.heartbeat(False)
    lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868, bandwidth=LoRa.BW_250KHZ,coding_rate=LoRa.CODING_4_5,sf=7, tx_power=14,power_mode=LoRa.ALWAYS_ON,preamble=8,
                tx_iq=False, rx_iq=False) # >17000 bps
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setblocking(False)
    i = 0
    while True:
        data=s.recv(512)
        if len(data)>0:
            print('count {0} value {1} length {2}'.format(i,data,len(data)))
            i = i+1
            pycom.rgbled(0xFFD058)
            time.sleep_ms(2)
            pycom.rgbled(0x000000)
            time.sleep_ms(2)
        time.sleep_ms(1)
    

    I receive data well, except when I comment out the 1ms delay in the while loop. In which case I receive no data at all. The transmissions are happening slowly. About every 1 second.



  • Right, we do not have specific documentation on that (yet) I believe, as in my experience its a fundamental feature of microcontrollers in general. Could you recommend a place where you would expect this information?

    Gijs



  • @Gijs What I meant was any documentation on the watchdog timer versus tight loops.



  • Its all in here: https://docs.pycom.io/firmwareapi/micropython/utime/
    Note that the 'u' in front of utime can be left when importing, its the same module

    Gijs



  • @Gijs Thank you for your response.
    Any document I can read more about this?



  • This post is deleted!


  • Because you have an infinite loop, removing the delay will leave no time for the watchdog timer to trigger, making the device reset internally. You can perhaps use time.sleep_us(...) instead?

    Gijs


Log in to reply
 

Pycom on Twitter