Plugwise Smile P1 – Digitale meter (gauge)
Dit Javascript haalt via het PHP CORS script de modules XML binnen en leest de waarde “huidig verbruik” uit, en geeft dit weer als “vermogens teller (gauge)”
Ik heb hier de code van ricdijk aangepast dat een gaugescript gemaakt heeft voor de Youless pulsmeter, zie de website hier.
Let op: de website wordt om een X aantal seconden ververst, zodoende worden de gegevens van de smile elke keer opnieuw uitgelezen.
Firmware 2.x.x
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
<!--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // This is a modified version of the original source: Gauge meter for Youless - by ricdijk // This version is supporting the Plugwise Smile (tested on firmware v1.1.9) // // parameters: // w - width of gauge(default 330) // h - height of gauge(default 330) // i - interval to poll Youless (seconds, default 5) // smileip = IP adress of the Plugwise smile // // designed to run as gadget in iframe, eg: // '<iframe scrolling=no align=center frameborder=0 src="Youless.html?h=110&w=110&i=10" height=120 width=148></iframe>' // // Needs the page 'download.php' to connect to Plugwise Smile (because of Cross-Origin Resource Sharing (CORS)) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////--> <head> <script type='text/javascript' src='https://www.google.com/jsapi'></script> <script type='text/javascript' src='jquery.js'></script> <script type=text/javascript> // Variabele voor het IP van de Plugwise Smile (zelf aanpassen) var smileip = '192.168.0.131'; var i = 10; // ververs de gegevens na X seconden var fileurl = 'http://' + smileip + '/core/modules'; var filename = 'modules.xml'; google.load('visualization', '1', {packages:['gauge']}); var richdGauge; var gaugeData; var gaugeOptions; var mEAV; function richdGup( name ) { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results == null ) return ""; else return results[1]; } function richdInit() { gaugeData = new google.visualization.DataTable(); gaugeData.addColumn('string', 'Label'); gaugeData.addColumn('number', 'Value'); gaugeData.addRows([ ['Smile', 0] ]); var w=richdGup('w'); if (w=="") w=330; var h=richdGup('h'); if (h=="") h=330; gaugeOptions = { width: w, height: h, redFrom: 5000, redTo: 10000, yellowFrom: 3000, yellowTo: 5000, greenFrom: 0, greenTo:500, minorTicks: 10, max: 10000, majorTicks: ['0', , , , , '10000'], animation:{ duration: 2500, easing: 'inAndOut'} }; richdGauge=new google.visualization.Gauge(document.getElementById('richdDisplay')); richdGauge.draw(gaugeData, gaugeOptions); } function richdChange(v) { gaugeData.setValue(0, 1, v); richdGauge.draw(gaugeData, gaugeOptions); } function richdRefresh() { //Voer het bestand 'download.php' uit en wacht totdat het klaar is met downloaden (jQuery/Ajax). $.ajax({ async: false, type: 'GET', url: 'download.php?url=' + fileurl + '&filename='+ filename, success: function(data) {} }); xmlDoc=loadXMLDoc("modules.xml"); mEAV = xmlDoc.getElementsByTagName("measurement")[9].childNodes[0].nodeValue; richdChange(mEAV); var i=richdGup('i'); if (i=="") i=5000; else i*=1000; setTimeout("richdRefresh();", i); } function richd_init() { richdInit(); richdRefresh(); } function loadXMLDoc(filename) { if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else // code for IE5 and IE6 { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",filename,false); xhttp.send(); return xhttp.responseXML; } </script> </head> <body onload=richd_init();> <div style="display: none" id="richdHidden"></div> <div id="richdDisplay"></div> </body> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php // Info : Script voor het downloaden van bestanden voor Java (CORS policy) // Door : Sebastiaan Ebeltjes (Phoenix Interactive) // Versie: v2.0.0.0 (Smile v2.x.x) // Datum : 2015-07-10 $SmileId = "abcdefgh"; // De 8 letters van de Smile ID. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $_GET['url']); curl_setopt($ch, CURLOPT_USERPWD, "smile:" . $SmileId); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $data = curl_exec($ch); curl_close($ch); file_put_contents($_GET['filename'], $data); ?> |
Firmware 1.x.x
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
<!--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // This is a modified version of the original source: Gauge meter for Youless - by ricdijk // This version is supporting the Plugwise Smile (tested on firmware v1.1.9) // // parameters: // w - width of gauge(default 330) // h - height of gauge(default 330) // i - interval to poll Youless (seconds, default 5) // smileip = IP adress of the Plugwise smile // // designed to run as gadget in iframe, eg: // '<iframe scrolling=no align=center frameborder=0 src="Youless.html?h=110&w=110&i=10" height=120 width=148></iframe>' // // Needs the page 'download.php' to connect to Plugwise Smile (because of Cross-Origin Resource Sharing (CORS)) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////--> <head> <script type='text/javascript' src='https://www.google.com/jsapi'></script> <script type='text/javascript' src='jquery.js'></script> <script type=text/javascript> // Variabele voor het IP van de Plugwise Smile (zelf aanpassen) var smileip = '192.168.1.101'; var i = 10; // ververs de gegevens na X seconden var fileurl = 'http://' + smileip + '/smartmeter/modules'; var filename = 'modules.xml'; google.load('visualization', '1', {packages:['gauge']}); var richdGauge; var gaugeData; var gaugeOptions; var mEAV; function richdGup( name ) { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results == null ) return ""; else return results[1]; } function richdInit() { gaugeData = new google.visualization.DataTable(); gaugeData.addColumn('string', 'Label'); gaugeData.addColumn('number', 'Value'); gaugeData.addRows([ ['Smile', 0] ]); var w=richdGup('w'); if (w=="") w=330; var h=richdGup('h'); if (h=="") h=330; gaugeOptions = { width: w, height: h, redFrom: 5000, redTo: 10000, yellowFrom: 3000, yellowTo: 5000, greenFrom: 0, greenTo:500, minorTicks: 10, max: 10000, majorTicks: ['0', , , , , '10000'], animation:{ duration: 2500, easing: 'inAndOut'} }; richdGauge=new google.visualization.Gauge(document.getElementById('richdDisplay')); richdGauge.draw(gaugeData, gaugeOptions); } function richdChange(v) { gaugeData.setValue(0, 1, v); richdGauge.draw(gaugeData, gaugeOptions); } function richdRefresh() { //Voer het bestand 'download.php' uit en wacht totdat het klaar is met downloaden (jQuery/Ajax). $.ajax({ async: false, type: 'GET', url: 'download.php?url=' + fileurl + '&filename='+ filename, success: function(data) {} }); //Lees het XML bestand 'modules.xml' in, en zoek naar de gegevens (jQuery/Ajax). $.ajax({ type: "GET", url: "modules.xml", dataType: "xml", success: function(xml) { $(xml).find('point_log').each(function(){ var type = $(this).find('type').text(); if(type == 'electricity_consumed') { mEAV = Number($(this).find('measurement').text()); } }); } }); richdChange(mEAV); var i=richdGup('i'); if (i=="") i=5000; else i*=1000; setTimeout("richdRefresh();", i); } function richd_init() { richdInit(); richdRefresh(); } </script> </head> <body onload=richd_init();> <div style="display: none" id="richdHidden"></div> <div id="richdDisplay"></div> </body> |
1 2 3 4 5 6 7 |
<?php // Info : Script voor het downloaden van bestanden voor Java (CORS policy) // Door : Sebastiaan Ebeltjes (Phoenix Interactive) // Versie: v1.0.0.0 // Datum : 2013-03-04 file_put_contents($_GET['filename'], file_get_contents($_GET['url'])); ?> |
[#/plugwise/smilep1/script_gauge” ]