Skip to content

Instantly share code, notes, and snippets.

@domadev812
Forked from ToeJamson/1
Last active November 15, 2017 21:05
Show Gist options
  • Save domadev812/d915fa10153d9d75ada3686e88d0ae4b to your computer and use it in GitHub Desktop.
Save domadev812/d915fa10153d9d75ada3686e88d0ae4b to your computer and use it in GitHub Desktop.
Tutorial: Building a Raspberry Pi Smart Home (Part 1)
h,t = dht.read_retry(dht.DHT22, 4)
print 'Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(t, h)
import os
import time
import sys
import Adafruit_DHT as dht
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
pnconfig = PNConfiguration()
pnconfig.subscribe_key = 'demo'
pnconfig.publish_key = 'demo'
pubnub = PubNub(pnconfig)
channel = 'pi-house'
temp='{0:0.1f}'.format(t)
hum='{0:0.1f}'.format(h)
message = {'temperature': temp, 'humidity': hum}
pubnub.publish().channel(channel).message(message).async(my_publish_callback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment