serversetup_webupdate - dl3ebb/OpenIot GitHub Wiki
The Web Update functionality is based on an apache2
web server with a PHP script.
Ubuntu 24.04 does not include PHP 8.4 by default, so we need to manually add the repository:
sudo add-apt-repository ppa:ondrej/php
sudo apt update
Now, install apache2 and PHP:
sudo apt install apache2 php8.4 -y
Once the installation is complete, navigating to http://openiot in your browser should display the Apache2 Default Page.
The Web Update consists of two parts:
1. PHP Script to Determine the Latest Version
This script identifies the latest version of an application and returns it. Save the following script as uq.php
in /var/www/html/
:
<?php
// Directory where the images are stored
$directory = 'update/img';
// The script is called with http://<servername>/uq.php?app=<appname>
// It will return the highest available version for the given application.
if (isset($_GET['app'])) {
$appName = $_GET['app'];
} else {
die("Application name not given.");
}
// Scan the directory
$files = scandir($directory);
// Initialize the variables
$highestVersion = 0;
// The image filenames follow the pattern <application>_<version>.bin
foreach ($files as $file) {
if (preg_match("/^" . preg_quote($appName, '/') . "_(\d+)\.bin$/", $file, $matches)) {
$version = $matches[1];
if (version_compare($version, $highestVersion, '>')) {
$highestVersion = $version;
}
}
}
// Return the result
if ($highestVersion !== null) {
echo $highestVersion;
} else {
echo "-1";
}
?>
2. Directory for Application Images
Create a directory where the program and SPIFFS images will be stored:
sudo mkdir -p /var/www/html/update/img
sudo chown openiot:openiot /var/www/html/update/img
This directory will hold the binary files for the updates. Ensure you upload the necessary images here.
3. Final Steps
- Test the setup by saving the PHP script and visiting the URL:
http://<servername>/uq.php?app=<appname>.
Replace <appname>
with the name of your application.
- To upload images for your application, refer to the Tutorial Web Update.
| ← Previous Page (Install Syslog) | ↑ Server Setup Main Page