-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpoint_heliostat.py
52 lines (36 loc) · 1.21 KB
/
point_heliostat.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
46
47
48
49
50
51
52
import sys, time, os, datetime
import heliostat, light2dac
import xively
import subprocess
import requests
# extract feed_id and api_key from environment variables
try:
FEED_ID = os.environ["FEED_ID"]
except:
FEED_ID = 276439635
try:
API_KEY = os.environ["API_KEY"]
except:
API_KEY=open('/home/pi/xively.api').read().strip()
DEBUG=True
# initialize Xively api client
api = xively.XivelyAPIClient(API_KEY)
# here is the Xively connection info
feed = api.feeds.get(FEED_ID)
h=heliostat.heliostat(4, 7, debug=DEBUG)
if h.alt>10:
l=light2dac.light2dac()
h()
l()
feed.datastreams = [
xively.Datastream(id='light_intensity', current_value=l.lux, at=datetime.datetime.utcnow()),
xively.Datastream(id='sun_altitude', current_value=round(h.alt,2), at=datetime.datetime.utcnow()),
xively.Datastream(id='sun_azimuth', current_value=round(h.az,2), at=datetime.datetime.utcnow()),
]
if DEBUG:
print 'Updating Xively feed with %d at %s UTC' % (l.lux,
datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'))
try:
feed.update()
except requests.HTTPError as e:
print "HTTPError({0}): {1}".format(e.errno, e.strerror)