def run(self): BOARD.setup() parser = LoRaArgumentParser("Continous LoRa receiver.") lora = LoRaRcvCont(verbose=False) args = parser.parse_args(lora) lora.set_mode(MODE.STDBY) lora.set_pa_config(pa_select=1) lora.set_freq(434.0) #lora.set_rx_crc(True) #lora.set_coding_rate(CODING_RATE.CR4_6) #lora.set_pa_config(max_power=0, output_power=0) #lora.set_lna_gain(GAIN.G1) #lora.set_implicit_header_mode(False) #lora.set_low_data_rate_optim(True) #lora.set_pa_ramp(PA_RAMP.RAMP_50_us) #lora.set_agc_auto_on(True) print("lora: {0}".format(lora)) assert (lora.get_agc_auto_on() == 1) time.sleep(1) try: lora.start() except KeyboardInterrupt: sys.stdout.flush() print("") sys.stderr.write("KeyboardInterrupt\n") finally: sys.stdout.flush() print("") lora.set_mode(MODE.SLEEP) print(lora) BOARD.teardown()
def lorainit(): global lora BOARD.setup() lora = LoRa(verbose=False) lora.set_mode(MODE.STDBY) lora.set_freq(923.0) #set to 915MHz for SG use
def controller_init(self, enablecontroller=None): if enablecontroller != None: self.enabled = enablecontroller self.initialized = False if self.enabled: if int(Settings.Settings["Unit"]) > 0: self.controllerport = Settings.Settings["Unit"] try: BOARD.setup() gpios.HWPorts.remove_event_detect(BOARD.DIO0) gpios.HWPorts.remove_event_detect(BOARD.DIO1) gpios.HWPorts.remove_event_detect(BOARD.DIO2) gpios.HWPorts.remove_event_detect(BOARD.DIO3) except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, "LORA Direct preinit msg: " + str(e)) try: self.lora = LoRaRcvCont(self.pkt_receiver) self.connect() self.initialized = True misc.addLog(rpieGlobals.LOG_LEVEL_INFO, "LORA Direct initialized") except Exception as e: self.initialized = False misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, "LORA Direct init error: " + str(e)) return True
def __init__(self, _verbosity=False): BOARD.setup() LoRa.__init__(self, _verbosity) self.set_mode(MODE.SLEEP) self.set_dio_mapping([1, 0, 0, 0, 0, 0]) self.tx_counter = 0 self.set_freq(LoRa_frequency) self.set_agc_auto_on(True) self.set_pa_config(pa_select=1, output_power=15) self._end = False
def tx(msg): BOARD.setup() lora = LoRaTransmit() lora.set_freq(868.000000) lora.set_pa_config(pa_select=1, max_power=5) lora.set_bw(8) lora.set_coding_rate(CODING_RATE.CR4_5) try: lora.send(msg) finally: lora.set_mode(MODE.SLEEP) BOARD.teardown()
def __init__(self, verbose=False): BOARD.setup() BOARD.reset() super(Transceiver, self).__init__(verbose) self.set_mode(MODE.SLEEP) self.config("long") self.setmode("RX") self.receiving = [] self.transmitting = [] self.txn = 0 self.rxn = None assert(self.get_agc_auto_on() == 1)
def main(): BOARD.setup() receiver = MyLoRa() try: while True: sleep(0.05) irq_flags = receiver.get_irq_flags() if irq_flags['rx_done'] == 1: receiver.on_rx_done() finally: BOARD.teardown()
def txRepeat(msg, num): BOARD.setup() lora = LoRaTransmit() lora.set_freq(868.000000) lora.set_pa_config(pa_select=1, max_power=5) lora.set_bw(8) lora.set_coding_rate(CODING_RATE.CR4_5) try: for i in range(0, num): lora.send(msg) try: with timeout(seconds=2): while lora.transmitting: sleep(0.1) except TimeoutError: print("Sending timed out.") sleep(1) finally: lora.set_mode(MODE.SLEEP) BOARD.teardown()
def txMulti(msg): BOARD.setup() lora = LoRaTransmit() lora.set_freq(868.000000) lora.set_pa_config(pa_select=1, max_power=5) lora.set_bw(8) lora.set_coding_rate(CODING_RATE.CR4_5) try: while len(msg) > 0: part = msg[:256] msg = msg[256:] lora.send(part[1:]) try: with timeout(seconds=3): while lora.transmitting: sleep(0.1) except TimeoutError: print("Sending timed out.") finally: lora.set_mode(MODE.SLEEP) BOARD.teardown()
def __init__(self): super(LoraServer,self).__init__() MyLog.debug('LoraServer in') BOARD.setup() self.lora = LoRa() self.LoraServer_init(self.lora) self.WaitCarComeTime = int(120) # 等待车子停进来的时间,2min不来就升锁 self.WaitCarLeaveTime = int(300) # 车子停进来前5min,依旧是2min升锁,超出时间立刻升锁 self.AfterCarLeaveTime = int(10) # 超出5min,认为车子是要走了,1min升锁 try: cf = configparser.ConfigParser() cf.read(path.expandvars('$HOME') + '/Downloads/WWTFrontServer_Lora/Configuration.ini', encoding="utf-8-sig") self.WaitCarComeTime = cf.getint("StartLoad", "WaitCarComeTime") self.WaitCarLeaveTime = cf.getint("StartLoad", "WaitCarLeaveTime") self.AfterCarLeaveTime = cf.getint("StartLoad", "AfterCarLeaveTime") except Exception as ex: MajorLog(ex + 'From openfile /waitcartime') MyLog.debug("WaitCarComeTime:" + str(self.WaitCarComeTime)) MyLog.debug("WaitCarLeaveTime:" + str(self.WaitCarLeaveTime)) MyLog.debug("AfterCarLeaveTime:" + str(self.AfterCarLeaveTime)) global stridList stridList = [] self.mtimer = QTimer() self.mtimer.timeout.connect(self.LockAutoDown) self.mtimer.start(1000) self.mtimer2 = QTimer() self.mtimer2.timeout.connect(self.WaitCarStatusDisable) self.mtimer2.start(1000) pass
def __init__(self, freqs=LORA_FREQS, sf=DEFAULT_SF, logging_level=DEFAULT_LOG_LEVEL, gps_baud_rate=DEFAULT_BAUD_RATE, gps_serial_port=DEFAULT_SERIAL_PORT, gps_serial_timeout=DEFAULT_SERIAL_TIMEOUT, lora_retries=DEFAULT_RETRIES): self.logger = logging.getLogger("Dragino") self.logger.setLevel(logging_level) logging.basicConfig( format= '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(message)s' ) BOARD.setup() super(Dragino, self).__init__(logging_level < logging.INFO) self.devnonce = [randrange(256), randrange(256)] #random none self.logger.debug("Nonce = %s", self.devnonce) self.freqs = freqs self.device_addr = None self.network_key = None self.apps_key = None self.lora_retries = lora_retries self.frame_count = 0 self.set_mode(MODE.SLEEP) self.set_dio_mapping([1, 0, 0, 0, 0, 0]) freq = freqs[randrange(len(freqs))] #Pick a random frequency self.set_freq(freq) self.logger.info("Frequency = %s", freq) self.set_pa_config(pa_select=1) self.set_spreading_factor(sf) self.logger.info("SF = %s", sf) self.set_pa_config(max_power=MAX_POWER, output_power=OUTPUT_POWER) self.set_sync_word(SYNC_WORD) self.set_rx_crc(RX_CRC) assert self.get_agc_auto_on() == 1 self.gps_serial = Serial(gps_serial_port, gps_baud_rate, timeout=gps_serial_timeout)
self.assertEqual(get_reg(REG.LORA.DIO_MAPPING_2), 0b00000000) self.assertEqual(lora.get_dio_mapping(), dio_mapping) dio_mapping = [0, 1, 2, 0, 1, 2] lora.set_dio_mapping(dio_mapping) self.assertEqual(get_reg(REG.LORA.DIO_MAPPING_1), 0b00011000) self.assertEqual(get_reg(REG.LORA.DIO_MAPPING_2), 0b01100000) self.assertEqual(lora.get_dio_mapping(), dio_mapping) dio_mapping = [1, 2, 0, 1, 2, 0] lora.set_dio_mapping(dio_mapping) self.assertEqual(get_reg(REG.LORA.DIO_MAPPING_1), 0b01100001) self.assertEqual(get_reg(REG.LORA.DIO_MAPPING_2), 0b10000000) self.assertEqual(lora.get_dio_mapping(), dio_mapping) # def test_set_lna_gain(self): # bkup_lna_gain = lora.get_lna()['lna_gain'] # for target_gain in [GAIN.NOT_USED, GAIN.G1, GAIN.G2, GAIN.G6, GAIN.NOT_USED, bkup_lna_gain]: # print(target_gain) # lora.set_lna_gain(target_gain) # actual_gain = lora.get_lna()['lna_gain'] # self.assertEqual(GAIN.lookup[actual_gain], GAIN.lookup[target_gain]) if __name__ == '__main__': BOARD.setup() lora = LoRa(verbose=False) unittest.main() BOARD.teardown()
# # You can be released from the requirements of the license by obtaining a commercial license. Such a license is # mandatory as soon as you develop commercial activities involving pySX127x without disclosing the source code of your # own applications, or shipping pySX127x with a closed source product. # # You should have received a copy of the GNU General Public License along with pySX127. If not, see # <http://www.gnu.org/licenses/>. import sys from time import sleep from SX127x.LoRa import * from SX127x.LoRaArgumentParser import LoRaArgumentParser from SX127x.board_config import BOARD BOARD.setup() parser = LoRaArgumentParser("A simple LoRa beacon") parser.add_argument('--single', '-S', dest='single', default=False, action="store_true", help="Single transmission") parser.add_argument('--wait', '-w', dest='wait', default=1, action="store", type=float, help="Waiting time between transmissions (default is 0s)") class LoRaBeacon(LoRa): tx_counter = 0 def __init__(self, verbose=False): super(LoRaBeacon, self).__init__(verbose) self.set_mode(MODE.SLEEP) self.set_dio_mapping([1,0,0,0,0,0])
""" Beacon Class """ """ Thomas Verbeke - [email protected] Send out data + counter value Tested with Embed LoRa Module (SX1276 Semtech chip) """ import sys from time import sleep from SX127x.LoRa import * from SX127x.board_config import BOARD, GPIO BOARD.setup() # setup GPIO's class LoRaBeacon(LoRa): tx_counter = 0 def __init__(self, verbose=False): super(LoRaBeacon, self).__init__(verbose) self.set_mode(MODE.SLEEP) self.set_dio_mapping([1,0,0,0,0,0]) #DIO0 is set to TxDone """ DIO Mapping DIO5 DIO4 DIO3 DIO2 DIO1 DIO0 ModeReady CadDetected CadDone FhssChangeChannel RxTimeout TxDone """ def on_rx_done(self): # will not be called trough DIO (because it is mapped to TxDone)
import os import threading import time import cola from subirDatosServidor import * from SX127x.LoRa import * from SX127x.board_config import BOARD from data_frame import * import pickle from angles import sexa2deci """Es necesario instalar la libreria angles "pip install angles""" BOARD.setup() #Mapeo de pines de la raspberry BOARD.reset() #Reseteo de los pines nodos = 1 # Cantidad de Nodos Clientes(maximo 255) t_sample = 1 #Decenas de segundos(maximo 255) class mylora(LoRa): def __init__(self, verbose=False): super(mylora, self).__init__(verbose) self.set_mode(MODE.SLEEP) self.set_dio_mapping([0] * 6) self.Recibido = False # Flag de paquete recibido self.TimeOut = False # Flag para detectar Timeout self.paqueteACK = bytes( [0]) # paquete ACK utilizado para indicar la llegada de un mensaje self.paqueteRecibidoC = bytes(0) #Callbacks def on_rx_done(self):
#!/usr/bin/env python import sys from time import sleep from SX127x.LoRa import * from SX127x.board_config import BOARD BOARD.setup() # setup GPIO's class LoRaBeacon(LoRa): tx_counter = 0 def __init__(self, verbose=False): super(LoRaBeacon, self).__init__(verbose) self.set_mode(MODE.SLEEP) self.set_dio_mapping([1, 0, 0, 0, 0, 0]) #DIO0 is set to TxDone """ DIO Mapping DIO5 DIO4 DIO3 DIO2 DIO1 DIO0 ModeReady CadDetected CadDone FhssChangeChannel RxTimeout TxDone """ def on_rx_done( self ): # will not be called trough DIO (because it is mapped to TxDone) print("\n(RxDone) Packet Received") print(self.get_irq_flags()) print('num bytes payload', self.get_rx_nb_bytes()) payload = self.read_payload(nocheck=True)
global FireBefore FireBefore = FireBefore + 1 timer = threading.Timer(300,Fire_timer) timer.start() break else: temp = str.split(temp) sendMsgHT(temp[1],temp[2]) break self.set_mode(MODE.SLEEP) self.reset_ptr_rx() self.set_mode(MODE.RXCONT) count = count - 1 if __name__ == '__main__': global EmailFlag BOARD.setup() #open SPI and other GPIO lora = LoRaRcvCont() lora.set_pa_config(pa_select=1) lora.set_freq(366) #set freqency videoName = 1 global FireBefore,FireFlag FireBefore,FireFlag = 1,1 global SomeBefore,SomeFlag SomeBefore,SomeFlag = 1,1 while True: print(FireFlag) time.sleep(0.5) temp = getOrder() print("THIS 1",temp) if temp == "NUL": lora.startRec()