Bootes87
January 1st, 2009, 10:16 AM
I have a temperature sensor connected to the serial port of my server. I use a command line program (digitemp_DS9097) to query the sensor and get the current temperature and it works great. Now I would like to post the temperature to a web page hosted on the server. Each time the page is loaded my a php script calls digitemp_DS9097 and print the results to the web page. At least that's how I would like it to happen.
index.php
<?
$temp = `digitemp_DS9097 -a -o %F`;
print($temp);
?>
running digitemp_DS9097 in console:
jeffrey@Tabitha:/var/www$ digitemp_DS9097 -a -o %F
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
68.000000
jeffrey@Tabitha:/var/www$
The web page displays:
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane GNU Public License v2.0 - http://www.digitemp.com
the web page (view source):
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
You can see that it excludes the last and IMPORTANT part of the output ... the temperature!
digitemp has a -v parameter that displays alot more information about the sensor:
jeffrey@Tabitha:/var/www$ digitemp_DS9097 -a -v -o %F
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
67.887500
Temperature : 0x28
Sign : 0x00
TH : 0x4B
TL : 0x46
Remain : 0x0D
Count Per C : 0x10
CRC : 0x57
scratchpad[0] = 0xBE
scratchpad[1] = 0x28
scratchpad[2] = 0x00
scratchpad[3] = 0x4B
scratchpad[4] = 0x46
scratchpad[5] = 0xFF
scratchpad[6] = 0xFF
scratchpad[7] = 0x0D
scratchpad[8] = 0x10
scratchpad[9] = 0x57
jeffrey@Tabitha:/var/www$
however the resulting web page and source does not change. It gets cut off after "Public License v2.0 - http://www.digitemp.com"
One thing I've noticed is that when running digitemp from the console it immediately prints
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
then there is a 750ms -1000ms delay before the temperature is printed. This is due to the time it takes to query the sensor. Is it possible that php is not patient enough to wait for the rest of the string and just carries on with out it? If so is there a way to put the breaks on and make it wait for the rest of the output?
I also wonder if after printing "Public License v2.0 - http://www.digitemp.com" there is some kind of character (like a carriage return) that is falsely telling php, it has reached the end?
Please let me know what you think about this!
Thank You,
Bootes
index.php
<?
$temp = `digitemp_DS9097 -a -o %F`;
print($temp);
?>
running digitemp_DS9097 in console:
jeffrey@Tabitha:/var/www$ digitemp_DS9097 -a -o %F
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
68.000000
jeffrey@Tabitha:/var/www$
The web page displays:
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane GNU Public License v2.0 - http://www.digitemp.com
the web page (view source):
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
You can see that it excludes the last and IMPORTANT part of the output ... the temperature!
digitemp has a -v parameter that displays alot more information about the sensor:
jeffrey@Tabitha:/var/www$ digitemp_DS9097 -a -v -o %F
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
67.887500
Temperature : 0x28
Sign : 0x00
TH : 0x4B
TL : 0x46
Remain : 0x0D
Count Per C : 0x10
CRC : 0x57
scratchpad[0] = 0xBE
scratchpad[1] = 0x28
scratchpad[2] = 0x00
scratchpad[3] = 0x4B
scratchpad[4] = 0x46
scratchpad[5] = 0xFF
scratchpad[6] = 0xFF
scratchpad[7] = 0x0D
scratchpad[8] = 0x10
scratchpad[9] = 0x57
jeffrey@Tabitha:/var/www$
however the resulting web page and source does not change. It gets cut off after "Public License v2.0 - http://www.digitemp.com"
One thing I've noticed is that when running digitemp from the console it immediately prints
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
then there is a 750ms -1000ms delay before the temperature is printed. This is due to the time it takes to query the sensor. Is it possible that php is not patient enough to wait for the rest of the string and just carries on with out it? If so is there a way to put the breaks on and make it wait for the rest of the output?
I also wonder if after printing "Public License v2.0 - http://www.digitemp.com" there is some kind of character (like a carriage return) that is falsely telling php, it has reached the end?
Please let me know what you think about this!
Thank You,
Bootes