LoRa.region doesn't accept any attribute
AlejandroReyes last edited by
Hello everyone, I'm pretty desperate at this point. I'm trying to work with a couple of Lopy4 and I want to connect them by LORA so first i tried to use the code i found on https://docs.pycom.io/chapter/tutorials/lora/lora-mac.html "LoRa-MAC (Raw LoRa)"
from network import LoRa import socket import machine import time # initialize LoRa in LORA mode # Please pick the region that matches where you are using the device: # Asia = LoRa.AS923 # Australia = LoRa.AU915 # Europe = LoRa.EU868 # United States = LoRa.US915 # more params can also be given, like frequency, tx power and spreading factor lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868) # create a raw LoRa socket s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) while True: # send some data s.setblocking(True) s.send('Hello') # get any data received... s.setblocking(False) data = s.recv(64) print(data) # wait a random amount of time time.sleep(machine.rng() & 0x0F)
I pasted that code on my main.py, connected my lopy4 and tried to run it and surprise, it throws me this error: AttributeError: type object 'LoRa' has no attribute 'US915'.
I already tried to change the attribute to every available option ('EU868', etc.) and it throws the same error. You may be thinking that my lopy4 or pytrack have some trouble but I ran this code also from docs.pycom.io :
import pycom import time pycom.heartbeat(False) while True: pycom.rgbled(0xFF0000) # Red time.sleep(1) pycom.rgbled(0x00FF00) # Green time.sleep(1) pycom.rgbled(0x0000FF) # Blue time.sleep(1)
And... it worked. I hope you can help me with this.
moneer last edited by moneer
This post is deleted!
robert-hh last edited by
@alejandroreyes It means, the value returned is a byterarray (or bytes object) and not a string. You may convert it to a string using decode.
See also https://docs.python.org/3/library/stdtypes.html or similar.
AlejandroReyes last edited by
You were right, my problem is solved and I can go on with my project. Thank you so much. I just have one more doubt, the messages I get on the terminal are: b'Hello'. What does the b mean ?
Prawnhead last edited by
I think I've experienced this too. The code you've posted is for LoRa.MAC, as you said. You can also try to create a LoRa.LORAWAN object using this code:
from network import LoRa lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)
My guess is you'll get the same error. One or two things might be an issue here:
- Your firmware might be so old it doesn't contain any LoRa regions.
- If you haven't done a firmware upgrade (even to the same version) you won't have selected the LoRa region. There has to be a default region set on each device.
Can you please run this code to see the firmware version on your devices?
>>> import os >>> os.uname() (sysname='LoPy4', nodename='LoPy4', release='1.18.0', version='v1.8.6-849-046b350 on 2018-06-01', machine='LoPy4 with ESP32', lorawan='1.0.2', sigfox='1.0.1') >>>
Either way, I'd recommend doing a firmware update to the latest (1.19) and checking the box "Force update LoRa region". See: 1.2.2 Updating Firmware in the documentation.