Ejemplo n.º 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()
Ejemplo n.º 2
0
 def mailbox_setup(self, boxNum):
     self.currentWin = 'MAILBOX_SETUP'
     var = IntVar()
     boxwin = Frame(self.root)
     boxwin.pack()
     message = Message(
         boxwin,
         text=
         "Please use Its Here App to scan the Activation Code on the Mailbox. Only click continue once the code is scanned.",
         width=500)
     message.pack()
     button = Button(boxwin, text="Continue", command=lambda: var.set(1))
     button.pack()
     #wait for message on inbound
     scan = mp.Process(target=lambda: self.scan_mailbox(boxNum))
     scan.start()
     print(var.get())
     button.wait_variable(var)
     scan.terminate()
     scan.join()
     unsubscribe()
     boxwin.destroy()
     if (self.mailbox_check() >= boxNum):
         return
     else:
         boxChan = self.get_box_channel(boxNum)
         if (boxChan != ''):
             s = open('.env').read()
             s = s.replace(
                 "KIT_CHANNEL=" + os.environ['KIT_CHANNEL'],
                 "KIT_CHANNEL=" + os.environ['KIT_CHANNEL'] + ',' + boxChan)
             f = open('.env', 'w')
             f.write(s)
             f.close()
             self.get_env()
             self.kit.terminate()
             self.kit.join()
             self.kit = mp.Process(target=lambda: self.kit_start(self.pw))
             self.kit.start()
             #self.sensor.terminate()
             #self.sensor.join()
             self.sensor = mp.Process(target=lambda: self.sensor_start())
             self.sensor.start()
             self.activeList.append('REGISTERED')
             #self.sensor_setup(boxNum)
         else:
             return
Ejemplo n.º 3
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()
Ejemplo n.º 4
0
def destroy():
    unsubscribe()
    lora.close()
Ejemplo n.º 5
0
                listbox.insert(END, boxText)
                i+=1

            newMailbox = Button(kitwin, text="Add Mailbox", command=lambda: [kitwin.destroy(), self.mailbox_setup(self.mailbox_check()+1)])
            newMailbox.pack()
            button = Button(kitwin, text="Done", command=lambda: var.set(1))
            button.pack()
            button.wait_variable(var)
            self.currentWin = 'START'
            kitwin.destroy()

        else:
            kitwin = Toplevel(self.root)
            kitwin.title('Kit')
            message = Message(kitwin, text="Please Activate Mailbox", width=200)
            button = Button(kitwin, text="ok", command=kitwin.destroy)
            message.pack(padx=5, pady=5)
            button.pack()



if __name__ == '__main__':
    root = Tk()
    #gate.get_env()
    gate = Gateway(root=root)
    try:
        gate.mainloop()
    except:
        root.destroy()
        unsubscribe()