Skip to content

Instantly share code, notes, and snippets.

@wimvds
Created November 7, 2016 22:11
Show Gist options
  • Save wimvds/2e72ed9adca2ac279ba9b729c9e42a28 to your computer and use it in GitHub Desktop.
Save wimvds/2e72ed9adca2ac279ba9b729c9e42a28 to your computer and use it in GitHub Desktop.
Onion Omega MQTT publisher client
<?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