Skip to content

Commit

Permalink
before coffee
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbajnai committed Oct 7, 2024
1 parent 9b6d60a commit bbdd766
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 70 deletions.
6 changes: 5 additions & 1 deletion controller/arduino/Ardu/Ardu.ino
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ void sendStatus(String param)
XpercentageArray[head] = Xpercentage;
YpercentageArray[head] = Ypercentage;
boxTempArray[head] = boxTemp;
boxHumArray[head] = boxHum;

// Initialize sums
float XpressureSum = 0;
Expand All @@ -739,6 +740,7 @@ void sendStatus(String param)
float XpercentageSum = 0;
float YpercentageSum = 0;
float boxTempSum = 0;
float boxHumSum = 0;

// Sum the elements in the array
for (byte i = 0; i < n; i++) {
Expand All @@ -748,6 +750,7 @@ void sendStatus(String param)
XpercentageSum += XpercentageArray[i];
YpercentageSum += YpercentageArray[i];
boxTempSum += boxTempArray[i];
boxHumSum += boxHumArray[i];
}

// Get the average of the array
Expand All @@ -757,6 +760,7 @@ void sendStatus(String param)
Xpercentage = XpercentageSum / n;
Ypercentage = YpercentageSum / n;
boxTemp = boxTempSum / n;
boxHum = boxHumSum / n;

// Update the head pointer for circular buffer
head = (head + 1) % n;
Expand Down Expand Up @@ -787,7 +791,7 @@ void sendStatus(String param)
doc["Z_percentage"] = String(percentageZ_fromSteps(), 2);
doc["X_pressure"] = String(Xpressure, 3);
doc["Y_pressure"] = String(Ypressure, 3);
doc["A_pressure"] = String(Zpressure, 1);
doc["Z_pressure"] = String(Zpressure, 1);
doc["valves"] = valveStatus;
doc["relays"] = relayStatus;
doc["boxHumidity"] = String(boxHum, 2);
Expand Down
44 changes: 25 additions & 19 deletions controller/php/evaluateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// This script is used to:
// evaluation data and send the results to the isolabor server

error_reporting(E_ALL);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/Berlin');
$timestamp = time();
$DateTimeAdded = date("Y-m-d H:i:s", $timestamp);
Expand All @@ -13,7 +15,7 @@
echo "Parameters are recieved from JavaScript<br><br>";
} else {
$sampleName = urldecode($_GET['sampleName']);
$userName = urldecode($GET['userName']);
// $userName = urldecode($GET['userName']);
echo "Parameters are recieved via URL<br><br>";
}

Expand Down Expand Up @@ -71,21 +73,18 @@
// Copy SPE files from the TILDAS PC to the local directory
$csvFile = $localDirectory . "/list_of_SPE_files.csv";
$localSPEDirectory = $localDirectory . "/SPE_files";
if (!is_dir($localSPEDirectory) && file_exists($csvFile)) {
if (file_exists($csvFile) && !is_dir($localSPEDirectory)) {
mkdir($localSPEDirectory, 0777, true);

$csv = fopen($csvFile, "r");
$speFiles = array();
while (!feof($csv)) {
$speFiles[] = fgetcsv($csv)[0];
}
fclose($csv);

exec("rm " . $csvFile);

if (count(scandir('/mnt/TILDAS_PC')) <= 2) {
echo("<br>TILDAS PC not mounted.<br>");
} else {
if (!is_dir('/mnt/TILDAS_PC')) {
echo("<br><span style='color:red;'>TILDAS PC not mounted</span><br>");
} else {
$speFiles = array_diff($speFiles, array(''));
foreach ($speFiles as $speFile) {
$localFilePath = $localDirectory . "/SPE_files/" . basename($speFile);
Expand All @@ -97,9 +96,18 @@
}
}
exec("rm " . $csvFile);
} elseif (is_dir($localSPEDirectory) && count(scandir($localSPEDirectory)) > 2) {
echo("<br>SPE files already there<br>");
} else {
echo("<br>SPE files not copied<br>");
echo("<br><span style='color:red;'>SPE files not copied</span><br>");
}

// Clean up
exec("rm " . $csvFile);
if (count(scandir($localSPEDirectory)) <= 2){
rmdir($localSPEDirectory);
}

echo "</br>";

// Create a ZIP archive of all files and upload that too the isolaborserver
Expand All @@ -115,28 +123,28 @@

$connection = ssh2_connect($server_IP);
if (!$connection) {
die("Failed to connect to the SSH server.</br>");
die("<span style='color:red;'>Failed to connect to the SSH server</span></br>");
}

// Authenticate with the SSH server
if (!ssh2_auth_password($connection, $server_user, $server_passwd)) {
die("Failed to authenticate with the SSH server.</br>");
die("<span style='color:red;'>Failed to authenticate with the SSH server</span></br>");
}

// Initialize SFTP subsystem
$sftp = ssh2_sftp($connection);
if (!$sftp) {
die("Failed to initialize SFTP subsystem.</br>");
die("<span style='color:red;'>Failed to initialize SFTP subsystem</span></br>");
}

// Check if remote directory exists
$stat = ssh2_sftp_stat($sftp, $remoteDirectory);
if ($stat !== false && $stat['mode'] & 0040000) {
echo "Remote directory exists.</br>";
echo "Remote directory exists</br>";
} else {
// Create remote directory if it doesn't exist
if (!ssh2_sftp_mkdir($sftp, $remoteDirectory)) {
die("Failed to create remote directory.</br>");
die("<span style='color:red;'>Failed to create remote directory</span></br>");
}
echo "Remote directory created.</br>";
}
Expand All @@ -149,14 +157,14 @@
// Upload the file via SFTP
$stream = fopen($localFilePath, 'r');
if (!$stream) {
echo "Failed to open local file for reading: $localFilePath</br>";
echo "<span style='color:red;'>Failed to open local file for reading: $localFilePath</span></br>";
continue;
}

$upload = ssh2_scp_send($connection, $localFilePath, $remoteFilePath, 0644);
$upload = ssh2_scp_send($connection, $localFilePath, $remoteFilePath, 0777);

if (!$upload) {
echo "Failed to upload file: $localFilePath</br>";
echo "<span style='color:red;'>Failed to upload file: $localFilePath</span></br>";
} else {
echo "File uploaded successfully: $localFilePath</br>";
}
Expand All @@ -166,6 +174,4 @@

// Delete some of the local files to save space on the Raspberry
exec("rm /var/www/html/data/Results/$sampleName/$sampleName.zip");
// exec("rm Results/$sampleName/*.png");
exec("rm /var/www/html/data/Results/$sampleName/bracketingResults.xlsx");
}
Loading

0 comments on commit bbdd766

Please sign in to comment.