def setup_rfm98w(frequency=441.200, spi_device=0, shutdown=False, deviation = 71797): # Set this to 1 if your RFM98W is on CE1 hw = HardwareInterface(spi_device) # Start talking to the module... lora = LoRa(hw) # Set us into FSK mode, and set continuous mode on lora.set_register(0x01,0x00) # Standby Mode # If we have been asked to shutdown the RFM98W, then exit here. if shutdown: sys.exit(0) # Otherwise, proceed. lora.set_register(0x31,0x00) # Set Continuous Mode # Set TX Frequency lora.set_freq(frequency) # Set Deviation (~70 kHz). Signals ends up looking a bit wider than the RFM22B version. _dev_lsbs = int(deviation / 61.03) _dev_msb = _dev_lsbs >> 8 _dev_lsb = _dev_lsbs % 256 lora.set_register(0x04,_dev_msb) lora.set_register(0x05,_dev_lsb) # Set Transmit power to 50mW. # NOTE: If you're in another country you'll probably want to modify this value to something legal... lora.set_register(0x09,0x8F) # Go into TX mode. lora.set_register(0x01,0x02) # .. via FSTX mode (where the transmit frequency actually gets set) lora.set_register(0x01,0x03) # Now we're in TX mode...
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 setup_rfm98w(frequency=434.650, spi_device=0, shutdown=False): # Set this to 1 if your RFM98W is on CE1 hw = HardwareInterface(spi_device) # Start talking to the module... lora = LoRa(hw) # Set us into FSK mode, and set continuous mode on lora.set_register(0x01, 0x00) # Standby Mode # If we have been asked to shutdown the RFM98W, then exit here. if shutdown: print("Transmitter shutdown.") sys.exit(0) # Otherwise, proceed. lora.set_register(0x31, 0x00) # Set Continuous Mode # Set TX Frequency lora.set_freq(frequency) # Set Deviation (~470 Hz) lora.set_register(0x04, 0x00) lora.set_register(0x05, 0x04) # Set Transmit power to 50mW. # NOTE: If you're in another country you'll probably want to modify this value to something legal... lora.set_register(0x09, 0x8F) # Go into TX mode. lora.set_register( 0x01, 0x02 ) # .. via FSTX mode (where the transmit frequency actually gets set) lora.set_register(0x01, 0x03) # Now we're in TX mode...
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
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()
from SX127x.LoRa import * from SX127x.board_config import BOARD BOARD.setup() lora = LoRa() from pdb import set_trace set_trace() BOARD.teardown()