def locate(positions):
    """locates an item on the shelf"""
    if "." in positions:
        positions, row = positions.split(".")
    else:
        row = 1
    if ":" in positions:
        start, end = positions.split(":")
    else:
        start = end = positions
    start, end, row = int(start), int(end), int(row)
    light.locate(start, end, row)
    print("holding lights for a while.")
    time.sleep(config.lights["hold_time"])
    light.clear()
    print("clearing lights")
def process_message(topic, message):
    """Processes message"""
    # TODO: convert the topic and message before using them.
    print((topic, message))
    topic = topic.decode()
    message = json.loads(message.decode())
    topic_type = _type(topic)
    if topic_type == "shelf":
        locate(**message)
    elif topic_type == "alert":
        alert(**message)
    elif topic_type == "highlight":
        n = message.get("n", 10)
        light.show_nth_leds(n)
    elif topic_type == "clear":
        light.clear()
        light.clear()
Beispiel #3
0
def exec_req(adr, param_dict):
    """Function to execute the request"""
    print("URL:", adr, param_dict)
    if adr[1] == 'locate':
        light.locate(param_dict["locate"])
        time.sleep(10)
        light.clear()
        return {'success': 'True'}
    elif adr[1] == "blink":
        if param_dict.get("color") is not None:
            light.blink(param_dict["color"])
        else:
            light.blink()
        return {
            'success': 'True',
            "message": "Blinked {}".format(param_dict.get("color"))
        }
    elif adr[1] == "clear":
        light.clear()
        return {'success': 'True'}
    elif adr[1] == "show_progress":
        light.show_progress(param_dict["value"])
        return {'success': 'True'}
    elif adr[1] == "toggle":
        if param_dict.get("color") is not None:
            light.change_state(param_dict["color"])
        else:
            light.change_state()
    elif adr[1] == "snake":
        if param_dict.get("reverse") is not None:
            light.snake(reverse=param_dict.get("reverse"))
        else:
            light.snake()
    elif adr[1] == "":
        return """<html>
        <head>
            <title>Strip A</title>
        </head>
        <body>
            <b>Strip</b>
            <p><a href="/toggle">Click here to toggle</a></p>
        </body>
        </html>"""

    return {"Status": "No Action"}
"""Boot file. Runs at boot (including wake-boot from deepsleep)"""

import gc
import webrepl
# Remember to set the password initially.
# this uses webrepl_cfg.py
# and reads the PASS variable.j
webrepl.start()
import ujson as json
print("preparing imports")
import utils
import light

if __name__ == "__main__":
    print("Preparing to boot.")
    utils.setup_network()
    light.clear()
    gc.collect()
    print("boot complete.")
Beispiel #5
0
#esp.osdebug(None)
import gc, webrepl, network

webrepl.start()
import ujson as json
import light

sta_if = network.WLAN(network.STA_IF)
if not sta_if.active():
    sta_if.active(True)

available_networks = sta_if.scan()

with open("networks.json", "r") as f:
    network_data = json.load(f)

# Disable access point.
ap_if = network.WLAN(network.AP_IF)
if ap_if.active():
    ap_if.active(True)

for network in available_networks:
    network_name = network[0].decode()
    if network_name in network_data.keys():
        sta_if.connect(network_name, network_data[network_name])
        break

light.clear()
light.clear()  # added it a second time to just flush out remnants.
gc.collect()