View a Twine dashboard in simple static HTML?
I don't see an obvious way to do this currently, and I'd really like to be able to. A static dashboard would enable viewing a twine's status using ultra-simple browsers (perhaps Dillo/Lynx) and/or fetching status via a script.
Answers
I have a PHP page that pulls data from a file that is updated by the twine. So not strictly an HTML page but all of the code is HTML in view source. The PHP just fills in the field values for temperature in.
I had originally designed this for use with mobile phone browsers. Big numbers displayed etc.
I'm hoping you have a basic understanding of HTML and PHP. I've commented most areas in the code explaining what is going on.
Serious note: The Twine can not be setup (as yet) to constantly push data every 5minutes... Super Mechanical have stated that the rules trigger only on threshold events. Pretty much meaning once.
PHP PAGE: twine_to_txt.php
CODE:
--------------
<?php
//Read Fahrenheit value from URL
$f=$_GET['f'];
$myFile = 'currenttemp.php';
$fh = fopen($myFile, 'w') or die('can not open file');
$stringData = ''.$f.'';
fwrite($fh, $stringData);
fclose($fh);
?>
--------------
PHP PAGE: currenttemp.php
CODE:
This page doesn't have code it is created on the fly by the above code.
HOW TO ACTION THE PHP PAGE twine_to_txt.php:
Set up a RULE for WHEN temperature rises above 0 trigger after 0 seconds reset 900 seconds
THEN HTTP request your page http://yourdomain.com/twine_to__txt.php?f=[temperature]
All of the above pushes the F temperature value of the Twine to a PHP file with only that in it.
Now you want to display your information, in both F and C values. See below:
PHP PAGE: temp_reading.php
CODE:
--------------
<?php
// Open the file that has the current temperature in it
$myFile = "currenttemp.php";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
// echo $theData;
//Convert Fahrenheit into Celsius
$c=intval((5/9)*($theData-32));
//$c is now Cel and $theData is Fahrenheit
?>
Twine Temperature
<?php
echo ''.$theData.' Fahrenheit';
?>
<?php
echo ''.$c.' Celsius';
?>
Last updated by Twine:
<?php
// outputs e.g. currenttemp.php was last modified: December 29 2002 22:16:23.
//
// NOTE TO TWINE COMMUNITY:
// On my server this would not give me the date/time. It said that the date could not be relied
// on so it wouldn't display it to me. Only an error message. So still looking for a solution.
//
//
$filename = 'currenttemp.php';
if (file_exists($filename)) {
echo "" . date ("F d Y H:i:s.", filemtime($filename));
}
?>
<?php
?>
--------------
FINISHED!!!
The above page is a very very very basic HTML/PHP combination to get you started.
I personally would use a Mobile Webkit or something to make it look like a web based iPhone app.
Hope this helps everyone out.
Any problems, issues let me know and I'll do my best.
As above in the code. The last updated date/time of the updated php file from the twine doesn't work. I have yet to find a solution that works.
G
Doesn't make any sense to have a rules device triggering actions when they've set it to only do it once. I want mine to report constantly.