Skip to content

Instantly share code, notes, and snippets.

@eydam-prototyping

eydam-prototyping/main.py Secret

Last active Feb 16, 2021
Embed
What would you like to do?
main.py v4
import network
import time
import ep_logging
import ep_http
import ep_file_server
import ep_rest_server
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
# Set DHCP host name to recognize the device in your router
wlan.config(dhcp_hostname="Heater")
# Replace your SSID and password
wlan.connect("<SSID>", "<password>")
while not wlan.isconnected():
time.sleep(1)
logger = ep_logging.colored_logger(appname="main")
logger.notice("WiFi connected")
logger_http = ep_logging.colored_logger(appname="http")
fs = ep_file_server.file_server(
html_dir="/html/",
default_file="index.html",
logger=logger_http
)
crs_nw = ep_rest_server.config_rest_server(
config_file="./network_config.json",
logger=logger_http
)
routes = [
("^\/?rest/nw\/?([A-Za-z0-9_\.\/]*)\??([A-Za-z0-9_\.\/]*)$", lambda sock, req: crs_nw.serve(sock, req)),
("^(.*)$", lambda sock, req: fs.serve(sock, req)),
]
http_server = ep_http.http_server(routes=routes, micropython_optimize=True, logger=logger_http)
http_server.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment