Created
November 7, 2016 22:11
-
-
Save wimvds/2e72ed9adca2ac279ba9b729c9e42a28 to your computer and use it in GitHub Desktop.
Onion Omega MQTT publisher client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MqttClient | |
{ | |
private $server; | |
private $port; | |
private $user; | |
private $password; | |
public function __construct($server, $port = 1883, $user = '', $password = '') | |
{ | |
$this->server = $server; | |
$this->port = $port; | |
$this->user = $user; | |
$this->password = $password; | |
} | |
public function publish($topic, $payload) | |
{ | |
exec(sprintf('mosquitto_pub -h %s -p %d -u %s -P %s -t "%s" -m "%s"', $this->server, $this->port, $this->user, $this->password, $topic, $payload)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment