temp.php
#!/usr/bin/php
<?php
 
$servername = "localhost";
$username = "ekorre";
$password = "sw0rks";
$dbname = "nexa";
 
 
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
 
//Get nexa data
$exec_command = "tdtool --list | grep -E \"fineoffset|orego\" ";
$string_delimiter = "\t";
 
exec($exec_command,$exec_output);
$output_device = "";
 
for($i=0; $i < count($exec_output); $i++){
        // print $exec_output[$i] . "\n";
        $cols = explode($string_delimiter, $exec_output[$i]);
        //print var_dump($cols);
        $output_device = trim($cols[2] = substr("$cols[2]", 0, -2));
        $output_datetime = trim($cols[7]);
        $output_temp = trim($cols[3] = substr("$cols[3]", 0, -2));
        $output_humid = trim($cols[4] = substr("$cols[4]", 0, -6));
        print "$output_device $output_datetime $output_temp $output_humid \n";
 
        $sql = "INSERT INTO temp (id, device, datentime, temp, humid) VALUES ('', '$output_device', '$output_datetime', '$output_temp', '$output_humid' )";
}
 
if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
 
$conn->close();
print $sql
 
//print "$output_device $output_datetime $output_temp $output_humid \n";
 
 
/*
För att sortera upp datumen: . trim($cols[2] = substr("$cols[2]", 0, -2)) . " " . trim($cols[8] = substr("$cols[7]", 0, -9)) . " " . trim($cols[9] = substr("$cols[7]", 1$
*/
 
/* $output = $output . trim($cols[2] = substr("$cols[2]", 0, -2)) ."". trim($cols[7]) . " " . trim($cols[3] = substr("$cols[3]", 0, -2)) ." " . trim($cols[4] = substr("$$
?>