def __init__(self, name, args, config_set, test_set):
        self.name = name
        self.config_set = config_set
        self.test_set = test_set
        self.capture_freq = args.frequency
        self.frequency_offset = args.frequency_offset
        self.sample_rate = args.sample_rate
        self.hw = args.hw
        self.name += "_" + self.hw
        self.path = os.path.join(args.data_out, self.name)
        self.pre_delay = 0.150
        self.post_delay = 1.0
        self.intra_delay = 0.1
        self.lc = RN2483Controller("/dev/lora")
        self.test_count = 0

        # Prepare SigMF global metadata (identical for all tests)
        self.global_meta = {
            "core:datatype": "cf32_le",
            "core:version": "0.0.1",
            "core:license": "CC0",
            "core:hw": self.hw,
            "core:sample_rate": self.sample_rate,
            "core:author": "Pieter Robyns"
        }

        # Prepare paths for storing suite
        try:
            if not os.path.exists(self.path):
                os.makedirs(self.path)
        except:
            Exception("Error creating output directory.")
 def __init__(self, num_messages):
     Thread.__init__(self)
     self.setDaemon(True)
     self.num_messages = num_messages
     self.lc = RN2483Controller("/dev/lora")
     self.lc.set_sf(7)
     self.name = "receiver_hw"
     self.data = {'payloads': [], 'snrs': []}
Exemple #3
0
    def __init__(self, mutex):
        Thread.__init__(self)
        self.setDaemon(True)
        self.lc = RN2483Controller("/dev/ttyACM0")
        self.lc.set_sf("7")
        self.lc.set_pwr("15")
        self.lc.get_bt()
#        self.lc.set_bt("none")
#        self.lc.set_freq("868000000")
        print("LoRa frequency: ",self.lc.get_freq())
        self.mutex = mutex
        self.counter = 4278190080
import configparser
from loranode.rpyutils import printd, Level, Color, clr, set_debug_level
from loranode import RN2483Controller

# LoRaController OTAA based join and message test
if __name__ == "__main__":
    set_debug_level(Level.DEBUG)

    # Parse config
    cp = configparser.ConfigParser()
    cp.read('lora.cfg')
    config = cp['DEFAULT']

    # Test controller
    lc = RN2483Controller(config.get("port"))
    if lc.test():
        printd("[+] Connected to LoRa RN2483 device", Level.INFO)
    else:
        printd(clr(Color.YELLOW, "[-] Failed to get version from LoRa device"), Level.WARNING)

    # Join and send a message
    if lc.join_otaa(config.get("appkey"), config.get("appeui"), config.get("deveui")):
        printd("[+] Connected to gateway", Level.INFO)
        lc.set_adr(True)
        lc.set_pwr(14)
        if lc.send("AC", ack=False):
            printd(clr(Color.GREEN, "[+] Test succeeded"), Level.CRITICAL)
            del lc
            exit()
Exemple #5
0
 def __init__(self, mutex):
     Thread.__init__(self)
     self.setDaemon(True)
     self.lc = RN2483Controller("/dev/ttyUSB1")
     self.mutex = mutex
     self.counter = 0
Exemple #6
0
    def __init__(self,
                 spreadingFactor=7,
                 codingRate="4/5",
                 output_dir='./lora-samples/',
                 output_prefix='examplify_data',
                 gains=[10, 20, 20]):
        ##################################################
        # Variables                                      #
        ##################################################
        self.target_freq = 868.1e6
        self.sf = spreadingFactor  # 6 7 8 12
        self.samp_rate = 1e6
        self.capture_freq = 868.0e6
        self.bw = 125e3
        #self.symbols_per_sec = self.bw  / (2**self.sf)
        self.offset = -(self.capture_freq - self.target_freq)
        #self.bitrate         = self.sf * (1 / (2**self.sf / self.bw ))
        self.crc = True
        self.pwr = 1
        self.codingRate = codingRate  # 4/5 4/6 4/7

        try:
            if not os.path.exists(output_dir):
                os.makedirs(output_dir)
        except:
            Exception("Error creating output directory.")

        self.output_dir = output_dir
        self.output_prefix = output_prefix
        self.output_ext = '.cfile'
        self.outputFile = self.output_dir + self.output_prefix + self.output_ext
        self.pre_delay = 0.150
        self.post_delay = 0.350
        self.trans_delay = 0.1
        self.examples_output = []

        ##################################################
        # LoRa transmitter                               #
        ##################################################
        try:
            self.lc = RN2483Controller("/dev/lora")
            self.lc.set_cr(self.codingRate)
            self.lc.set_bw(self.bw / 1e3)
            self.lc.set_sf(self.sf)
            self.lc.set_crc("on" if self.crc else "off")
            self.lc.set_pwr(self.pwr)
        except:
            raise Exception(
                "Error initialising LoRa transmitter: RN2483Controller")

        ##################################################
        # Blocks                                         #
        ##################################################
        self.tb = gr.top_block()

        self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                               '')
        self.osmosdr_source_0.set_sample_rate(self.samp_rate)
        self.osmosdr_source_0.set_center_freq(self.capture_freq, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(0, 0)
        self.osmosdr_source_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_0.set_gain_mode(False, 0)
        self.osmosdr_source_0.set_gain(gains[0], 0)
        self.osmosdr_source_0.set_if_gain(gains[1], 0)
        self.osmosdr_source_0.set_bb_gain(gains[2], 0)
        self.osmosdr_source_0.set_antenna('', 0)
        self.osmosdr_source_0.set_bandwidth(0, 0)
    def __init__(self, spreadingFactor = 7, codingRate = "4/5",  gains = [10, 20, 20]):
        ##################################################
        # Variables                                      #
        ##################################################
        self.target_freq     = 868.1e6
        self.sf              = spreadingFactor  # 7 8 9 10 11 12
        self.samp_rate       = 1e6
        self.capture_freq    = 868.0e6
        self.bw              = 125e3
        #self.symbols_per_sec = self.bw  / (2**self.sf)
        self.offset          = -(self.capture_freq - self.target_freq)
        #self.bitrate         = self.sf * (1 / (2**self.sf / self.bw ))
        self.crc             = True
        self.pwr             = 1
        self.codingRate      = codingRate      # 4/5 4/6 4/7 4/8

        self.pre_delay       = 0.150
        self.post_delay      = 0.350
        self.trans_delay     = 0.250
        self.testResults     = None

        # Socket connection for sink
        self.host            = "127.0.0.1"
        self.port            = 40868

        self.server          = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.server.bind((self.host, self.port))
        self.server.setblocking(0)

        ##################################################
        # LoRa transmitter                               #
        ##################################################
        try:
            self.lc = RN2483Controller("/dev/lora")
            self.lc.set_cr ( self.codingRate)
            self.lc.set_bw ( self.bw / 1e3)
            self.lc.set_sf ( self.sf )
            self.lc.set_crc( "on" if self.crc else "off")
            self.lc.set_pwr( self.pwr )
        except:
            raise Exception("Error initialising LoRa transmitter: RN2483Controller")

        ##################################################
        # Blocks                                         #
        ##################################################
        self.tb = gr.top_block ()

        self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' )
        self.osmosdr_source_0.set_sample_rate(self.samp_rate)
        self.osmosdr_source_0.set_center_freq(self.capture_freq, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(0, 0)
        self.osmosdr_source_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_0.set_gain_mode(False, 0)
        self.osmosdr_source_0.set_gain(gains[0], 0)
        self.osmosdr_source_0.set_if_gain(gains[1], 0)
        self.osmosdr_source_0.set_bb_gain(gains[2], 0)
        self.osmosdr_source_0.set_antenna('', 0)
        self.osmosdr_source_0.set_bandwidth(0, 0)

        self.lora_lora_receiver_0         = lora.lora_receiver(self.samp_rate, self.capture_freq, self.offset, self.sf, self.samp_rate, 0.01)
        self.blocks_throttle_0            = blocks.throttle(gr.sizeof_gr_complex*1, self.samp_rate, True)
        self.blocks_message_socket_sink_0 = lora.message_socket_sink()

        self.tb.connect(     (self.osmosdr_source_0, 0),            (self.blocks_throttle_0, 0))
        self.tb.connect(     (self.blocks_throttle_0, 0),           (self.lora_lora_receiver_0, 0))
        self.tb.msg_connect( (self.lora_lora_receiver_0, 'frames'), (self.blocks_message_socket_sink_0, 'in'))