initial commit

This commit is contained in:
2026-06-23 13:28:38 +07:00
commit 966ed115b2
590 changed files with 111412 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use PhpMqtt\Client\Facades\MQTT;
class PublishToTopic extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'mqtt:publish';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Publish To MQTT topic';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
echo "Publishing to topic...\n";
$message = "Ini dari Backend!";
MQTT::publish('fromAPI', $message);
echo "$message\n";
return Command::SUCCESS;
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use PhpMqtt\Client\Contracts\MqttClient;
use PhpMqtt\Client\Facades\MQTT;
class SubscribeToTopic extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'mqtt:subscribe';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Subscribe To MQTT topic';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
/** @var MqttClient $mqtt */
// $mqtt = MQTT::connection();
// $mqtt->publish('myInTopic', 'foo', 1);
// // $mqtt->subscribe('myInTopic', function (string $topic, string $message) {
// // echo sprintf('Received QoS level 1 message on topic [%s]: %s', $topic, $message);
// // }, 1);
// $mqtt->loop(true);
$mqtt = MQTT::connection();
$mqtt->subscribe('fromMobile', function(string $topic, string $message) {
echo sprintf('Received message on topic [%s]: %s\n',$topic, $message);
});
$mqtt->loop(true);
return Command::SUCCESS;
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* @param Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}