Advertisement
Azuria

PHP Script til beregning af thermistor og data input til sql

Apr 24th, 2011
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. <?
  2. function Thermistor($Temp)
  3. {
  4.   $Temp = (10240000/$Temp) - 10000;
  5.   $Temp = log( $Temp);
  6.   $Temp = 1 / (0.001129148 + (0.000234125 * $Temp) + (0.0000000876741 * $Temp * $Temp * $Temp));
  7.   $Temp = $Temp - 273.15;            // Convert Kelvin to Celcius
  8.   $Temp = round($Temp, 2);
  9.   return $Temp;
  10. }
  11. $temps = explode('|', $print, -1);
  12. $TankTop = Thermistor($temps[0]);
  13. $TankMidt = Thermistor($temps[1]);
  14. $TankBund = Thermistor($temps[2]);
  15. $SolIndF = Thermistor($temps[3]);
  16. $SolUdF = Thermistor($temps[4]);
  17. $SolIndT = Thermistor($temps[5]);
  18. $SolUdT = Thermistor($temps[6]);
  19. $Pumpe = $temps[7];
  20.  
  21.  
  22. $dbhost = 'localhost';
  23. $dbuser = 'root';
  24. $dbpass = 'password';
  25. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');
  26. $dbname = 'solfanger';
  27. mysql_select_db($dbname);
  28.  
  29.  
  30. mysql_query("INSERT INTO tempdata (tanktop, tankmidt, tankbund, fangerind, fangerud, tankind, tankud, pumpe) VALUES ('$TankTop', '$TankMidt', '$TankBund', '$SolIndF', '$SolUdF', '$SolIndT', '$SolUdT', '$Pumpe')") or die(mysql_error());
  31.  
  32.  
  33. mysql_close($conn);
  34.  
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement