From 1983197c9849dcac9a39c10045b224c1fb588085 Mon Sep 17 00:00:00 2001 From: Benjamin Nussbaum Date: Tue, 4 Mar 2025 18:01:47 +0100 Subject: [PATCH] fix: compatibility with trmnl simulator --- Dockerfile | 2 +- README.md | 14 +++++++++++--- database/factories/DeviceFactory.php | 2 +- routes/api.php | 22 +++++++++++++++++++--- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6b0786e..6bae527 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,7 +44,7 @@ COPY --chown=www-data:www-data . . COPY --chown=www-data:www-data ./.env.example ./.env # Install application dependencies -RUN composer install --no-dev --optimize-autoloader --no-interaction +RUN composer install --no-interaction --prefer-dist --optimize-autoloader RUN npm install && npm run build # Copy configuration files diff --git a/README.md b/README.md index 2445491..c183324 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,22 @@ Inspired by [usetrmnl/byos_sinatra](https://github.com/usetrmnl/byos_sinatra). ![Screenshot](README_byos-screenshot.png) -[More Screenshots](screenshots/SCREENSHOTS.md) +* 👉 [more Screenshots](screenshots/SCREENSHOTS.md) ### Key Features * 📡 Device Information – Display battery status, WiFi strength, firmware version, and more. * 🔍 Auto-Join – Automatically detects and adds devices from your local network. * 🖥️ Screen Generation – Supports Markup, API, or update via Code. -* 🔄 TRMNL API Proxy – Can act as a proxy for TRMNL API (requires TRMNL Developer Edition). +* 🔄 TRMNL API Proxy – Can act as a proxy for the TRMNL Display API (requires TRMNL Developer Edition). * This enables a hybrid setup – for example, you can update your custom Train Monitor every 5 minutes in the morning, while displaying native TRMNL plugins throughout the day. * 🐳 Deployment – Dockerized setup for easier hosting (Dockerfile, docker-compose). +### 🎯 Target Audience + +This project is for developers who are looking for a self-hosted server for devices running the TRMNL firmware. +It serves as a starter kit, giving you the flexibility to build and extend it however you like. + ### Requirements * PHP >= 8.2 @@ -178,7 +183,7 @@ class PluginTrainMonitorFetch extends Command { protected $signature = 'plugin:train:fetch'; - protected $description = 'Command description'; + protected $description = 'Fetches train monitor data and updates the screen'; public function handle(): void { @@ -239,6 +244,9 @@ Here are some features and improvements that are open for contribution: - 🏡 Home Assistant integration - Provide Web UI controls to enable/disable plugins. +##### 📦 Visual Studio Code Devcontainer +* Add a .devcontainer to this repo for easier development with Docker. + ##### Improve Code Coverage - Expand Pest tests to cover more functionality. diff --git a/database/factories/DeviceFactory.php b/database/factories/DeviceFactory.php index eebf0a9..6183cf3 100644 --- a/database/factories/DeviceFactory.php +++ b/database/factories/DeviceFactory.php @@ -18,7 +18,7 @@ class DeviceFactory extends Factory 'mac_address' => $this->faker->macAddress(), 'default_refresh_interval' => '900', 'friendly_id' => Str::random(6), - 'api_key' => 'tD-'.Str::random(19), + 'api_key' => Str::random(22), 'user_id' => 1, 'last_battery_voltage' => $this->faker->randomFloat(2, 3.0, 4.2), 'last_rssi_level' => $this->faker->numberBetween(-100, 0), diff --git a/routes/api.php b/routes/api.php index d89d483..1e4f048 100644 --- a/routes/api.php +++ b/routes/api.php @@ -75,12 +75,28 @@ Route::get('/setup', function (Request $request) { $device = Device::where('mac_address', $mac_address)->first(); if (! $device) { - return response()->json([ - 'message' => 'MAC Address not registered', - ], 404); + // Check if there's a user with assign_new_devices enabled + $auto_assign_user = User::where('assign_new_devices', true)->first(); + + if ($auto_assign_user) { + // Create a new device and assign it to this user + $device = Device::create([ + 'mac_address' => $mac_address, + 'api_key' => Str::random(22), + 'user_id' => $auto_assign_user->id, + 'name' => "{$auto_assign_user->name}'s TRMNL", + 'friendly_id' => Str::random(6), + 'default_refresh_interval' => 900, + ]); + } else { + return response()->json([ + 'message' => 'MAC Address not registered or invalid access token', + ], 404); + } } return response()->json([ + 'status' => '200', 'api_key' => $device->api_key, 'friendly_id' => $device->friendly_id, 'image_url' => url('storage/images/setup-logo.png'),