Display PVoutput.org statistical solar PV data on Cisco 79xx IP phones idle screen
This project requires you to have already an account at PVoutput.org and your inverter or data collection device is uploading data or data get’s pulled from the inverter to PVoutput. There are many ways to upload data from your solar system, see here for details. For our Samil inverter we are using this Python3 script from Maarten Visscher.
In this article I describe only how to download the statistic portlet data from PVoutput.org using a PHP script, generating a PNG idle background image and configure a Cisco 7941 / 7942(G) / 7945 / 7961 / 7962(G) / 7965 / 7970 / 7971 / 7972 / 7975(G) and possibly other phones of the 79xx series. It may also work on the 7940/7960 but this possibly requires some changes because this phones needs GIF2XML converted files. Some details here.
The phones we are using are 7941G and 7961G with SIP firmware. If you are on SIP, probably using Asterisk or another SIP PBX like the Fritzbox, you are maybe already familiar with the configuration using XML files on your TFTP server. Phones with SCCP firmware on Cisco Callmanager can also be configured, but this means admin access to the Callmanager, because the idle URL configuartion can only be done at the server side. Details on Cisco SCCP idle URL config you may find here.
First of all lets assume the server parameters:
Web Server IP address: 192.168.100.20 (FQDN may be used as well)
Web Server html folder: /cisco/idle
Create an idle.php file like below and upload it to the /cisco/idle folder on your webserver.
<?php Header("Content-type: text/xml"); Header("Refresh: 900"); ?> <CiscoIPPhoneImageFile> <URL>http://192.168.100.20/cisco/idle/createpng.php</URL> </CiscoIPPhoneImageFile>
Create the createpng.php and place it to the web folder as well:
<?php /*Copyright (C) 2016 CCTECH Inc. This program is free software: you can redistribute it and/or modify, it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You can retrieve a copy of the GNU General Public License at <http://www.gnu.org/licenses>*/ // Set png size for cisco phone idle background (125x60 for 79x0 series) $width = 295; $height = 140; // Set PVoutput.org portlet URL // Replace XXXXX with your own SID here $url = "https://pvoutput.org/portlet/r1/getstatus.jsp?sid=XXXXX"; function curl_download($Url){ // check if cURL is installed? if (!function_exists('curl_init')){ die('Sorry cURL is not installed!'); } // create a new cURL resource handle $ch = curl_init(); // Set download URL curl_setopt($ch, CURLOPT_URL, $Url); // Set a referer for PVoutput.org, enter this URL at your PVoutput API profile curl_setopt($ch, CURLOPT_REFERER, "http://FQDN/cisco/idle/createpng.php"); // User agent (we simulate a Linux Firefox here) curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux i586; rv:49.0) Gecko/20100101 Firefox/49.0"); // Include header in result? (0 = yes, 1 = no) curl_setopt($ch, CURLOPT_HEADER, 0); // Should cURL return or print out the data? (true = return, false = print) curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Timeout in seconds curl_setopt($ch, CURLOPT_TIMEOUT, 15); // Download the given URL, and return output $output = curl_exec($ch); // Close the cURL resource, and free system resources curl_close($ch); return $output; } // download the data from PVoutput.org $lines = curl_download($url); // format the result string, remove HTML tags and insert line breaks $common_words = array("document.write", "('", "');('", "');" ); $output = str_replace($common_words, "", $lines); $output = strip_tags($output); $output = str_replace("Energy", "\nEnergy", $output); $output = str_replace("Efficiency", "\nEfficiency", $output); $output = str_replace("Power", "\nPower", $output); $output = str_replace("Temperature", "\nTemperature", $output); $output = str_replace("V", "V\n", $output); $output = str_replace("V\noltage", "\nVoltage ", $output); $arrText=explode("\n",wordwrap($output,30,"\n")); // creates the foreground image $im = @imagecreate($width, $height); //sets image background color $bgcolor = imagecolorallocate($im, 255, 255, 255); $y=5; //vertical position of text // Set transparent background color imagecolortransparent($im, $bgcolor); // format string and remove unwanted chars foreach($arrText as $arr) { $textcolor=imagecolorallocate($im,0,0,0); //sets text color imagestring($im,5,15,$y,trim($arr),$textcolor); $y=$y+15; } // read background image (optional, enable the following two commands if you want a background image) // Background image should reside in the same folder than this php file, 295x140 in size, Index Color Mode // $bg = imagecreatefrompng('background.png'); // imagecopymerge($bg, $im, 0, 0, 0, 0, 295, 140, 100); // Image output header("Content-type: image/png"); imagepng($im); // change to imagepng($bg); in case of background image imagedestroy($im); // change to imagedestroy($bg); in case of background image ?>
If you’d like to use a background image layered behind the status information, like in the sample screenshot on top, change the code lines to this:
// read background image (optional, enable the following two commands if you want a background image) // Background image should reside in the same folder than this php file, 295x140 in size, Index Color Mode $bg = imagecreatefrompng('background.png'); imagecopymerge($bg, $im, 0, 0, 0, 0, 295, 140, 100); // Image output header("Content-type: image/png"); imagepng($bg); imagedestroy($bg); ?>
The background image should be a PNG file, 295x140px in size and saved as 8-Bit Index Color Mode!
Configuring the Cisco 79xx idle setting
The Cisco IP Phones are requesting XML files and the idle URL should be set like this:
http://192.168.100.20/cisco/idle/idle.php
The idle.php generates an XML output for the phone to retreive the idle background image.
Open your SEP00260B5ABCDEF.cnf.xml phone config template on your TFTP server and edit the following:
Note: The filename for the above config file contains your phones MAC address, so this is only an example.
<idleTimeout>360</idleTimeout> <idleURL>http://192.168.100.20/cisco/idle/idle.php</idleURL>
idleTimeout sets the phones screensaver timeout in seconds.
After the set timeout the phone will retreive the image from your webserver and displays your solar statistics. The refresh timer to determine how often the image should reload, can be set in the idle.php at “Refresh: 900”.
Be reminded that every refresh calls the portlet at PVoutput.org.
—
Additional configuration options:
1. You can also integrate the XML call in your services menue, for example the open79xx xml database services are supporting Link Objects, just create an object type link and point it to “http://SERVERIP-OR-FQDN/cisco/idle/idle.php”.
2. Also a nice solution is the usually unused (?) button at the phone. Just add this code to your SEP00…cnf.xml
<informationURL> http://192.168.100.20/cisco/idle/idle.php </informationURL>
Recent Comments