moving some scripts, making unsubsribe, disconnect and ending clean
This commit is contained in:
parent
cac1c638b9
commit
f2b24bc0fe
25
moha.php
25
moha.php
@ -156,6 +156,8 @@ $client = new Mosquitto\Client();
|
||||
$client->onConnect('connectResponse');
|
||||
$client->onDisconnect('disconnectResponse');
|
||||
$client->onSubscribe('subscribeResponse');
|
||||
$client->onUnsubscribe('unsubscribeResponse');
|
||||
|
||||
$client->onMessage('message');
|
||||
$client->onLog('logger');
|
||||
$client->onPublish('publishResponse');
|
||||
@ -250,25 +252,30 @@ function loadHooks($dir, &$hookList)
|
||||
|
||||
function endMoha()
|
||||
{
|
||||
global $topics, $nSubscribed ,$client;
|
||||
global $topics, $nSubscribed ,$client, $logFh, $connected;
|
||||
$x = 0;
|
||||
foreach($topics as $topic => $object)
|
||||
/*foreach($topics as $topic => $object)
|
||||
{
|
||||
if ($object->status)
|
||||
{
|
||||
$mid = $client->unsubscribe($topic);
|
||||
$mids[$mid] = $topic;
|
||||
{*/
|
||||
$mid = $client->unsubscribe("#");
|
||||
/*$mids[$mid] = $topic;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
while ($nSubscribed != 0)
|
||||
while ($connected)
|
||||
{
|
||||
//echo $nSubscribed;0x00124b0022ebac5c
|
||||
if ( $x++ > 60) exit (0);
|
||||
if ( $x++ > 60)
|
||||
{
|
||||
$client->disconnect();
|
||||
fclose($logFh);
|
||||
exit (1);
|
||||
}
|
||||
$client->loop();
|
||||
}
|
||||
$client->disconnect();
|
||||
fclose($logFh);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,19 +88,19 @@ function connectResponse($r, $message)
|
||||
{
|
||||
case 0:
|
||||
echo _("Successfull connection") . EOL;
|
||||
return true;
|
||||
$connected = true;
|
||||
break;
|
||||
case 1:
|
||||
echo _("Connection refused : unacceptable protocol version") . EOL;
|
||||
return false;
|
||||
$connected = true;
|
||||
break;
|
||||
case 2:
|
||||
echo _("Connection refused : identifier rejected") . EOL;
|
||||
return false;
|
||||
$connected = true;
|
||||
break;
|
||||
case 3:
|
||||
echo _("Connection refused (broker unavailable )") . EOL;
|
||||
return false;
|
||||
$connected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -116,16 +116,18 @@ function subscribeResponse($mid, $qosCount)
|
||||
|
||||
function unsubscribeResponse($mid)
|
||||
{
|
||||
global $topics, $mids, $nSubscribed;
|
||||
$key = $mids[$mid];
|
||||
echo _("Unsubscribed from ") . $topics[$key]->name . EOL;
|
||||
$topics[$key]->status = false;
|
||||
$nSubscribed -= 1;
|
||||
global $client; //$topics, $mids, $nSubscribed;
|
||||
//$key = $mids[$mid];
|
||||
echo _("Unsubscribed"); // from ") . $topics[$key]->name . EOL;
|
||||
//$topics[$key]->status = false;
|
||||
//$nSubscribed -= 1;
|
||||
$client->disconnect();
|
||||
}
|
||||
|
||||
function disconnectResponse($r)
|
||||
{
|
||||
if (! $r)
|
||||
global $connected;
|
||||
if ($r != 0)
|
||||
{
|
||||
echo _('Badly ');
|
||||
}else
|
||||
@ -133,6 +135,7 @@ function disconnectResponse($r)
|
||||
echo _('Cleanly ');
|
||||
}
|
||||
echo _("disconnected from server") . EOL;
|
||||
$connected = false;
|
||||
}
|
||||
|
||||
function publishResponse($mid)
|
||||
|
Loading…
Reference in New Issue
Block a user