-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
174 lines (130 loc) · 6.71 KB
/
index.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<html lang="en"><head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Raspberry Pi</title>
<!-- Bootstrap core CSS -->
<link href="bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="blog.css" rel="stylesheet">
<style type="text/css"></style><style id="holderjs-style" type="text/css"></style></head>
<body style="">
<div class="container">
<div class="blog-header">
<h1 class="blog-title">Making the Raspberry Pi talk PubNub's language</h1>
<p class="lead blog-description"><a href = "/Users/bhavana/Desktop/bootstrap/cover.html">IoT-PubNub-Embedded Devices </a></p>
</div>
<div class="row">
<div class="col-sm-8 blog-main">
<div class="blog-post">
<p class="blog-post-meta">June 7, 2014 by <a href="#">Bhavana</a></p>
<p>With all the buzz surrounding IoT, its only natural for us at PubNub to dive right into it.
With over two hundred million connected devices connected to our global realtime network in fourteen data centers,
we average 50 to 60 thousands transactions per second, peaking at over 3 million. PubNub has its foot in the automative
industry, home automation and IoT wearables.</p>
<hr>
<p>The <a href = "http://www.raspberrypi.org">Raspberry Pi</a>, is a fully functional mini-computer, and is a cheap
solution for harnessing the Internet of Things. It include plenty of inputs and outputs for sensory add-ons
to test light, temperature, humidity and more.
</p>
<p> This post walks you through the steps of connecting a Raspberry Pi to the PubNub network. This way you can now connect
with
a million other devices on this global network and start sending or receiving information to and from the Pi.
<hr>
PubNub provides
extensive documentation and support for the Raspberry Pi <a href = "http://www.pubnub.com/documentation/">here </a>. Once
you are up and running with the Pi, feel free to choose your favorite language and start connecting. I have used
<a href = "https://github.com/pubnub/python"> Python </a> for this project.
</p> <br>
<h2>Basics of Connecting the Raspberry Pi to PubNub</h2>
<p>Follow these steps to get connected. </p>
<br>
<p> <strong> STEP 1: </strong> Connect the Pi to a monitor, keyboard, mouse and ethernet cable. Check out their website at
<a href = "http://www.raspberrypi.org"> Raspberry Pi </a> to set up your Pi. Login in to
the Raspberry Pi OS and open IDLE, the python IDE.
<br></br>
<p> <strong> STEP 2: </strong> Open a new window and paste the following code.
<pre><code>from Pubnub import Pubnub
from IoT_wrapper import iotwrapper
pi = iotwrapper(publish_key = 'demo',
subscribe_key = 'demo',
uuid = 'PI')
channel = 'iotchannel'
message = "hello from pi"
pi.send(channel, message)
pi.connect(channel)</code></pre>
<blockquote>
<p> The above code lets you set up the following :
<ul>
<li> publish key using "publish_key" </li>
<li> subscribe key using "subscribe_key" </li>
<li> UUID using "uuid" </li>
<li> channel you wish to subscribe and publish to using "channel"</li>
<li> message that you want to send. This is a JSON message. </li>
</ul>
</p>
</blockquote>
<p> We create an instance of the iotwrapper called pi and we can use the SEND and CONNECT methods belonging to that
class.
<br></br>
<strong>SEND: </strong>This invokes the publish() API to send any message over a desired
channel.</p>
<p><pre><code>def send(self, channel, message):
self.pubnub.publish({
'channel' : channel,
'message' : message})</code></pre></p>
<br></br>
<p><strong>CONNECT:</strong> This invokes the subscribe() API to listen for messages from other embedded devices
connected to the same channel.
the call back function receive is invoked when subscribe runs.
</p>
<pre><code>def connect(self, channel):
self.pubnub.subscribe({
'channel' : channel,
'callback' : self.receive})
def receive(self,message):
print(message)</code></pre>
<br>
<p> You can customize the channels you publish/subscribe to, the UUID you assume and also the messages you
send by just changing the above fields.
<br></br>
<p> <strong> huzzzaaaaah! </strong>
Thats it! You can now talk Raspberry Pi to any other device or application subscribing/publishing to the same channel.
</p>
</div><!-- /.blog-post -->
</div><!-- /.blog-main -->
<div class="col-sm-3 col-sm-offset-1 blog-sidebar">
<div class="sidebar-module sidebar-module-inset">
<h3>PubNub</h3>
<p>The PubNub Realtime Network powers thousands of apps, streaming more than 3 million messages a second to over
200 million devices a month.
<p><a class="btn btn-default" href="http://www.pubnub.com" role="button">View details »</a></p></p>
</div>
<div class="sidebar-module">
<h3>Related Blog Posts</h3>
<ul>
<li>IoT Arduino board connected to the Dashboard</li>
</ul>
</div>
<div class="sidebar-module">
<h4>Elsewhere</h4>
<ol class="list-unstyled">
<li><a href="https://github.com/banasrini/PiToPubNub">GitHub</a></li>
<li><a href="https://twitter.com/PubNub">Twitter</a></li>
</ol>
</div>
</div><!-- /.blog-sidebar -->
</div><!-- /.row -->
</div><!-- /.container -->
<div class="blog-footer">
<p>
<a href="#">Back to top</a>
</p>
</div>
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="bootstrap.min.js"></script>
</body></html>