You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
554 B

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\TaskWorker;
  4. use App\Libs\MQTTClient;
  5. use Hyperf\Task\Annotation\Task;
  6. class MQTTClientTask
  7. {
  8. protected $mqttClient = null;
  9. /**
  10. * @Task
  11. */
  12. public function getClient()
  13. {
  14. $this->mqttClient = new MQTTClient(env('MQTT_HOST'), env('MQTT_PORT'));
  15. $this->mqttClient->setAuthentication(env('MQTT_NAME'), env('MQTT_PASS'));
  16. if (env('MQTT_CERT')) {
  17. $this->mqttClient->setEncryption(env('MQTT_CERT'));
  18. }
  19. return $this->mqttClient;
  20. }
  21. }