Last active
October 24, 2017 06:03
-
-
Save artem-smotrakov/b864a0ebadfff0e50ec227bc6fea5c47 to your computer and use it in GitHub Desktop.
Measuring temperature and humidity with DHT22 and MicroPython. See details on https://blog.gypsyengineer.com/fun/diy-electronics/micropython-esp8266-sending-data-to-thingspeak.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import dht | |
import machine | |
def mesure_temperature_and_humidity(): | |
d = dht.DHT22(machine.Pin(DHT22_PIN)) | |
d.measure() | |
t = d.temperature() | |
h = d.humidity() | |
print('temperature = %.2f' % t) | |
print('humidity = %.2f' % h) | |
while True: | |
current_time = time.time() | |
if current_time - last_mesurement_time > MESUREMENT_INTERVAL: | |
mesure_temperature_and_humidity() | |
last_mesurement_time = current_time | |
time.sleep(DELAY) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment