The Cultured Reef
Subject: Signature Generator XML intergration into Website
Prev Next
You are not authorized to post a reply.

Page 1 of 3123 > >>
AuthorMessages
slallen User is Offline
ReefChat Staff
Moray
Moray

Posts:301
Flower Mound, TX


06/29/2007 2:53 PM  

If you are using the XML output file from the Signature Generator on your site, please post a link here. Would like to build a list of examples of how it is being used. Also if you can give a brief description of how it is integrated that would be great. Maybe it will inspire others.

So let's see those sites!


real time stats
Click my stats for a graphed history.
Come Chat with Us!
LVReefer User is Offline
Copepod
Copepod

Posts:19


07/24/2007 9:29 AM  
Here is my humble little attempt; Reefspace Blog
I hope to someday create something like these, but my programming knowledge is very little.
Not sure how to take the xml feed and use it. Some pointers would be appreciated.

slallen User is Offline
ReefChat Staff
Moray
Moray

Posts:301
Flower Mound, TX


07/24/2007 3:21 PM  
You know what is funny about you using ReefSpace. A year ago I asked about doing the same kind of thing on our site here. Looks like Travis is all over the place these days. There are some tips in this thread. http://www.reefchat.org/Forums/tabid/264/forumid/9/tpage/1/view/topic/postid/933/Default.aspx#1083

Basically you will have to read each name/value pair into strings and use them as needed. I am working on a layout similar to CarlosReef as a demo. I think his is in php, perhaps he will stop back in and share some of his tips.

real time stats
Click my stats for a graphed history.
Come Chat with Us!
LVReefer User is Offline
Copepod
Copepod

Posts:19


07/24/2007 3:59 PM  
Cool, thanks

Carlosreef User is Offline
Copepod
Copepod
Posts:21
Melrose Park, IL


08/13/2007 6:47 PM  

Yes, carlosreef.com is all PHP.

The way the carlosreef.com/default.php?f=TankStatus works is as follows:

The first part of the page takes the XML items and creates variables with values.

It takes the LT1 (metal halide 1) status and creates a variable with the status as a value... $LT1 = ON

Then, when it is time for the code to display images, I tell the page to check the status of the LT1 variable.  If LT1 = ON, then display image A... If LT1 = OFF then display image B.

Here is the first part of the PHP file:

 

# Opens up the XML file  
$xml = "";
$f = fopen( 'URL of XML file', 'r' );
while( $data = fread( $f, 4096 ) ) { $xml .= $data; }
fclose( $f );
preg_match_all( "/\(.*?)\<\/item\>/s", 
$xml, $itemblocks );
foreach( $itemblocksΏ] as $block )
{
preg_match_all( "/\(.*?)\<\/title\>/", 
$block, $title );
preg_match_all( "/\(.*?)\<\/description\>/", 
$block, $description );
# Creates and assigns values to variables.  
switch ($titleΏ]Ύ]) {
case ('Date'):
$Date = $descriptionΏ]Ύ]
break;     
case ('Time'):
$Time = str_replace(" ", "", $descriptionΏ]Ύ]);
break;     
case ('Temp'):
$Temp = str_replace(" ", "", $descriptionΏ]Ύ]);
break;     
case ('pH'):
$pH = str_replace(" ", "", $descriptionΏ]Ύ]);
break;     
case ('ORP'):
$ORP = str_replace(" ", "", $descriptionΏ]Ύ]);
break;     
case ('LT1'):
$LT1 = str_replace(" ", "", $descriptionΏ]Ύ]);
break;     
case ('LT2'):
$LT2 = str_replace(" ", "", $descriptionΏ]Ύ]);
break;     
case ('LT3'):
$LT3 = str_replace(" ", "", $descriptionΏ]Ύ]);
break;     
case ('PM1'):
$PM1 = str_replace(" ", "", $descriptionΏ]Ύ]);
break;     
case ('PM2'):
$PM2 = str_replace(" ", "", $descriptionΏ]Ύ]);
break;     
case ('HET'):
$HET = str_replace(" ", "", $descriptionΏ]Ύ]);
break;     
case ('COL'):
$COL = str_replace(" ", "", $descriptionΏ]Ύ]);
break;     
case ('CO2'):
$CO2 = str_replace(" ", "", $descriptionΏ]Ύ]);
break;     
case ('ALM'):
$ALM = str_replace(" ", "", $descriptionΏ]Ύ]);
break;    
} 
}
?>
Carlosreef User is Offline
Copepod
Copepod
Posts:21
Melrose Park, IL


08/13/2007 6:54 PM  

Steve, Not sure how much PHP you know but I would be more than happy to send you over the actual php files. It might help to see how I created the pages and allow you to work on your templates.

At this time, TankStatus page works off the XML file.

Default.php works off a MySQL database where the XML file gets stored every 5 minutes. The database allows me to do energy consumption as well as history, and more importantly, realtime charts.

Carlos

Posted By slallen on 07/24/2007 3:21 PM
You know what is funny about you using ReefSpace. A year ago I asked about doing the same kind of thing on our site here. Looks like Travis is all over the place these days. There are some tips in this thread. http://www.reefchat.org/Forums/tabid/264/forumid/9/tpage/1/view/topic/postid/933/Default.aspx#1083

Basically you will have to read each name/value pair into strings and use them as needed. I am working on a layout similar to CarlosReef as a demo. I think his is in php, perhaps he will stop back in and share some of his tips.

 

Carlosreef User is Offline
Copepod
Copepod
Posts:21
Melrose Park, IL


08/13/2007 7:35 PM  

Later on that page, here is where I tell it to check the status of the item and display the corresponding image:

switch($LT1) {
#Here is where the code checks if LT1 status is ON.
case ON:
echo '<div align="center"><img src="images/tank_status/mh_on.jpg" width="54" height="90" border="0" alt="image"/>MH: '.$LT1.';
break;
#Here the code specifies that if LT1 has a status that is other than ON (i.e. OFF), display the OFF image.<br />
default:
echo' <div align="center"><img src="images/tank_status/mh_off.jpg" width="54" height="90" border="0" alt="image"/>MH: '.$LT1.';
break;
}

Carlosreef User is Offline
Copepod
Copepod
Posts:21
Melrose Park, IL


08/13/2007 7:49 PM  
hmm, tried to put the HTML code but don't seem to be able to do so.
admin User is Offline
Site Administrator
Tang
Tang

Posts:255


08/14/2007 10:33 AM  
The easiest way to put a code window on this forum.

In the editor select source. Then where you want the window type < code > (Without the spaces). Insert your code. Finally type < / code > (Again without spaces).
Click source. (Your code will not show). Then click submit.

And you get the results above.


ReefChat Staff
slallen User is Offline
ReefChat Staff
Moray
Moray

Posts:301
Flower Mound, TX


08/15/2007 4:26 PM  

Well I have attempted to keep it simple. The JavaScript is about as simple as you can get it. You can modify the switch statement to include any of your parameters. Then simply modify the body area to your taste.

No for the bad news. Even though the code is proper for FireFox and other Mozilla browsers it does not seem to work. If anyone has any idea what I am missing let me know.

 

<html><head><script language="JavaScript">var xmlhttp;function loadXMLDoc(url) {
xmlhttp=null;// code for Mozilla, etc.if (window.XMLHttpRequest) {
xmlhttp= new XMLHttpRequest()
}
// code for IEelse if (window.ActiveXObject)
{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP")
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=loadXML
xmlhttp.open("GET",url,false)
xmlhttp.send(null)
//alert(xmlhttp.responseXML.xml);
}
else
{
alert("Your browser does not support XMLHTTP.")
}
}
function loadXML() {
if (xmlhttp.readyState==4) {
// if "OK"if (xmlhttp.status==200) {
var root = xmlhttp.responseXML.documentElement;var items = root.getElementsByTagName("item")
for (var i=0;i<items.length;i++) {
var item= items[i]try {
var title = item.getElementsByTagName("title")Ύ].firstChild.nodeValue;var description = item.getElementsByTagName("description")Ύ].firstChild.nodeValue;
}
catch (e){}
switch (title) {
case 'Time': time.innerText = description; break;case 'Temp': temp.innerText = description; break;case 'pH': pH.innerText = description; break;case 'ORP': ORP.innerText = description; break;//case 'Cond': CONDVal = description; break;
}
}
//document.write("Time: " + timeVal + " Temp: " + tempVal + " pH: " + pHVal + " ORP: " + ORPVal);
}
else
{
alert("Problem retrieving XML data")
}
}
}
</script></head><body onload="loadXMLDoc('http://www.reefchat.org/slallen.xml');"><b>Current Status: </b><span id="time"> </span><br /><b>Temp: </b><span id="temp"></span><br /><b>pH: </b><span id="pH"></span><br /><b>ORP: </b><span id="ORP"></span></body></html>


real time stats
Click my stats for a graphed history.
Come Chat with Us!
Carlosreef User is Offline
Copepod
Copepod
Posts:21
Melrose Park, IL


08/20/2007 12:32 PM  

So as I am using the scripts and the XML file I find little things that happen.

First I had the script setup so everytime someone visited my site, the script would parse the XML file and get the information from them.  The problem I was having is that since my site gets a bit of traffic, the real-time parsing was slowing things down big time.  It was taking time for the script to parse the file.

In order to fix the problem, I changed the site slightly.  Now I have a script that parses the XML file into a MySQL database via cron job every 1 minutes. Since I am just looking for the current status, the script starts by clearing the table and then populating the fields with the information from the XML file. Therefore the table only contains the latest status info. (I have another table and another script that logs ALL status for historical use).  Then the website was changed to query the database (much faster) instead of the XML file.  It seems to have made quite a difference.

Here is the script that parses the XML file to a database (PHP 4 and 5 compatible):

 

php
##This file is to be run via cron job once every 1 minutes
##It takes the AC generated XML file and stores the status
##and values to a SQL database.  
##
## * * * * * /usr/bin/lynx -source http://URLofScript
##
#Opens the database connectionmysql_connect('localhost', 'username', 'password') or die(odbc_error());mysql_select_db("table_name");
#Clears the current status table and prepares it for new valuesmysql_query("TRUNCATE TABLE `table_name`");
#Opens and stores the xml file into a string
$xml = "";
$f = fopen( 'http://www.YourSite.com/RSS/AquaStatus.XML', 'r' );while( $data = fread( $f, 4096 ) ) { $xml .= $data; }
fclose( $f );
#Parse items from XMLpreg_match_all( "/\<item\>(.*?)\<\/item\>/s", 
$xml, $itemblocks );
foreach( $itemblocksΏ] as $block )
{
preg_match_all( "/\<title\>(.*?)\<\/title\>/", $block, $title );
preg_match_all( "/\<description\>(.*?)\<\/description\>/", $block, $description );
#Stores items in SQL database
mysql_query("INSERT INTO table_name (`ID`, `Title`, `Description`, `PubDate`) VALUES ('', '".$titleΏ]Ύ]."', '".$descriptionΏ]Ύ]."', NOW())";
#A screen print of what was stored
echo( $titleΏ]Ύ]." - ".$descriptionΏ]Ύ]."<br/>\n" );
}
?>
host User is Offline
Copepod
Copepod
Posts:11


08/20/2007 3:07 PM  
Cool Carlos! Definitely has inspired a few of us to play with the idea. As I posted the java scriopt above. I have been convinced to look at php. So who knows you may see some other pages like yours soon.

Thanks again!
Ashlar User is Offline
ReefChat Staff
Goby
Goby
Posts:144


08/20/2007 5:53 PM  
Carlos, could I get you to make a zip file of the above code and provide a link to it? The regex comes out jumbled.

Carlosreef User is Offline
Copepod
Copepod
Posts:21
Melrose Park, IL


08/21/2007 7:18 AM  

Give me a day or so and I will put together a set of template files (php) that people can use as Tank Status pages on their websites. 

Carlos  

Carlosreef User is Offline
Copepod
Copepod
Posts:21
Melrose Park, IL


08/22/2007 10:43 AM  

Here is the template (does not need MySQL to work, images NOT included):

TankStatus.zip

There are two files:

TankStatus.php - actual file needed
README.txt - Instructions on how to use it.

Here is what the file looks like when installed correctly:

TankStatus.php

HTH,

Carlos

slallen User is Offline
ReefChat Staff
Moray
Moray

Posts:301
Flower Mound, TX


08/22/2007 4:07 PM  
Thanks Carlos! Not sure why the $title [ 1 ].[ 0 ] is being translated the way it is. Sorry to ask you for the zip but it is much easier this way.

real time stats
Click my stats for a graphed history.
Come Chat with Us!
climatestudios User is Offline
Copepod
Copepod
Posts:12


09/13/2007 5:15 PM  

Thanks to Reefchat & CarlosReef, here's the integration (rough draft ) in my page... still having trouble getting the php file that store data in sql to work..., but getting there! (Error on line 27, unexpected ']' driving me nuts...)... crash course in php for me

admin User is Offline
Site Administrator
Tang
Tang

Posts:255


09/14/2007 6:01 AM  
Now that is pretty cool. Actually it is almost the perfect size for a mobile widget.

ReefChat Staff
Ashlar User is Offline
ReefChat Staff
Goby
Goby
Posts:144


09/14/2007 3:44 PM  
very very cool

Carlosreef User is Offline
Copepod
Copepod
Posts:21
Melrose Park, IL


09/18/2007 12:58 PM  
Posted By climatestudios on 09/13/2007 5:15 PM

Thanks to Reefchat & CarlosReef, here's the integration (rough draft ) in my page... still having trouble getting the php file that store data in sql to work..., but getting there! (Error on line 27, unexpected ']' driving me nuts...)... crash course in php for me


Hey,

Post your code here and I might be able to help you fix the problem.

Carlos

You are not authorized to post a reply.
Page 1 of 3123 > >>

Forums > ReefChat Extras > Signature Generator > Signature Generator XML intergration into Website



ActiveForums 3.7
Home|Forums|Links|LFS Map|Photo Galleries|Video Gallery|Sponsors
Copyright 2006 by ReefChat.org - A reef keeping communityTerms Of UsePrivacy Statement