LAN DS18B20 WEB Temperature Monitor 1 meter Cable
www.WEB-Relays.com
www.Facebook.com/KMtronic

Create a Crontab server side PHP script for uploading temperature to a MySQL database

Spread the love

 

KMtronic LAN DS18B20 WEB 1-Wire Digital Temperature Monitor
KMtronic LAN DS18B20 WEB 1-Wire Digital Temperature Monitor

 


 

Temperature Monitor STATUS XML data

http://XXX.XXX.XXX.XXX/status.xml
XXX.XXX.XXX.XXX is IP ADDRESS Temperature monitor

 


 

MySQL table

Create a Crontab server side PHP script for uploading temperature to a MySQL database
Create a Crontab server side PHP script for uploading temperature to a MySQL database
Create a Crontab server side PHP script for uploading temperature to a MySQL database
Create a Crontab server side PHP script for uploading temperature to a MySQL database

 


 

Cron is a system daemon used to execute desired tasks (in the background) at designated times. 

A crontab file is a simple text file containing a list of commands meant to be run at specified times. It is edited using the crontab command. The commands in the crontab file (and their run times) are checked by the cron daemon, which executes them in the system background.

Crontab PHP file:

<?php

$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "temperature_database";


// Loading the XML file
$xml = simplexml_load_file("http://XXX.XXX.XXX.XXX/status.xml");
// XXX.XXX.XXX.XXX is IP ADDRESS Temperature monitor

foreach($xml->children() as $sensor)
 {
  if ($sensor->id == "2874EDD0040000F3" )
  {
  $temp_value = $sensor->temp;
  }
 }
// "2874EDD0040000F3" is ID DS18B20 sensor

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
 die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO km_temperature (temp_id, temp_value, temp_time )
VALUES ('2874EDD0040000F3', $temp_value , NOW())";
// "km_temperature" is TABLE name


if ($conn->query($sql) === TRUE) {
 echo "New record created successfully";
} else {
 echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

?>

 

 

 

 

 

 

KMtronic LAN WEB 8 Channel Relay board