from weather_master import PackageReader from aws import AWS print("Start Master Module Simulator") reader = PackageReader() print("\nRxDone") #payload = [0x0A, 0x05, 0x2E, 0x95, 0xF3, 0x71, 0x84, 0x00, 0x62, 0x11] payload = [ 0x10, 0x05, 0x2E, 0x8F, 0xED, 0x8C, 0x8E, 0x00, 0x64, 0x17, 0x3F, 0x2C, 0x23, 0x01, 0x89, 0x44 ] #10052E8FED8C8E0064173F2C23018944 print(bytes(payload).hex()) reader.read_package(payload, True) db = AWS() db.connect() db.publish_sensor_data(reader.data_pack, True) db.disconnect()
class LoRaMaster(LoRa): def __init(self): super(LoRaRcvCont, self).__init__(verbose) self.set_mode(MODE.STDBY) #self.set_dio_mapping([0] * 6) self.db = AWS() def on_rx_done(self): BOARD.led_on() self.clear_irq_flags(RxDone=1) reader.read_package(self.read_payload(nocheck=True), True) self.set_mode(MODE.SLEEP) self.reset_ptr_rx() BOARD.led_off() self.set_mode(MODE.RXCONT) if (reader.is_accepted): self.db.connect() self.db.publish_sensor_data(reader.data_pack, True) self.db.disconnect() def on_txdone(self): print("\nTxDone") print(self.get_irq_flags()) def on_cad_done(self): print("\non_CadDone") print(self.get_irq_flags()) def on_rx_timeout(self): print("\non_RxTimeout") print(self.get_irq_flags()) time.sleep(.5) self.set_mode(MODE.SLEEP) self.reset_ptr_rx() self.set_mode(MODE.RXCONT) def on_valid_header(self): print("\non_ValidHeader") print(self.get_irq_flags()) def on_payload_crc_error(self): print("\non_PayloadCrcError") print(self.get_irq_flags()) def on_fhss_change_channel(self): print("\non_Fhss_changeChannel") print(self.get_irq_flags()) def print_payload(self, payload): chex_sum = payload[0] cmd = payload[1] print("chex_sum: \t{}".format(chex_sum)) print("payload len: \t{}".format(len(payload))) if (chex_sum == len(payload)): print("payload of correct length") else: print("payload of incorrect length") print("command: \t{}".format(cmd)) def start(self): self.db = AWS() self.reset_ptr_rx() self.set_mode(MODE.RXCONT) while True: time.sleep(.5) rssi_value = self.get_rssi_value() snr_value = self.get_pkt_snr_value() status = self.get_modem_status() sys.stdout.flush() sys.stdout.write("\r%d %d %d %d" % (rssi_value, snr_value, status['rx_ongoing'], status['modem_clear']))