Skip to content

Instantly share code, notes, and snippets.

@eydam-prototyping
Last active February 16, 2021 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eydam-prototyping/54030827a86769f7884c7b8a43806fd7 to your computer and use it in GitHub Desktop.
Save eydam-prototyping/54030827a86769f7884c7b8a43806fd7 to your computer and use it in GitHub Desktop.
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