Example php script for the info widget

Talk about YBoxen, widgets, Propeller hacking, etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
tvdbon
 
Posts: 14
Joined: Fri Jun 06, 2008 2:51 pm

Example php script for the info widget

Post by tvdbon »

I've got some temperature sensors around the home and the value of each gets dumped into a mysql database. I wrote a little php script which gets the current/min/maximum values for two of the zones and returns in to the ybox2.

I'm still struggling to figure out the color codes and the clear screen code doesn't work for me, but apart from that it works nicely. Here is the script in case anybody is interested. Obviously you need to change the queries to your own database, but its a starting point.

If anybody can get the clear screen code to work or figured out how to do the colours then let me know.

Code: Select all

<?
    require_once( "lib/database.php" );

    connect_sql();

    echo chr(0x1);  // goto home
    
    echo chr(0x0);  // this is not working so we do our own clear
    
    for ( $c = 0; $c < 12; $c++ )
    {
        for ( $d = 0; $d < 10; $d++ )
            echo chr(0x09);
    }

    echo chr(0x1);  // goto home
    
    echo "            GeekHouse Dashboard         ";
    echo chr(0xD);
    echo "Temperatures:";
    echo chr(0xD);
    echo chr(0x09).chr(0x09)."Cur".chr(0x09)."Min".chr(0x09)."Max".chr(0x0D);
    
    // temp sensor outside
    $sql = "SELECT  value FROM `sensor_readings` where sensor_id='109D4EF800080050' ORDER BY `timestamp`  DESC limit 0,1";
    $result = mysql_query( $sql );
    $data = mysql_fetch_row( $result );
    
    echo "Outside: ".chr(0x09).$data[0]." C".chr(0x09);
    
    $sql = "SELECT  value FROM `sensor_readings` where sensor_id='109D4EF800080050'  order by value  ASC ";
    $result = mysql_query( $sql );
    $data = mysql_fetch_row( $result );
    
    echo "".$data[0]." C".chr(0x09);

    $sql = "SELECT  value FROM `sensor_readings` where sensor_id='109D4EF800080050'  order by value  DESC limit 0,1";
    $result = mysql_query( $sql );
    $data = mysql_fetch_row( $result );
    
    echo "".$data[0]." C".chr(0x09);
       
    
    // temp sensor bedroom
    $sql = "SELECT  value FROM `sensor_readings` where sensor_id='1023983F00080039' ORDER BY `timestamp`  DESC limit 0,1";
    $result = mysql_query( $sql );
    $data = mysql_fetch_row( $result );
    
    echo "Bedroom: ".chr(0x09).$data[0]." C".chr(0x09);
    
    $sql = "SELECT  value FROM `sensor_readings` where sensor_id='1023983F00080039'  order by value  ASC limit 0,1";
    $result = mysql_query( $sql );
    $data = mysql_fetch_row( $result );
    
    echo "".$data[0]." C".chr(0x09);

    $sql = "SELECT  value FROM `sensor_readings` where sensor_id='1023983F00080039'  order by value  DESC limit 0,1";
    $result = mysql_query( $sql );
    $data = mysql_fetch_row( $result );
    
    echo "".$data[0]." C".chr(0x09);
?>
I'll post a photo of what it looks like as soon as my camera is charged.

tvdbon
 
Posts: 14
Joined: Fri Jun 06, 2008 2:51 pm

Post by tvdbon »

this is what it looks like so far :

Image

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Post by adafruit »

too cool! (or hot, depending :) )

tvdbon
 
Posts: 14
Joined: Fri Jun 06, 2008 2:51 pm

Post by tvdbon »

thanks ladyada, unfortunately I'm still struggling to get the colours right and the clear screen doesn't work for me at all.

But this is experiment #1, so I'll see how it goes. How difficult would it be to change the ethernet implementation to accept a connection instead of retrieving data from a remote server?

User avatar
harrison
 
Posts: 8
Joined: Mon Jun 09, 2008 3:55 am

Post by harrison »

the clear screen doesn't work for me at all
There was a small bug in the original infowidget that broke the clear screen control byte ($00). Darco fixed it a few weeks ago in the svn repository.

Specifically, the problem was this line:

Code: Select all

if (in := \tel.rxcheck) > 0
The > 0 condition dropped all 0's before they made it to the tv_text driver. You can also work around it by just sending a screen worth of spaces to push off any unwanted stuff.
How difficult would it be to change the ethernet implementation to accept a connection instead of retrieving data from a remote server?
The tcp/ip stack supports both client and server mode. Take a look at the .listen(...) method in api_telnet_serial.spin / driver_socket.spin. The webserver in infowidget.spin would probably be a good reference on how to wait for connections.

tvdbon
 
Posts: 14
Joined: Fri Jun 06, 2008 2:51 pm

Post by tvdbon »

There was a small bug in the original infowidget that broke the clear screen control byte ($00). Darco fixed it a few weeks ago in the svn repository.
Cool, I'll get the new widget then and reprogram it. Thats anyways on my todo list

(x) Compile and download new widget onto the ybox2
You can also work around it by just sending a screen worth of spaces to push off any unwanted stuff.
Yeah, thats what I did with the script, instead I sent a bunch of tabs.
The tcp/ip stack supports both client and server mode. Take a look at the .listen(...) method in api_telnet_serial.spin / driver_socket.spin. The webserver in infowidget.spin would probably be a good reference on how to wait for connections.
Ofcourse, I never even thought about the webserver, it also accepts incoming connections. This is starting to sound like my original Home Automation idea will work great.

Another question: I've only worked on AVR's before, no parallax or even basic stamps before, so what I want to try and do is write some small test programs as I learn to use the propeller and get a handle on spin. Will my own programs influence the ethernet bootloader ? I don't have propplug (planning on getting one when the money is available) so I don't want to lose functionality of uploading new programs (widgets).

User avatar
darco
 
Posts: 118
Joined: Wed Jun 04, 2008 7:54 pm

Post by darco »

I've only worked on AVR's before, no parallax or even basic stamps before, so what I want to try and do is write some small test programs as I learn to use the propeller and get a handle on spin. Will my own programs influence the ethernet bootloader ? I don't have propplug (planning on getting one when the money is available) so I don't want to lose functionality of uploading new programs (widgets).
It is somewhat hard to overwrite the bootloader on accident. If you need to store information persistently in the EEPROM, just use my settings object and you will be absolutely safe. Other than that you shouldn't have to worry about it.

Using the prop-plug on the other hand will overwrite the bootloader. This isn't really considered to be much of a problem however, because if you have a prop-plug then you can easily write the bootloader back.



[/quote]

Locked
Please be positive and constructive with your questions and comments.

Return to “YBox2 (discontinued)”