The Twine forums are now archived. If you need help, please visit http://help.supermechanical.com

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

  • 10 Comments sorted by Votes Date Added
  • I have kind of pulled this off.

    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.
  • Cool! How is the file updated by the twine? Is the PHP script scraping the control panel somehow?
  • No, not scraping. It's sending. I'll put something together for you. Sorry for the late reply.
  • Josh, I've found the code and very quickly cleaned it up, however it's still very crude.

    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
  • edited January 2013 Vote Up0Vote Down
    When I posted the last message is added a lot of random < br /> in places. You'll need to find these and take them out. It might stop things from working.
  • Thanks Gary! No trouble reading the code. Guess I'll have to set up a bunch of transition rules to trigger updates...
  • I think people have still been having issues getting their Twine to trigger even with as many as 16 rules set for reporting. I've got mine set wrong and it only ever goes off when I set it up.

    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.
  • Yeah, not quite what I was hoping for.  Someone suggested that Selenium might be a better way to accomplish my original page-scraping goal.  Will see if I can get it going...
  • Selenium-python solution works as I'd hoped.  Only drawback is that it has to open up a real web browser (choice of Firfox, Chrome, or IE) to do the job.  Will post up a script if anyone's interested.
Sign In or Register to comment.