-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendenergy.py
61 lines (49 loc) · 1.87 KB
/
sendenergy.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
53
54
55
56
57
58
59
60
61
import serial, sys, time
import httplib
# Domain you want to post to: localhost would be an emoncms installation on your own laptop
# this could be changed to emoncms.org to post to emoncms.org
domain = "emoncms.org"
# Location of emoncms in your server, the standard setup is to place it in a folder called emoncms
# To post to emoncms.org change this to blank: ""
emoncmspath = ""
# Write apikey of emoncms account
apikey = "b742b99d9880b27ff50ce73b17c2e224"
# Node id youd like the emontx to appear as
nodeid = 1
# Connection to web
conn = httplib.HTTPConnection(domain)
#Enable dac output
out0en = open('/sys/class/hwmon/hwmon0/device/out0_enable', 'w')
out0en.write(str(1))
out0en.close
#Loop forever
while 1:
# Turn on led
out0 = open('/sys/class/hwmon/hwmon0/device/out0_output', 'w')
out0.write(str(255))
out0.close
# Read analog values and format into csv
in0 = open('/sys/class/hwmon/hwmon0/device/in0_input', 'r')
in0val = in0.read()
in0.close()
in1 = open('/sys/class/hwmon/hwmon0/device/in1_input', 'r')
in1val = in1.read()
in1.close()
in2 = open('/sys/class/hwmon/hwmon0/device/in2_input', 'r')
in2val = in2.read()
in2.close()
in3 = open('/sys/class/hwmon/hwmon0/device/in3_input', 'r')
in3val = in3.read()
in3.close()
csv = in0val.rstrip() + "," + in1val.rstrip() + "," + in2val.rstrip() + "," + in3val.rstrip()
print csv
# Send to emoncms
conn.request("GET", "/"+emoncmspath+"/input/post.json?apikey="+apikey+"&node="+str(nodeid)+"&csv="+csv)
response = conn.getresponse()
print response.read()
conn.close()
# Turn off led and wait for next reading
out0 = open('/sys/class/hwmon/hwmon0/device/out0_output', 'w')
out0.write(str(0))
out0.close
time.sleep(5)