c2is/ota
c2is/ota provides a basic OTA (over-the-air) package for Laravel/PHP projects. Set up and manage OTA-related functionality in your application with a simple, lightweight foundation.
Installation
composer require c2is/ota
Register the service provider in config/app.php:
'providers' => [
C2is\OTA\OTAServiceProvider::class,
],
Publish Configuration
php artisan vendor:publish --provider="C2is\OTA\OTAServiceProvider" --tag="config"
Configure config/ota.php with your OTA server endpoints, authentication, and storage paths.
First Use Case: Triggering an OTA Update Use the facade in a controller or command:
use C2is\OTA\Facades\OTA;
public function updateDeviceFirmware($deviceId, $firmwarePath)
{
$result = OTA::update($deviceId, $firmwarePath);
return response()->json($result);
}
Firmware Update Pipeline
// 1. Check for available updates
$availableUpdates = OTA::checkForUpdates($deviceId);
// 2. Download the update (sync or async)
$updatePath = OTA::downloadUpdate($updateId, storage_path('app/ota'));
// 3. Apply the update (with rollback support)
$result = OTA::applyUpdate($deviceId, $updatePath);
Delta Updates (Bandwidth Optimization)
$deltaPatch = OTA::generateDeltaPatch($currentVersion, $newVersion);
OTA::applyDeltaPatch($deviceId, $deltaPatch);
Progress Tracking
OTA::onProgress(function ($progress) {
Log::info("Update progress: {$progress}%");
});
Queue Large Updates Offload heavy operations to Laravel queues:
UpdateJob::dispatch($deviceId, $firmwarePath);
Event-Driven Workflows Listen for OTA events to trigger notifications or audits:
// In EventServiceProvider
protected $listen = [
'C2is\OTA\Events\UpdateStarted' => [
\App\Listeners\LogUpdateAttempt::class,
],
'C2is\OTA\Events\UpdateFailed' => [
\App\Listeners\NotifyDevOps::class,
],
];
Custom Storage Backends
Extend the StorageAdapter interface to support S3 or other storage:
class S3StorageAdapter implements \C2is\OTA\Contracts\StorageAdapter
{
public function store($file, $path)
{
// S3 logic here
}
}
Authentication Integration Tie into your existing auth system (e.g., Sanctum, Passport):
OTA::setAuthResolver(function () {
return auth()->user()->apiToken;
});
Binary Data Handling
$checksum = OTA::calculateChecksum($firmwarePath);
if (!OTA::validateChecksum($checksum, $expectedChecksum)) {
throw new \Exception("Checksum mismatch!");
}
Device-Specific Quirks
PostUpdateHook interface:
class CustomPostUpdateHook implements \C2is\OTA\Contracts\PostUpdateHook
{
public function execute($deviceId)
{
// Device-specific reboot logic
}
}
Concurrent Update Conflicts
if (Lock::get('ota-'.$deviceId)->block(10)) {
OTA::applyUpdate($deviceId, $firmwarePath);
Lock::release('ota-'.$deviceId);
}
Undocumented API Changes
composer.json:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/your-fork/OTA.git"
}
],
"require": {
"c2is/ota": "dev-your-branch"
}
Enable Verbose Logging
Set OTA_DEBUG=true in .env and check storage/logs/ota.log for low-level details.
Simulate Failures Use Laravel’s HTTP mocking to test edge cases:
$this->mock(\C2is\OTA\Http\OTAClient::class)
->shouldReceive('download')
->andThrow(new \Exception("Simulated network failure"));
Inspect Raw Payloads Dump binary data for debugging:
$binaryData = file_get_contents($firmwarePath);
dd(bin2hex(substr($binaryData, 0, 100))); // Hex dump first 100 bytes
Custom Validation Rules
Extend the Validator class to add device-specific checks:
class CustomValidator extends \C2is\OTA\Validator
{
protected function validateFirmware($firmware)
{
// Add custom logic (e.g., check for required headers)
return parent::validateFirmware($firmware);
}
}
Plugin System for OTA Protocols Support multiple protocols (HTTP, MQTT, etc.) via a plugin interface:
interface ProtocolPlugin
{
public function sendUpdate($deviceId, $payload);
}
Rollback Strategy Customization Override the default rollback behavior (e.g., time-based or version-based):
OTA::setRollbackStrategy(function ($deviceId, $failedUpdate) {
return OTA::revertToVersion($deviceId, '1.2.0');
});
Progress Reporting
Integrate with frontend progress bars by extending the ProgressTracker:
class FrontendProgressTracker extends \C2is\OTA\ProgressTracker
{
public function report($progress)
{
event(new \App\Events\UpdateProgress($progress));
}
}
Default Timeouts
The package may use short timeouts for OTA operations. Adjust in config/ota.php:
'timeouts' => [
'download' => 300, // 5 minutes
'apply' => 600, // 10 minutes
],
Storage Paths
Ensure paths are absolute and writable. Use Laravel’s storage_path() helper:
'storage' => [
'path' => storage_path('app/ota_updates'),
'temp_path' => sys_get_temp_dir(),
],
Authentication Caching
API tokens may not be cached by default. Configure in config/ota.php:
'auth' => [
'cache_ttl' => 3600, // 1 hour
],
How can I help you explore Laravel packages today?