diff --git a/src/Service/MQTTClient.php b/src/Service/MQTTClient.php index f652ca76..79fa9dac 100644 --- a/src/Service/MQTTClient.php +++ b/src/Service/MQTTClient.php @@ -57,14 +57,23 @@ class MQTTClient return; } + $channels = []; + // send to every customer session foreach ($sessions as $sess) { $phone_num = $sess->getPhoneNumber(); $channel = self::PREFIX . $phone_num; - $this->publish($channel, json_encode($payload)); - error_log('sent to ' . $channel); + // gather channels, so we only send once + $channels[$channel] = json_encode($payload); + } + + foreach ($channels as $channel => $json_payload) + { + $this->publish($channel, $json_payload); + + // error_log('sent to ' . $channel); } }