# Import the microdot web server library from microdot import Microdot, Response from dht import DHT11 from machine import Pin # We also need network access so clients can connect to our web page... import network # Make sure we're connected to the network wlan = network.WLAN(network.STA_IF) if not wlan.isconnected(): print("Network isn't connected!") # If we're not connected, quit. # A better solution might be to try connecting to WiFi instead of giving up from sys import exit exit() # Print out our IP address so we know where to point the web browser! ip_address = wlan.ifconfig()[0] print("Site will be accessible at http://{}".format(ip_address)) sensor = DHT11(Pin(23)) # Set up the microdot server app = Microdot() page = """

WELCOME TO MY KITCHEN

This is my kitchen, where everything is connected to the Internet. Click here for the weather """ # Main page @app.route('/') def index(request): return Response(body=page, headers={'Content-Type': 'text/html'}) # Weather page @app.route('/weather') def weather(request): sensor.measure() return "Sunny with a high of {}".format(sensor.temperature()) # Start the server running # port=80 will make it run on the default HTTP port like a normal web server # debug=True will make it print out useful information to the REPL app.run(port=80, debug=True)