Created
April 17, 2015 18:19
-
-
Save alexanderhiam/82e552cd065200c760da to your computer and use it in GitHub Desktop.
Using PyBBIO to post weather data to ThingSpeak.com
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 requests | |
from bbio import * | |
from bbio.libraries.BMP183 import BMP183 | |
from bbio.libraries.HTU21D import HTU21D | |
bmp = BMP183(SPI0) | |
htu = HTU21D(I2C2) | |
API_KEY = "0000000000000000" # Put your API key here | |
def postData(*data): | |
url = "https://api.thingspeak.com/update" | |
params = {'api_key' : API_KEY} | |
for i in range(0, len(data)): | |
params['field%i' % (i+1)] = data[i] | |
print params | |
response = requests.post(url, params=params) | |
print response | |
def setup(): | |
pass | |
def loop(): | |
pressure = bmp.getPressure() / 1000.0 # in kPa | |
rh = htu.getHumidity() | |
temp = htu.getTemp() | |
dew_point = htu.calculateDewPoint(rh, temp) | |
postData(temp, rh, pressure, dew_point) | |
delay(30000) | |
run(setup, loop) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment