How to get data from a particular device in lopy ?



  • Hi Everyone !
    I just need to know how to get data from a particular device ? To make clear, I am using Lopy as a repeater.For example, now I am sending data from arduino, and lopy perfectly transmits to the server. But now I have to create a list in lopy with the several device address , so it should only get data from those particular devices. I hope everyone understands me.I will share my code here.

    from network import LoRa
    import socket
    import binascii
    import struct
    
    while True:
    
        lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868, sf = 7, frequency = 868500000)
    
        # create a raw LoRa socket
        s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
        s.setblocking(True)
    
        # get any data received...
        data = s.recv(64)
        print(data)
    
        lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868,  sf = 12)
    
        # create an ABP authentication params
        dev_addr = struct.unpack(">l", binascii.unhexlify('26010000'))[0]
        nwk_swkey = binascii.unhexlify('9A51C4DD083444A245C0000000000000')
        app_swkey = binascii.unhexlify('7DF13A7CD2B2AA078710000000000000')
    
        # join a network using ABP (Activation By Personalization)
        lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))
    
        # 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)
    
        # make the socket blocking
        # (waits for the data to be sent and for the 2 receive windows to expire)
        s.setblocking(True)
    
        # send some data
        s.send(data)
        print('data sent')
    

    Thank you in Advance !



  • @robert-hh Sorry for the late and Thanks for your reply. I have tried with simple change like adding if statement with particular device address but it's not working. Is there any other possible way ?



  • @harish-kumar You cannot restrict your Lopy repeater to receive messages only from certain devices. You have to add any controls at your script level. And be also aware, that at the LoRaWAN server you will all data see as being sent by your repeater.



Pycom on Twitter