Lopy4 sending confirmed messages on 915 problem



  • Hi

    I have multiple lopys sending confirmed messages on 915 however after maybe 2 successful confirmed messages it changes the message on the server to be unconfirmed and the device print out these errors

    sending !!!
    OS error: [Errno 11] EAGAIN
    Attempting to send !!!!!
    sending !!!
    OS error: [Errno 11] EAGAIN
    and this is what i am seeing on my lora server
    c2f2977fafd03938ba1466f1aaff22c30a1bf47d.png

    Here is the code i am using what i am trying to do is to get it to send a confirmed message every 1 minute

    from network import LoRa, WLAN
    import socket
    import ubinascii
    import struct
    import pycom
    import time
    import machine
    from machine import Pin
    from pysense import Pysense
    from LIS2HH12 import LIS2HH12
    from SI7006A20 import SI7006A20
    from LTR329ALS01 import LTR329ALS01
    from MPL3115A2 import MPL3115A2, ALTITUDE, PRESSURE
    
    ### initialise the sensors in the pysense board ###
    py = Pysense()
    # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals
    mp = MPL3115A2(py, mode=ALTITUDE)
    si = SI7006A20(py)
    lt = LTR329ALS01(py)
    li = LIS2HH12(py)
    
    ### Initialise LoRa in LORAWAN mode, region, class etc.. ###
    lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.US915, adr=True,
                tx_retries=4, power_mode=LoRa.ALWAYS_ON, device_class=LoRa.CLASS_C)
                
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)  # create a LoRa socket
    s.setsockopt(socket.SOL_LORA, socket.SO_DR, 3)  # set the LoRaWAN data rate
    s.setsockopt(socket.SOL_LORA, socket.SO_CONFIRMED,True)  # set LoRaWAN to confirmed
    s.bind(1)
    
    def lora_cb(lora):
        events = lora.events()
        if events & LoRa.RX_PACKET_EVENT:
            data = s.recv(64)
            data = data.decode('utf-8')
            print('Lora packet received')
            print(data)
            if (data == 'blue'):
                pycom.rgbled(0x00000f)  # dim blue
            if (data == 'red'):
                pycom.rgbled(0x0f0000)  # dim red
            if (data == 'green'):
                pycom.rgbled(0x000f00)  # dim green
            wdt.feed()
        if events & LoRa.TX_PACKET_EVENT:
            print('Lora packet sent')
            print('TX_PACKET_EVENT')
            pycom.rgbled(0x00000f)
            time.sleep(0.5)
            pycom.rgbled(0x000000)
            wdt.feed()
    
    ##### Handles the sending of Messages #####
    
    
    class Clock:
        def __init__(self):
            ####!! Change time interval for sending here '(self._seconds_handler, <TIME_IN_SECONDS>,..)' !!####
            self.__alarm = machine.Timer.Alarm(self._seconds_handler, 60, periodic=True)
    
        def _seconds_handler(self, alarm):
            print('Attempting to send !!!!!')
            wdt.feed()
            s.setblocking(True)  # make socket blocking
            payload = "t:" + str(mp.temperature()) + ",l:" + str(lt.light())
            print("Payload : ",payload)
            try:  # send some data with error handler
                print('sending !!!')
                s.send(payload)
                print('sent')
                pycom.rgbled(0x000f00)
                time.sleep(0.5)
                pycom.rgbled(0x000000)
                # lora.nvram_save()
            except OSError as err:
                print("OS error: {0}".format(err))
                _seconds_handler
            except ValueError:
                print("ValueError.")
            except:
                print("Unexpected error:", sys.exc_info()[0])
    
            s.setblocking(False)  # make the socket non-blocking
    
    
    # Start WDT
    wdt = machine.WDT(timeout=1000000)
    
    # LoRa OTAA authentication parameters
    app_eui = ubinascii.unhexlify('3C71BF8773B8')
    app_key = ubinascii.unhexlify('10d441d14e0cc75f09fb60b2ec46047c')
    
    # Join LoRA network using OTAA
    lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)
    # LED is red whilst not joined
    pycom.rgbled(0x0f0000)
    # wait until we have joined the network
    while not lora.has_joined():
        time.sleep(2.5)
        print(ubinascii.hexlify(lora.mac()).upper().decode('utf-8'))
        print('Not yet joined US915...')
    wdt.feed()
    # Confirming join status here
    loraStatus = str(lora.has_joined())
    print('Lora joined: ' + loraStatus)
    # LED goes green for 3 seconds upon join
    pycom.rgbled(0x000f00)
    time.sleep(3)
    pycom.rgbled(0x000000)
    
    
    ### Initialise Callbacks and Timers ###
    lora.callback(trigger=(LoRa.RX_PACKET_EVENT |
                           LoRa.TX_PACKET_EVENT |
                           LoRa.TX_FAILED_EVENT), handler=lora_cb)
    clock = Clock()
    wdt.feed()
    

    any input on what could be causing this to happen


Log in to reply
 

Pycom on Twitter