importerror:无法从“network”导入名称“lora”

xbp102n0  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(360)

我试着用python在我的树莓上使用lora。
这是我的密码:

from network import LoRa
import socket
import time
import ubinascii

# Initialise LoRa in LORAWAN mode.

# Europe = LoRa.EU868

lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868, sf=12)

# create an OTAA authentication parameters

dev_eui = ubinascii.unhexlify('DEADDEAD0009DEAB')
app_eui = ubinascii.unhexlify('DEAD25DEAD25DEAD')
app_key = ubinascii.unhexlify('0123456789ABCDEF0123456789ABCDEF')

# join a network using OTAA (Over the Air Activation)

lora.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0)

# wait until the module has joined the network

# try each second

while not lora.has_joined():
    time.sleep(1)
    print('Not yet joined...')

print("Joined!")

# 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)

# send some data

while True:
    s.send("This is a message from Armand".encode())
    ##s.setblocking(False)
    time.sleep(1.0)

# get any data received (if any...)

data = s.recv(64)
print(data)

但它在执行时甚至无法通过导入 python3 my_file.py ,我得到一个 ImportError: cannot import name 'LoRa' from 'network' (后来我得到了与ubinascii相同的错误),而我成功地执行了 pip3 install network 命令。
我查了network.py文件,但里面没有提到劳拉。
我安装了正确的软件包吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题