I wrote a little code in python to read the live current from OpenEVSE Via RAPI then upload the data to the Open Energy Monitor website
http://emoncms.org" onclick="window.open(this.href);return false;.
Here is my live dashboard with input from OpenEVSE and Open Energy Monitor:
http://emoncms.org/chris1howell/" onclick="window.open(this.href);return false;
The code runs great on a OpenWRT router, Raspberry pi or any other device that supports Python
Basic steps...
Setup account at emoncms.org
copy write API key
edit python code to insert your read/write API key
setup OpenWRT router on network
connect router to OpenEVSE with a serial TTL cable
setup python
opkg update
opkg install python
opkg install pyserial
upload python file to router via ftp or http
ensure OpenEVSE has firmware with RAPI enabled
run python file
set up a dashboard on emoncms.org
Every 10 seconds the current will be read and sent. This is the expected output:
Send RAPI>>$GG*B2
OpenEVSE>>$OK 16
POST OpenEVSE current to emoncms.org
Recieved HTTP Response
Here is the source code. Note the API Key below has been modified, please do not forget to insert your key.
Code: Select all
#OpenEVSE RAPI current in Python
import time, httplib, urllib, serial
done = False
amp_ct = 0
# Setup for Serial Port
comm = serial.Serial()
comm.port='/dev/ttyUSB0'
comm.baudrate=115200
comm.open()
# Setup for Open Energy Monitor Emoncms.org
host = 'www.emoncms.org'
url_post = '/input/post.json?'
apikey = '&apikey=07abcd292c15e5222e4a4075b95e12345'
values = urllib.urlencode({'value' : '1234',}) headers = {
'User-Agent': 'python',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'text/plain',
}
conn = httplib.HTTPConnection(host)
while not done:
#read current from OpenEVSE and Post
comm.write("$GG*B2\r")
print (" ")
print ("Send RAPI>>$GG*B2")
time.sleep(1)
out = ''
while comm.inWaiting() > 0:
out += comm.read(1)
if out != '':
print "OpenEVSE>>" + out
if out != "$NK":
amp_ct = out.replace("$OK ", "")
input_amp = 'json={OpenEVSE:' + amp_ct + '}'
url_amp_ct = url_post + input_amp + apikey
conn.request("POST", url_amp_ct, values, headers)
response = conn.getresponse()
print "POST OpenEVSE current to emoncms.org"
if response != '':
print "Recieved HTTP Response"
else:
print "Serial Error: No response"
if out == "$NK":
print "OpenEVSE>> Error"
time.sleep(9)