lora.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:INF3910-LoPy 作者: TobiasBorgen 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号