Python socket.SO_DR() Examples

The following are code examples for showing how to use socket.SO_DR(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: WiPy-LoPy   Author: Enabling   File: connection.py    (license) View Source Project 7 votes vote down vote up
def __init__(self, deviceAddress, applicationKey, networkKey):
        from network import LoRa
        import socket
        import binascii
        import struct
        self.deviceAddress = deviceAddress
        self.applicationKey = applicationKey
        self.networkKey = networkKey
        self.lora = LoRa(mode=LoRa.LORAWAN)
        dev_addr = struct.unpack(">l", binascii.unhexlify(deviceAddress.replace(' ','')))[0]
        nwk_swkey = binascii.unhexlify(networkKey.replace(' ',''))
        app_swkey = binascii.unhexlify(applicationKey.replace(' ',''))
        self.lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))
        self.s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
        self.s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
        self.s.setblocking(False) 
Example 2
Project: SCHC   Author: ltn22   File: CoAP.py    (license) View Source Project 5 votes vote down vote up
def increase_lora_delivary_chances(element):
    if (element.attempts == 2): element.DR = 4
    elif (element.attempts == 4): element.DR = 2

    element.socket.setsockopt(socket.SOL_LORA, socket.SO_DR, element.DR) 
Example 3
Project: INF3910-LoPy   Author: TobiasBorgen   File: lora.py    (license) View Source Project 4 votes vote down vote up
def connect(self, dev_eui, app_eui, app_key):
    """
    Connect device to LoRa.
    Set the socket and lora instances.
    """
    
    dev_eui = unhexlify(dev_eui)
    app_eui = unhexlify(app_eui)
    app_key = unhexlify(app_key)
    
    # Disable blue blinking and turn LED off
    LED.heartbeat(False)
    LED.off()

    # Initialize LoRa in LORAWAN mode
    self.lora = LoRa(mode = LoRa.LORAWAN)

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

    # Wait until the module has joined the network
    count = 0
    while not self.lora.has_joined():
      LED.blink(1, 2.5, 0xff0000)
      # print("Trying to join: " ,  count)
      count = count + 1

    # Create a LoRa socket
    LED.blink(2, 0.1)
    self.s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)

    # Set the LoRaWAN data rate
    self.s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)

    # Make the socket non-blocking
    self.s.setblocking(False)

    # print ("Joined! ",  count)
    # print("Create LoRaWAN socket")

    # Create a raw LoRa socket
    self.s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    self.s.setblocking(False)