Last active
May 6, 2024 14:07
-
-
Save Pierry/96287a03bce023fcffbdc76e18f944cd to your computer and use it in GitHub Desktop.
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 dht | |
import machine | |
import time | |
import urequests | |
from wifilib import conecta | |
d = dht.DHT11(machine.Pin(4)) | |
rele = machine.Pin(2, machine.Pin.OUT) | |
while True: | |
d.measure() | |
temp = d.temperature() | |
hum = d.humidity() | |
print('Temperatura:', temp, 'C') | |
print('Umidade:', hum, '%') | |
station = conecta("java", "sanborges43") | |
if not station.isconnected(): | |
print("Não conectado!") | |
else: | |
print("Conectado!") | |
url = f"https://api.thingspeak.com/update?api_key=RSPOB7HXKJJQI0WU&field1={temp}&field2={hum}" | |
response = urequests.get(url) | |
print("Resposta:", response.text) | |
if (temp > 31 or hum > 70): | |
rele.value(1) | |
else: | |
rele.value(0) | |
time.sleep(60) |
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
def conecta(ssid, senha): | |
import network | |
import time | |
station = network.WLAN(network.STA_IF) | |
station.active(True) | |
station.connect(ssid, senha) | |
for t in range(50): | |
if station.isconnected(): | |
break | |
time.sleep(0.1) | |
return station |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment