Skip to content

Commit 418141a

Browse files
authored
Support for Lat/Lon/Elevation Data (#48)
* modified model for location feeds * added send_location_data method to API client wrapper * fix send_location_data arg order, update example
1 parent f056b83 commit 418141a

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

Adafruit_IO/client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ def append(self, feed, value):
130130
"""
131131
return self.create_data(feed, Data(value=value))
132132

133+
def send_location_data(self, feed, value, lat, lon, ele):
134+
"""Sends locational data to a feed
135+
136+
args:
137+
- lat: latitude
138+
- lon: logitude
139+
- ele: elevation
140+
- (optional) value: value to send to the feed
141+
"""
142+
return self.create_data(feed, Data(value = value,lat=lat, lon=lon, ele=ele))
143+
133144
def receive(self, feed):
134145
"""Retrieve the most recent value for the specified feed. Feed can be a
135146
feed ID, feed key, or feed name. Returns a Data instance whose value

Adafruit_IO/model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
'feed_id',
3737
'expiration',
3838
'position',
39-
'id' ]
39+
'id',
40+
'lat',
41+
'lon',
42+
'ele']
4043

4144
FEED_FIELDS = [ 'name',
4245
'key',

examples/api/location.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
'location.py'
3+
==================================
4+
Example of sending location over an
5+
Adafruit IO feed to a Map Dashboard
6+
block
7+
8+
Author(s): Brent Rubell
9+
"""
10+
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 = 'YOUR_AIO_USERNAME'
16+
ADAFRUIT_IO_KEY = 'YOUR_AIO_KEY'
17+
18+
# Create an instance of the REST client.
19+
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
20+
21+
# Create a location feed
22+
try:
23+
location = aio.feeds('location')
24+
except RequestError:
25+
feed = Feed(name="location")
26+
location = aio.create_feed(feed)
27+
28+
29+
# Top Secret Adafruit HQ Location
30+
value = 1
31+
lat = 40.726190
32+
lon = -74.005334
33+
ele = 6 # elevation above sea level (meters)
34+
35+
# Send location data to Adafruit IO
36+
aio.send_location_data(location.key, value, lat, lon, ele)

0 commit comments

Comments
 (0)