I have a Power Delivery Unit device connected to my local network, that is controlled by a simple web page and I´m trying to use Laravel Schedule to turn the device on and off at specific times of the day. So I´ve created a PDUController with the following methods: (both approaches work fine)
public function on()
{
return redirect()->away(
"http://192.168.0.100/control_outlet.htm?outlet6=1&outlet7=1&op=0&submit=Apply"
);
}
public function off()
{
return Redirect::to(
"http://192.168.0.100/control_outlet.htm?outlet6=1&outlet7=1&op=1&submit=Apply"
);
}
If you visit the routes:
Route::get('/pdu/on', [PDUController::class, 'on'])->name('pdu.on');
Route::get('/pdu/off', [PDUController::class, 'off'])->name('pdu.off');
Everything works as expected and you can turn the device on or off accordingly. Now when I use the Scheduler on Kernel.php like:
protected function schedule(Schedule $schedule)
{
$schedule->call('App\Http\Controllers\PDUController@on')->everyMinute();
}
It doesn´t work. I know the flow is right, because I can Log::debug() every step of the process correctly, but the device is not receiveing the signal and thus is not turning on. Could you help, please? Thanks!
CodePudding user response:
The Redirect functions return a redirect response to the browser. Since the scheduler runs through Artisan, there is no browser to redirect, so no connection is made. Instead, use the HTTP Client to create a connection to the page.