导入错误:无法从“网络”导入名称“LoRa”

时间:2021-04-27 15:32:43

标签: python import pip raspberry-pi

我试图使用 Python 在我的 Raspberry 上使用 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 文件,它只是没有在任何地方提到 LoRa。

我是否通过 pip 安装了正确的软件包?

0 个答案:

没有答案