setsockopt fails with EOPNOTSUPP



  • When trying to run the LoRa ABP example code (from https://docs.pycom.io/pycom_esp32/library/network.LoRa.html#network.LoRa) on a LOPY, the following line:

    s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
    

    fails with EOPNOTSUPP.

    From the console, this happens:

    Connecting to a Pycom device...
    Connected
    >>> s2=socket.socket(socket.AF_LORA,socket.SOCK_RAW)
    >>> s2.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: [Errno 95] EOPNOTSUPP
    >>> os.uname()
    (sysname='LoPy', nodename='LoPy', release='1.6.7.b1', version='v1.8.6-493-g99ac80fe on 2017-03-03', machine='LoPy with ESP32', lorawan='1.0.0')
    

    Any ideas?



  • This post is deleted!


  • @jmarcelino Thanks for the quick reply. Yes, I'm in US915, and setting it to 3 does solve the issue. Now to figure out how to view what I'm sending from the LoPy to the mLinux Conduit gateway... :-/



  • @wteason

    SO_DR (datarate) 5 is only available in LoRa 868Mhz (EU868). Are you in a different region? For US915 it should be 3.



  • I'm experiencing the same problem. Was there ever any resolution to this based on the OP?



  • Use spaces in your keys



  • Hi @bbfnq! Apologies, I've been travelling without access to a LoPy the last couple of days - I did try it on the weekend at a hackathon I was at and there didn't seem to be any problems - I'll have a go at it when I'm back at the office tomorrow!



  • @bucknall Hi - just wondered if you had had any success looking at this? Is there any more information I might provide to help?



  • Hi @bucknall

    The code is exactly as in the example (except that the keys are different).

    main.py:

    from network import LoRa
    import socket
    import binascii
    import struct
    
    # Initialize LoRa in LORAWAN mode.
    lora = LoRa(mode=LoRa.LORAWAN)
    
    # create an ABP authentication params
    dev_addr = struct.unpack(">l", binascii.unhexlify('26011769'.replace(' ','')))[0]
    nwk_swkey = binascii.unhexlify('E44A1E59045F3CDD81A2606491F626D1'.replace(' ',''))
    app_swkey = binascii.unhexlify('85FFDD197900F1AD6D86F3E7DD9F46FC'.replace(' ',''))
    
    # join a network using ABP (Activation By Personalization)
    lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))
    
    # create a LoRa socket
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    
    # set the LoRaWAN data rate
    s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
    
    # make the socket non-blocking
    s.setblocking(False)
    
    # send some data
    s.send(bytes([0x01, 0x02, 0x03]))
    
    # get any data received...
    data = s.recv(64)
    print(data)
    

    boot.py is:

    from machine import UART
    import os
    uart = UART(0, 115200)
    os.dupterm(uart)
    

    Running the code (either by resetting the PyCom, or by pressing the Run button in Pymakr) results in the following at the console:

    Traceback (most recent call last):
      File "main.py", line 21, in <module>
    OSError: [Errno 95] EOPNOTSUPP
    

    Also from the console:

    >>> os.uname()
    (sysname='LoPy', nodename='LoPy', release='1.6.7.b1', version='v1.8.6-493-g99ac80fe on 2017-03-03', machine='LoPy with ESP32', lorawan='1.0.0')
    

    We have 2 LoPy boards and the problem occurs with both.

    Thanks.



  • Hi @bbfnq I'm trying to recreate what's happening with your code, are you running anything in your main.py script?

    Thanks!



Pycom on Twitter