def loop(): try: packet = lora.recv() if not packet: return info('loop', 'recv packet {}'.format(lora.packet_str(packet))) base_name = '{}_'.format(get_channel()) data = [] op = packet[0] size = len(packet) if op == config.OP_ACK: data.append({'bn': base_name, 'n': 'Flag', 'u': 'Flag', 'v': packet[9]}) data.append({'n': 'Lock', 'u': 'Lock', 'v': packet[10]}) data.append({'n': 'Package', 'u': 'Package', 'v': packet[11]}) data.append({'n': 'Power', 'u': 'Power', 'v': packet[12]}) data.append({'n': 'Error', 'u': 'Error', 'v': packet[13]}) box_checksum = packet[1:9] info('loop', 'box checksum {}'.format(lora.packet_str(box_checksum))) elif op == config.OP_CONNECT: data.append({'bn': base_name, 'n': 'Flag', 'u': 'Flag', 'v': packet[0]}) data.append({'n': 'Lock', 'u': 'Lock', 'v': packet[1]}) data.append({'n': 'Package', 'u': 'Package', 'v': packet[2]}) data.append({'n': 'Power', 'u': 'Power', 'v': packet[3]}) data.append({'n': 'Error', 'u': 'Error', 'v': packet[4]}) box_key = packet[5:] info('loop', 'box key {}'.format(lora.packet_str(box_key))) elif op == config.OP_STATUS: data.append({'bn': base_name, 'n': 'Flag', 'u': 'Flag', 'v': packet[9]}) data.append({'n': 'Lock', 'u': 'Lock', 'v': packet[10]}) data.append({'n': 'Package', 'u': 'Package', 'v': packet[11]}) data.append({'n': 'Power', 'u': 'Power', 'v': packet[12]}) box_checksum = packet[1:9] info('loop', 'box checksum {}'.format(lora.packet_str(box_checksum))) else: raise Exception('invalid OP packet {}'.format(op)) if len(data) > 1: info('send', 'ACK') packet = bytearray(config.OP_ACK_SIZE) packet[0] = config.OP_ACK packet[1:9] = crypto.get_checksum(packet) packet[9] = 1 packet[10] = 1 packet[11] = 1 packet[12] = 100 packet[13] = config.E_OK lora.send(packet) info('send', 'ACK {}'.format(lora.packet_str(packet))) msg = Message(get_topic(), data) info('loop', 'message {}'.format(msg)) publish(msg) except Exception as ex: error('loop', str(ex)) finally: time.sleep(0)
def handle(msg): try: info('handle', str(msg)) #if msg.get_base_name() != base_name: # return if(msg.get_topic() != self.get_topic()): return name = msg.get_name() if name == 'AUTH': print('allow', name, str(msg)) lora.send_allow(msg.get_value()) elif name == 'UNAUTH': print('deny', name, str(msg)) lora.send_deny(msg.get_value()) elif name == 'LOCK': print('lock', name, str(msg)) lora.send_lock() elif name == 'STATUS': print('status', name, str(msg)) lora.send_status() elif name == 'UNLOCK': print('unlock', name, str(msg)) lora.send_unlock() except Exception as ex: error('handle', str(ex))
def handle_mailbox(msg): print('in here............') try: info('handle', str(msg)) name = msg.get_name() print(name) if name == 'ADD': boxinfo = msg.get_str() print(boxinfo) if self.mailbox_exists(boxinfo): print('mailbox_exists') return #boxinfo[0] = Pub_Key s = open('.env').read() s = s.replace("GATE_PUB_KEYS="+os.environ['GATE_PUB_KEYS'], "GATE_PUB_KEYS="+os.environ['GATE_PUB_KEYS']+','+boxinfo) #s = s.replace("KIT_CHANNEL="+os.environ['KIT_CHANNEL'], "KIT_CHANNEL="+os.environ['KIT_CHANNEL']+','+self.get_box_channel(boxNum)) f = open('.env', 'w') f.write(s) f.close() #look up activate to get mailbox channel self.get_env() print('added', name, str(msg)) except Exception as ex: error('handle', str(ex))
def handle(msg): def check_topic(topic): i = 0 for x in os.environ['KIT_CHANNEL'].split(','): if i != 0 and x == topic.split('/')[1]: print ('xKey: ' + x + ' BoxNum: ' + str(i)) return i i+=1 return -1 try: info('handle', str(msg)) #if msg.get_base_name() != base_name: # return boxNum = check_topic(msg.get_topic()) if(boxNum == -1): return name = msg.get_name() if name == 'AUTH': print('allow', name, str(msg)) lora.send_allow(boxNum, msg.get_value()) elif name == 'UNAUTH': print('deny', name, str(msg)) lora.send_deny(boxNum, msg.get_value()) elif name == 'LOCK': print('lock', name, str(msg)) lora.send_lock(boxNum) elif name == 'STATUS': print('status', name, str(msg)) lora.send_status(boxNum) elif name == 'UNLOCK': print('unlock', name, str(msg)) lora.send_unlock(boxNum) except Exception as ex: error('handle', str(ex))
pwd = os.environ['PWD'] if '/tests' in pwd: pwd = '../' sys.path.insert(0, pwd) from kit.crypto import encrypt from kit.file import write_file from kit.logger import error from stellar_base.keypair import Keypair if __name__ == "__main__": parser = argparse.ArgumentParser(description='keypair arguments') parser.add_argument('--secret', default='', type=str, help='the secret key to use to create the secret.dat') args = parser.parse_args() if not args.secret: error('secret', 'please provide a --secret= value') sys.exit(1) try: password = getpass('Please provide your password: '******'secret.dat', data=data) except Exception as ex: error('secret', 'save error: ' + str(ex)) sys.exit(1)