Пример #1
0
def thread_run(q):
    def _handle(data):
        msg = decode(decrypt(data, _password))
        if msg.get_topic() != _topic:
            q.put(msg)

    subscribe(_handle, channel=_channel)

    while _running:
        get_message()
        time.sleep(0.1)

    unsubscribe()
Пример #2
0
    def scan_mailbox(self, boxNum):
        print('scan')

        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))

        subscribe(fn=handle_mailbox, channel='inbound')
        while (self.mailbox_check() < boxNum):
            get_message()
            #time.sleep(.5)
        unsubscribe()
Пример #3
0
    print('Mailbox Number: ' + str(box))

    info('send', 'STATUS')
    packet = bytearray(config.OP_STATUS_SIZE)
    packet[0] = config.OP_STATUS
    packet[1:9] = crypto.get_checksum(packet)
    packet[9] = 1
    packet[10] = 1
    packet[11] = 1
    packet[12] = 1

    lora.send(packet)
    info('send', 'ACK {}'.format(lora.packet_str(packet)))

if __name__ == '__main__':
    boxNum = int(sys.argv[1])
    setup(boxNum)
    looping = True

    try:
        env.load(envPath)
        subscribe(fn=handle, channel='inbound')
        #subscribe(fn=handle, channel=get_topic())

        while looping:
            get_message()
            loop()
    except KeyboardInterrupt:
        looping = False
        destroy()