使用队列使用curl运行命令

时间:2019-06-28 00:04:57

标签: php curl arduino yii2

我正在尝试运行命令以将信号发送到arduino设备,以便它可以打开一个led,通过队列进行此过程,将作品推送到队列中,一旦获得他们应该在特定的时间运行它们,它是使用curl方法运行的,但是我不确定如何编写代码。

我使用Sublime Text 3和php运行代码,我尝试使用已经编程的curl运行它,但是认为它不能那样工作,我尝试进行研究并查看是否需要特殊命令将curl与队列结合使用,我发现了这一点:https://github.com/adawley/php-curl-queue,但不确定如何在我的代码中实现它

这是从队列执行作业的代码:     

namespace app\commands;

use Yii;
use app\models\Equipos;
use app\models\EquiposSearch;
use app\models\Horarios_Equipos;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\data\ActiveDataProvider;
use skeeks\yii2\curl;

class HorarioJob extends \yii\base\BaseObject implements 
\yii\queue\JobInterface
{
public $id_equipo;
public $estado;

public function execute($queue)
{
    if ($estado == 1){

        $curl = new curl\Curl();

    $response = $curl->get($equipo->ip.'/gpio/LEDa=ON');

}




    }
}

这是将作业推送到队列中的代码:

<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace app\commands;

use yii\console\Controller;
use yii\console\ExitCode;
use app\models\Horarios_Equipos;


/**
 * This command echoes the first argument that you have entered.
 *
 * This command is provided as an example for you to learn how to create 
 console commands.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
 class HorarioController extends Controller
 {
 /**
 * This command echoes what you have entered as the message.
 * @param string $message the message to be echoed.
 * @return int Exit code
 */
public function actionBuscar()
{
    $hora = date("H").":00".":00";
    $dia = date("N");

    $horarios = Horarios_Equipos::find()->where([
        'hora' => $hora,
        'dia' => $dia,
    ])->all();

    foreach($horarios as $horario)
    {

        //echo $horario->id_equipo."\n";
        //echo $horario->estado."\n";
        //enviar a cola

        \Yii::$app->queue->push(
            new HorarioJob([
                'id_equipo' => $horario->id_equipo,
                'estado' => $horario->estado,

            ])
        );
    }

    return ExitCode::OK;
}

}

运行队列后,arduino设备应将led对应于它从数据库获取的ID,但到目前为止还没有

0 个答案:

没有答案