Skip to content

Instantly share code, notes, and snippets.

@drisanateixeira
Created June 11, 2019 03:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drisanateixeira/acb3a0d940967bc4e64e2934247ff2c9 to your computer and use it in GitHub Desktop.
Save drisanateixeira/acb3a0d940967bc4e64e2934247ff2c9 to your computer and use it in GitHub Desktop.
Fase 3
import urllib3
import RPi.GPIO as gpio
import Adafruit_DHT as dht
import time as t
gpio.setmode(gpio.BOARD)
gpio.setup(32, gpio.OUT)
chave = 'TTN9Y84915G60MJY'
url ='https://api.thingspeak.com/update?api_key={}&field1={}&field2={}'
while True:
# Raspberry Pi e Sensor de Temperatura e Umidade DHT11
umid, temp = dht.read_retry(dht.DHT11, 4) # CONECATDO NA PORTA 4
urllib3.PoolManager().request('GET', url.format(chave, temp, umid))
if temp > 31 or umid > 70:
gpio.output(32, 1) #Liga Rele
else:
gpio.output(32, 0) #Desliga Rele
#t.sleep(5) # Pausa de 5 segundos
print('Temperatura: {0:0.1f} Umidade: {1:0.1f}'.format(temp, umid)) # Imprimir a temperatura e umidade
t.sleep(5) # Pausa de 5 segundos
@douglasjam
Copy link

remova a chave do script publico, caso contrario outros poderao utiliza-la e atrapalhar seu DB, no seu caso n e critico, mas fica a dica para projetos futuros

@drisanateixeira
Copy link
Author

drisanateixeira commented Oct 8, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment