Beispiel #1
0
def send_open_request():
    LED.value(OFF)

    # send post request to open door
    if sta_if.isconnected():
        _, _, host, path = conf.URL.split('/', 3)

        try:
            host, port = host.split(':')
            port = int(port)
        except ValueError as e:
            port = 80

        try:
            # try to get address info from domain name
            addr = socket.getaddrinfo(host, port)[0][-1]
        except OSError:
            # then just parse IP
            addr = (host, port)

        s = socket.socket()
        try:
            s.connect(addr)
            s.send(
                bytes('POST /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host),
                      'utf8'))
            time.sleep(1)
        except OSError as e:
            pass

        s.close()

    LED.value(ON)
Beispiel #2
0
def connect(ssid=None, password=None, indicate=True):
    """Tries to connect to the wi-fi network"""
    if indicate:  # this is required because LED pin is blocking serial interface on ESP-01
        from utils.pins import LED

    ssid = ssid or conf.SSID
    password = password or conf.PASSWORD

    for i in range(conf.CONNECT_RETRIES):
        t_start = time.time()
        sta_if.connect(ssid, password)

        while not sta_if.isconnected():
            if indicate:
                LED.value(0)  # 0 - is enable for LED
                time.sleep(0.1)
                LED.value(1)
            time.sleep(0.1)

            t = time.time() - t_start
            if t >= conf.CONNECTION_TIME:
                break

        if sta_if.isconnected():
            return sta_if.isconnected()
Beispiel #3
0
def wait_and_add_card():
    print('Waiting to store new card')
    for _ in range(10):
        time.sleep(0.1)
        LED.value(not LED.value())
    LED.value(ON)

    card = reader.read_data([])
    if not card:
        return False

    print('Storing uid:', card.str_uid)
    storage.add_card(card.str_uid)

    for _ in range(10):
        time.sleep(0.1)
        LED.value(not LED.value())
    LED.value(OFF)

    return True
def connect(ssid=None, password=None):
    """Tries to connect to the wi-fi network"""
    ssid = ssid or conf.SSID
    password = password or conf.PASSWORD

    for i in range(conf.CONNECT_RETRIES):
        t_start = time.time()
        sta_if.connect(ssid, password)

        while not sta_if.isconnected():
            LED.value(0)  # 0 - is enable for LED
            time.sleep(0.1)
            LED.value(1)
            time.sleep(0.1)

            t = time.time() - t_start
            if t >= conf.CONNECTION_TIME:
                break

        if sta_if.isconnected():
            return sta_if.isconnected()
Beispiel #5
0
from utils import wifi
from utils.pins import LED
import gc

wifi.enable_wifi()
is_connected = wifi.connect()

LED.value(not is_connected)  # 'not' because 0 - is enable for led

gc.collect()
Beispiel #6
0
import esp; esp.osdebug(None)

import gc

from utils import wifi
from utils.pins import LED, ON

wifi.toggle_wifi(False)
wifi.toggle_hotspot(True)

LED.value(ON)

gc.collect()