Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <!--
- This script requires a PHP shim to make the Enphase API queries so the
- key is not exposed. To allow all the JSON queries to go out at the same
- time, the system ID is hard coded as well. Create a php script
- called ENPHASE_QUERY.PHP in the web hosting directory. The link for
- this file is in the "queryurl" variable in this script. The file PHP
- file contains the following:
- =======================================================================
- $key = ""; // enter API key here
- $systemid = 0; // enter system id number here
- $url = "https://api.enphaseenergy.com/api/systems";
- if ($_GET['func'] && $_GET['func']!="index")
- $url .= "/{$systemid}/{$_GET['func']}";
- $url .= "?key={$key}";
- $file = fopen($url, 'r');
- while ($file && !feof($file)) echo fread($file, 8192);
- fclose($file);
- =======================================================================
- You will need to bracket that in the php script delimeters. It's not
- included here since it could actually trigger the PHP parser if it is
- processing HTML files.
- The only parameters that need to be set in this file are the public url
- (puburl), and optionally the width and height.
- -->
- <head><style type="text/css">
- table {border-radius:10px;font: 18px "Lucida Grande",Lucida,Arial,Verdana;}
- td {color:#333333;border:none;}
- th {color:#333333;border:none;}
- a {color:#333333;text-decoration:none;}
- .tab {font-size:14px; background:#A0A0A0; padding:5px; border-radius: 10px 10px 0px 0px; cursor:pointer;}
- .seltab {font-size:14px; background:#E0E0E0; padding:5px; border-radius: 10px 10px 0px 0px; cursor:default;}
- .content {background:#E0E0E0; padding:5px; border-radius: 0px 0px 10px 10px;}
- .center {vertical-align: middle;text-align: center;}
- .grad {
- background-image: linear-gradient(bottom, #CCCCCC 75%, #AAAAAA 100%);
- background-image: -o-linear-gradient(bottom, #CCCCCC 75%, #AAAAAA 100%);
- background-image: -moz-linear-gradient(bottom, #CCCCCC 75%, #AAAAAA 100%);
- background-image: -webkit-linear-gradient(bottom, #CCCCCC 75%, #AAAAAA 100%);
- background-image: -ms-linear-gradient(bottom, #CCCCCC 75%, #AAAAAA 100%);
- background-image: -webkit-gradient( linear, left bottom, left top, color-stop(0.75, #CCCCCC), color-stop(1, #AAAAAA));
- }
- </style>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
- <script>
- var width = 320;
- var height = 240;
- var graphw = width - 40;
- var graphh = height / 2 - 60;
- var puburl = '#'; // enter public URL here
- var queryurl = "enphase_query.php?func=";
- function drawarray(canvas, data, max)
- {
- if (max == 0) max = 1;
- var cv=document.getElementById(canvas);
- var ctx=cv.getContext('2d');
- ctx.strokeStyle='#0063FF';
- for (x = 0 ; x < data.length ; x++) {
- ctx.moveTo(x * graphw / data.length, graphh );
- ctx.lineTo(x * graphw / data.length, graphh - graphh * data[x] / max - 1);
- }
- ctx.stroke();
- }
- function seltab(t) {
- for (x = 1 ; x <= 3 ; x++) {
- document.getElementById('tab'+x).className = (x==t)?'seltab':'tab';
- document.getElementById('content'+x).style.display = (x==t)?'block':'none';
- }
- }
- $(document).ready(function() {
- document.getElementById('puburl').href = puburl;
- document.getElementById('daygraph').width = graphw;
- document.getElementById('daygraph').height = graphh;
- document.getElementById('lifegraph').width = graphw;
- document.getElementById('lifegraph').height = graphh;
- $.getJSON(queryurl + 'index', function(data) {
- document.getElementById('sysname').innerHTML = data.systems[0].system_public_name;
- });
- $.getJSON(queryurl + 'alerts', function(data) {
- var level = 0;
- $.each(data.alerts, function(key, val) {
- if (val.level == 'medium' && level < 1) level = 1;
- if (val.level == 'high' && level < 2) level = 2;
- });
- var apng = document.getElementById('alertimg');
- if (level == 0) apng.src = "http://assets1.enphaseenergy.com/images/icons/normal_medium.png";
- else if (level == 1) apng.src = "http://assets1.enphaseenergy.com/images/icons/warning_medium.png";
- else if (level == 2) apng.src = "http://assets1.enphaseenergy.com/images/icons/error_medium.png";
- });
- $.getJSON(queryurl + 'summary', function(data) {
- var cp = document.getElementById('current_power');
- cp.innerHTML = data.current_power + 'W';
- var energy = data.energy_today / 1000.0;
- document.getElementById('energy_today').innerHTML = '' + energy.toFixed(1) + 'kWh';
- var energyl = data.energy_lifetime / 1000000.0;
- document.getElementById('energy_lifetime').innerHTML = '' + energyl.toFixed(1) + 'MWh';
- });
- $.getJSON(queryurl + 'power_today', function(data) {
- var peak = 0;
- $.each(data.production, function(key, val) {
- if (val > peak) peak = val;
- });
- drawarray('daygraph', data.production, peak);
- peak = peak / 1000.0;
- document.getElementById('peak_power').innerHTML = '' + peak.toFixed(2) + 'kW';
- });
- $.getJSON(queryurl + 'energy_lifetime', function(data) {
- var peak = 0;
- $.each(data.production, function(key, val) {
- if (val > peak) peak = val;
- });
- drawarray('lifegraph', data.production, peak);
- });
- });
- </script>
- </head><html><body>
- <table id='frametab' width=320 height=240 border=0 class='grad'>
- <script>
- document.getElementById('frametab').width = width;
- document.getElementById('frametab').height = height;
- </script>
- <tr><td style='padding:5px 5px 0px 5px;font-size:24px;'>
- <a id='puburl' target='_blank' href='#'><img style='border:none;' src='http://assets1.enphaseenergy.com/images/icons/site_medium.png'> <span id='sysname' style='font-weight:bold;'> </span> <img id='alertimg' style='vertical-align:bottom;float:right;border:none;' src=''></a></td></tr>
- <tr>
- <td style='padding:5px 5px 5px 5px; height:100%;'>
- <table border=0 style='border-spacing: 2px 0px;' width='100%' height='100%'>
- <tr>
- <th onClick='seltab(1);' id='tab1' class='seltab'>Current</th>
- <th onClick='seltab(2);' id='tab2' class='tab'>Today</th>
- <th onClick='seltab(3);' id='tab3' class='tab'>Lifetime</th>
- </tr>
- <tr><td class='content' colspan=3 style='height:100%'>
- <span id='content1' class='center' style='display:block;'>
- Power Production<br><br>
- <span id='current_power' style='color:#F85C16;font-size:36px;'></span><br><br>
- Today's Peak: <span id='peak_power'></span>
- </span>
- <span id='content2' class='center' style='display:none;'>
- Today's Energy<br>
- <span id='energy_today' style='color:#F85C16;font-size:36px;'></span><br>
- <canvas id='daygraph' width=1 height=1></canvas>
- </span>
- <span id='content3' class='center' style='display:none;'>
- Lifetime Energy<br>
- <span id='energy_lifetime' style='color:#F85C16;font-size:36px;'></span><br>
- <canvas id='lifegraph' width=1 height=1></canvas>
- </span>
- </td></tr>
- </table>
- </td></tr>
- <tr><td align='right' valign='center'><span style='font-size:10px'>POWERED BY </span><a href='http://enphase.com' target='_blank'><img src='http://enphase.com/wp-uploads/enphase.com/2011/06/EnphaseAPIMark.png' style='border:none;vertical-align:middle;'></a></td></tr>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement