Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    setsockopt fails with EOPNOTSUPP

    Scheduled Pinned Locked Moved LoPy
    lorawansetsockoptlopy
    10 Posts 6 Posters 4.2k Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B Offline
      bbfnq
      last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • B Offline
        bucknall
        last edited by

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

        Thanks!

        Developer Evangelist - Pycom

        B 1 Reply Last reply Reply Quote 0
        • B Offline
          bbfnq
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • B Offline
            bbfnq @bucknall
            last edited by

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

            B 1 Reply Last reply Reply Quote 0
            • B Offline
              bucknall @bbfnq
              last edited by

              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!

              Developer Evangelist - Pycom

              1 Reply Last reply Reply Quote 0
              • F Offline
                FrenkieG
                last edited by

                Use spaces in your keys

                1 Reply Last reply Reply Quote 0
                • W Offline
                  wteason
                  last edited by

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

                  J 1 Reply Last reply Reply Quote 0
                  • J Offline
                    jmarcelino @wteason
                    last edited by

                    @wteason

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

                    W 1 Reply Last reply Reply Quote 1
                    • W Offline
                      wteason @jmarcelino
                      last edited by

                      @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... :-/

                      1 Reply Last reply Reply Quote 0
                      • K Offline
                        ksamuelson
                        last edited by

                        This post is deleted!
                        1 Reply Last reply Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • 1 / 1
                        • First post
                          Last post

                        Pycom on Twitter

                        Pycom