10000 LoPy L01 LoRaWAN blocking socket.send() hangs permanently · Issue #105 · pycom/pycom-micropython-sigfox · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

LoPy L01 LoRaWAN blocking socket.send() hangs permanently #105

Open
jmarcelino opened this issue Dec 7, 2017 · 1 comment
Open

LoPy L01 LoRaWAN blocking socket.send() hangs permanently #105

jmarcelino opened this issue Dec 7, 2017 · 1 comment
Labels
bug Something isn't working LoRa Issues related to LoRa

Comments

@jmarcelino
Copy link

From https://forum.pycom.io/topic/2272/lopy-l01-lorawan-blocking-socket-send-hangs-permanently

Using firmware v1.10.2.b1 on LoPy L01 OEM module

Using the code shown below periodically the socket.send() function call hangs forever. The only way to recover is to enable the watchdog timer.

Code:

import pycom
import network
from network import LoRa
import socket
import machine
import time
import binascii

reset_cause = machine.reset_cause()

def select_subband(lora, subband):
    if (type(subband) is int):
        if ((subband<1) or (subband>8)):
            raise ValueError("subband out of range (1-8)")
    else:
        raise TypeError("subband must be 1-8")

    for channel in range(0, 72):
        lora.remove_channel(channel)

    channel_idx = 0
    for channel in range((subband-1)*8, ((subband-1)*8)+8):
        lora.add_channel(channel_idx, frequency=902300000+channel*200000, dr_min=1, dr_max=3)
        channel_idx += 1

# Initialize LoRa in LORAWAN mode.
print("LoRa init")
lora = LoRa(mode=LoRa.LORAWAN, device_class=LoRa.CLASS_A)

if reset_cause == machine.DEEPSLEEP_RESET:
    lora.nvram_restore()

if reset_cause == machine.DEEPSLEEP_RESET and lora.has_joined():
    print('Skipping LoRaWAN join, previously joined')
else:
    select_subband(lora, 1)

    # create an OTAA authentication parameters
    app_eui = binascii.unhexlify('00 00 00 00 00 00 00 01'.replace(' ',''))
    app_key = binascii.unhexlify('00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01'.replace(' ',''))

    # join a network using OTAA (Over the Air Activation)
    lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)

    print('Joining LoRa network')

    # wait until the module has joined the network
    while not lora.has_joined():
        time.sleep(2.5)

    print('Joined!!!')

# create a LoRa socket
print("LoRa socket setup")
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
s.setsockopt(socket.SOL_LORA, socket.SO_DR, 1)
s.setblocking(False)

print("Init complete, running main loop")

# simulate time delay to detect sensors, etc
time.sleep(10)

while True:
    was_lora_tx_error = False
    try:
        s.setblocking(True)
        print('Trying to send...')
        s.send(bytes(21))
        print('info sent')
    except Exception as e:
        was_lora_tx_error = True
        if e.args[0] == 11:
            print('cannot send just yet, waiting...')
            time.sleep_ms(30)
        else:
            print('error: ')
            print(e.args[0])
            raise    # raise the exception again

    s.setblocking(False)

    if not was_lora_tx_error:
        print('Going to deep sleep')
        time.sleep_ms(10)
        lora.nvram_save()
        lora.power_mode(LoRa.SLEEP)
        machine.deepsleep(10000)
@jmarcelino jmarcelino self-assigned this Dec 7, 2017
@atoy40
Copy link
atoy40 commented Dec 15, 2017

Exact same problem with exact same firmware, and a very simple test program (no deepsleep or other "features", just sending unconfirmed lorawan packet every minute). It hangs after around 100 to 400 packets in the send() function.

@danspndl danspndl added LoRa Issues related to LoRa bug Something isn't working labels Sep 3, 2018
peter-pycom pushed a commit that referenced this issue Feb 28, 2020
sleep in main thread to yield
X-Ryl669 pushed a commit to X-Ryl669/pycom-micropython-sigfox that referenced this issue May 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working LoRa Issues related to LoRa
Projects
None yet
Development

No branches or pull requests

3 participants
0