Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ota Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require c2is/ota
    

    Register the service provider in config/app.php:

    'providers' => [
        C2is\OTA\OTAServiceProvider::class,
    ],
    
  2. 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.

  3. 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);
    }
    

Implementation Patterns

Core Workflows

  1. 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);
    
  2. Delta Updates (Bandwidth Optimization)

    $deltaPatch = OTA::generateDeltaPatch($currentVersion, $newVersion);
    OTA::applyDeltaPatch($deviceId, $deltaPatch);
    
  3. Progress Tracking

    OTA::onProgress(function ($progress) {
        Log::info("Update progress: {$progress}%");
    });
    

Integration Tips

  • 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;
    });
    

Gotchas and Tips

Pitfalls

  1. Binary Data Handling

    • The package may not handle binary data safely by default (e.g., no validation for firmware file integrity).
    • Fix: Add checksum validation before applying updates:
      $checksum = OTA::calculateChecksum($firmwarePath);
      if (!OTA::validateChecksum($checksum, $expectedChecksum)) {
          throw new \Exception("Checksum mismatch!");
      }
      
  2. Device-Specific Quirks

    • Some embedded devices require custom bootloaders or reboot sequences post-update.
    • Fix: Implement a PostUpdateHook interface:
      class CustomPostUpdateHook implements \C2is\OTA\Contracts\PostUpdateHook
      {
          public function execute($deviceId)
          {
              // Device-specific reboot logic
          }
      }
      
  3. Concurrent Update Conflicts

    • Multiple update attempts on the same device may corrupt firmware.
    • Fix: Use Laravel’s locks or a distributed lock manager (e.g., Redis):
      if (Lock::get('ota-'.$deviceId)->block(10)) {
          OTA::applyUpdate($deviceId, $firmwarePath);
          Lock::release('ota-'.$deviceId);
      }
      
  4. Undocumented API Changes

    • The package lacks a changelog or semantic versioning, risking breaking changes.
    • Fix: Fork the repo and pin the version in composer.json:
      "repositories": [
          {
              "type": "vcs",
              "url": "https://github.com/your-fork/OTA.git"
          }
      ],
      "require": {
          "c2is/ota": "dev-your-branch"
      }
      

Debugging

  • 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
    

Extension Points

  1. 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);
        }
    }
    
  2. Plugin System for OTA Protocols Support multiple protocols (HTTP, MQTT, etc.) via a plugin interface:

    interface ProtocolPlugin
    {
        public function sendUpdate($deviceId, $payload);
    }
    
  3. 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');
    });
    
  4. 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));
        }
    }
    

Configuration Quirks

  • 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
    ],
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
croct/coding-standard
croct/plug-php
nqxcode/phpmorphy
boundwize/pyrameter
testo/facade
headercat/phpstan-extension-ide-helper
yosymfony/parser-utils
innmind/black-box
babenkoivan/elastic-migrations
babenkoivan/elastic-adapter
develia/commons
dmstr/symfony-system-resources-bundle
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
renatomarinho/laravel-page-speed
develia/geo-bundle
austinheap/laravel-database-encryption
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle