-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpubnub-txt.py
45 lines (40 loc) · 1.12 KB
/
pubnub-txt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python2.7
import os
import sys
from pubnub import Pubnub
pubnub = Pubnub(publish_key='pub-c-xxxxxxxxxxxxxxxxxxxxxxxxxxxx3', subscribe_key='sub-c-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1')
channel = "Rcv-data"
def callback(m):
print m
def main():
while True:
os.system("clear")
print "1. Bulb on"
print "2. Bulb off"
print "3. Fan/Ac on"
print "4. Fan/Ac off"
print "5. Motor on"
print "6. Motor off"
choice=input("choice? : ")
if choice==1:
data={"bulb":1}
pubnub.publish(channel,data,callback=callback,error=callback)
elif choice==2:
data={"bulb":0}
pubnub.publish(channel,data,callback=callback,error=callback)
elif choice==3:
data={"fan":1}
pubnub.publish(channel,data,callback=callback,error=callback)
elif choice==4:
data={"fan":0}
pubnub.publish(channel,data,callback=callback,error=callback)
elif choice==5:
data={"motor":1}
pubnub.publish(channel,data,callback=callback,error=callback)
elif choice==6:
data={"motor":0}
pubnub.publish(channel,data,callback=callback,error=callback)
else:
print "\nInvalid Choice"
if __name__=="__main__":
main()