Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import Adafruit_DHT
- import time
- import csv
- import sys
- csvfile = "temp.csv"
- als = True
- API_ENDPOINT = "://pastebin.com/api/api_post.php"
- API_KEY = "63d8b228fe6349b0fae90c609f42e95a"
- source_code = '''
- while als:
- humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, 21) # gpio pin 4 or pin number 7
- if humidity is not None and temperature is not None:
- humidity = round(humidity, 2)
- temperature = round(temperature, 2)
- print 'Temperature = {0:0.1f}*C Humidity = {1:0.1f}%'.format(temperature, humidity)
- else:
- print 'can not connect to the sensor!'
- timeC = time.strftime("%I")+':' +time.strftime("%M")+':'+time.strftime("%S")
- data = [temperature, timeC]
- with open(csvfile, "a")as output:
- writer = csv.writer(output, delimiter=",", lineterminator = '\n')
- writer.writerow(data)
- time.sleep(6) # update script every 60 seconds '''
- data = {'api_dev_key':API_KEY,
- 'api_option':'paste',
- 'api_paste_code':source_code,
- 'api_paste_format':'python'}
- r = requests.post(url = API_ENDPOINT, data = data)
- pastebin_url = r.text
- print("The pastebin URL is:%s"%pastebin_url)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement