File tree 4 files changed +54
-4
lines changed
4 files changed +54
-4
lines changed Original file line number Diff line number Diff line change 1
- __version__ = "2.0.19 "
1
+ __version__ = "2.1 "
Original file line number Diff line number Diff line change @@ -167,10 +167,21 @@ def receive_weather(self, weather_id=None):
167
167
:param int id: optional ID for retrieving a specified weather record.
168
168
"""
169
169
if weather_id :
170
- weatherpath = "integrations/weather/{0}" .format (weather_id )
170
+ weather_path = "integrations/weather/{0}" .format (weather_id )
171
171
else :
172
- weatherpath = "integrations/weather"
173
- return self ._get (weatherpath )
172
+ weather_path = "integrations/weather"
173
+ return self ._get (weather_path )
174
+
175
+ def receive_random (self , id = None ):
176
+ """Access to Adafruit IO's Random Data
177
+ service.
178
+ :param int id: optional ID for retrieving a specified randomizer.
179
+ """
180
+ if id :
181
+ random_path = "integrations/words/{0}" .format (id )
182
+ else :
183
+ random_path = "integrations/words"
184
+ return self ._get (random_path )
174
185
175
186
def receive (self , feed ):
176
187
"""Retrieve the most recent value for the specified feed. Returns a Data
Original file line number Diff line number Diff line change @@ -205,6 +205,17 @@ def subscribe_group(self, group_id):
205
205
"""
206
206
self ._client .subscribe ('{0}/groups/{1}' .format (self ._username , group_id ))
207
207
208
+ def subscribe_randomizer (self , randomizer_id ):
209
+ """Subscribe to changes on a specified random data stream from
210
+ Adafruit IO's random data service.
211
+
212
+ MQTT random word subscriptions will publish data once per minute to
213
+ every client that is subscribed to the same topic.
214
+
215
+ :param int randomizer_id: ID of the random word record you want data for.
216
+ """
217
+ self ._client .subscribe ('{0}/integration/words/{1}' .format (self ._username , randomizer_id ))
218
+
208
219
def subscribe_weather (self , weather_id , forecast_type ):
209
220
"""Subscribe to Adafruit IO Weather
210
221
:param int weather_id: weather record you want data for
Original file line number Diff line number Diff line change
1
+ """
2
+ 'random_data.py'
3
+ ================================================
4
+ Example for accessing the Adafruit IO Random
5
+ Data Service.
6
+
7
+ Author(s): Brent Rubell for Adafruit Industries
8
+ """
9
+ # Import JSON for forecast parsing
10
+ import json
11
+ # Import Adafruit IO REST client.
12
+ from Adafruit_IO import Client , Feed , RequestError
13
+
14
+ # Set to your Adafruit IO key.
15
+ ADAFRUIT_IO_USERNAME = 'brubell'
16
+ ADAFRUIT_IO_KEY = '6ec4b31bd2c54a09be911e0c1909b7ab'
17
+
18
+ # Create an instance of the REST client.
19
+ aio = Client (ADAFRUIT_IO_USERNAME , ADAFRUIT_IO_KEY )
20
+
21
+ generator_id = 1461
22
+
23
+ # Get the specified randomizer record with its current value and related details.
24
+ random_data = aio .receive_random (generator_id )
25
+ # Parse the API response
26
+ data = json .dumps (random_data )
27
+ data = json .loads (data )
28
+ print ('Random Data: {0}' .format (data ['value' ]))
You can’t perform that action at this time.
0 commit comments