Lora Class: C config
-
Hello everyone! Since a few weeks I'm trying to use my Lopy4 in C class and I'm not obtaining good results.
This is my code:
self.lora = LoRa( mode=LoRa.LORAWAN, region=LoRa.EU868, device_class=LoRa.CLASS_C, tx_retries = 5, adr=True, sf=7)
I need to add some more parameter? The problem is despite having defined class C, it still works as if it were in class A. And it only receives the downlink after having made an uplink.
If it's necessary, this is all my code:
class myLoRa: def __init__(self): # LoRa device parameters self.dev_eui = config.dev_eui self.app_eui = config.app_eui self.app_key = config.app_key # self.region = config.lora_region self.lora_class = config.lora_class self.lora_sf = config.lora_sf # Initialize LoRa in LORAWAN mode. self.lora = LoRa( mode=LoRa.LORAWAN, region=self.region, device_class=self.lora_class, tx_retries = 3, adr=False, sf=self.lora_sf) # Understand the events during LoRa comunication self.lora.callback(trigger=(LoRa.RX_PACKET_EVENT | LoRa.TX_PACKET_EVENT | LoRa.TX_FAILED_EVENT), handler=self.lora_events) def LoRa_join(self): # join a network using OTAA self.lora.join( activation=LoRa.OTAA, auth=(self.dev_eui, self.app_eui,self.app_key), timeout=0, dr=self.dr) # wait until the module has joined the network cnt = 0 while not self.lora.has_joined(): time.sleep(2.5) if config.debug: print('\t\t· Trying to join...', str(cnt)) if (cnt < 30): cnt += 1 else: machine.reset() def LoRa_socket(self): self.lora_socket = socket.socket(socket.AF_LORA, socket.SOCK_RAW) self.lora_socket.setsockopt(socket.SOL_LORA,socket.SO_CONFIRMED,True) self.lora_socket.setblocking(True) def LoRa_send(self, payload): self.lora_socket.send(payload) def lora_events(self, lora): events = self.lora.events() if events & LoRa.RX_PACKET_EVENT: if config.debug: print('\t\t· Lora packet RECEIVED') self.lora_socket.setblocking(False) value = self.lora_socket.recv(64) self.lora_socket.setblocking(True) self.LoRa_downlink_handler(value) if events & LoRa.TX_PACKET_EVENT: if config.debug: print('\t\t· Lora packet sent') if events & LoRa.TX_FAILED_EVENT: if config.debug: print('\t\t· Lora packet sent FAIL')
Thank you very much!!
-
@M-m you need to tell the network (LNS) that your device is a class C device. This information is not sent in LoRaWAN joins or other MAC commands, you need to configure it separately (usually in the place where you set up the device in the network, where the IDs are).