Skip to content

Instantly share code, notes, and snippets.

Created September 24, 2017 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/a6151fb6e83c595de8fe1812284ed382 to your computer and use it in GitHub Desktop.
Save anonymous/a6151fb6e83c595de8fe1812284ed382 to your computer and use it in GitHub Desktop.
import picoweb
from time import sleep
from machine import Pin
from dht import DHT22
import network
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected():
print('connecting to network...')
sta_if.active(True)
sta_if.connect('yourssidname', 'ssidpassword')
while not sta_if.isconnected():
pass
print('network config:', sta_if.ifconfig())
ipadd=sta_if.ifconfig()
app = picoweb.WebApp(__name__)
hw_sensor=DHT22(Pin(13,Pin.IN,Pin.PULL_UP))
@app.route("/temp")
def html(req, resp):
hw_sensor.measure()
t = hw_sensor.temperature()
h = hw_sensor.humidity()
sensor={"tmpr":t,"hmdty":h}
msg = (b'{0:3.1f} {1:3.1f}'.format(t,h))
print(msg)
yield from picoweb.start_response(resp, content_type = "text/html")
yield from app.render_template(resp, "sensor.tpl", (sensor,))
app.run(debug=True, host =ipadd[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment