Esempio n. 1
0
    async def check_wifi(self):
        while True:
            self.loop.create_task(self.connect(True))

            if self.credentials.load().is_valid():
                await sleep_ms(WAIT_FOR_CONNECT)

            if not self.sta_if.isconnected():
                self.loop.create_task(self.start_access_point())

            while not self.sta_if.isconnected():
                await sleep_ms(CHECK_CONNECTED)

            self.ip = self.sta_if.ifconfig()[0]

            Blink().flash3TimesFast()

            print("> Connected to {} with IP: {}".format(
                self.credentials.essid.decode("ascii"), self.ip))

            if self.ap_if.active():
                # Leave a bit of time so the client can retrieve the Wifi IP address
                await sleep_ms(WAIT_BEFORE_AP_SHUTDOWN)

                print("> Shuting down AP")
                self.ap_if.active(False)

            while self.sta_if.isconnected():
                await sleep_ms(CHECK_CONNECTED)
Esempio n. 2
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.blink = Blink()
     self.blink.rgb(0,0,0,1)
     self.daemon = True
     self.queue = Queue.Queue()
     self.history = []
     self.killed = False
Esempio n. 3
0
class BlinkFader(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.blink = Blink()
        self.blink.rgb(0,0,0,1)
        self.daemon = True
        self.queue = Queue.Queue()
        self.history = []
        self.killed = False

    def run(self):
        while not self.killed:
            while not self.queue.empty():
                (r,g,b) = self.queue.get()

                self.blink.rgb(r,g,b, 1000)
                self.history.append((r,g,b))
                sleep(6)

                # self.blink.rgb(0, 0, 0, 1000)
                # sleep(2.5)

            self.addHistoryToQueue()

    def addHistoryToQueue(self):
        for (r,g,b) in self.history:
            self.add(r,g,b)
        sleep(.1)

    def add(self, r, g, b):
        self.queue.put((r,g,b))

    def clear(self):
        while not self.queue.empty():
            self.queue.get()
        del self.history[0:len(self.history)]
        self.blink.off()

    def kill(self):
        self.killed = True