Skip to content

Instantly share code, notes, and snippets.

@stephenlb
Forked from domadev812/1
Created November 15, 2017 21:05
Show Gist options
  • Select an option

  • Save stephenlb/421b1ed385b8afe87abc53c8867a3e64 to your computer and use it in GitHub Desktop.

Select an option

Save stephenlb/421b1ed385b8afe87abc53c8867a3e64 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