Problem with my thermostat

Hey,

I have trouble with my thermostat. I mean it is working kind of. I can turn it on and off or I can set the temperature. I use phpMQTT and simple php script to listen to onoff and to tempset-setpoint. I have two scripts, one for each and my problem is that when they both running then most of my requests go missing. Google Assistant thinks yeah okay Im doing it but roughly 3 out 4 times I receive nothing. If only one script is running then it works flawlessly. (at moment I left only set temperature script running as I can always turn temperature down and my system automatically switches radiator off but this is not the way it should be)

Am I doing something wrong ? I heard letters mqtt just about week ago and I am still getting my head around it :slight_smile: so there’s huge chance Im doing something wrong … can somebody direct me to right path :).

Hi.
Can you try to print out what each script is receiving, it sounds a little like one script is stealing all messages.
Wiken

yep, actually that was my first step to troubleshoot the problem … I made both script to print what they get with time and date and that was the moment I noticed it. when they both run then if they get a message they get the message they suppose to get … it doesnt seem that they steal message from each other.

I will add my change temperature php script, maybe there’s some obvious flaw that I just cant see.

error_reporting(E_ALL);

ini_set(‘display_errors’, 1);

ini_set(‘date.timezone’, ‘Europe/Berlin’);
require("/var/www/lib/phpMQTT.php");
$test = “mqtt://gbridge-xxxxxx:[email protected]:1883/gBridge/xxxxxxx/xxxxxxx/tempset-setpoint”;
$url = parse_url($test);
$topic = substr($url[‘path’], 1);
$client_id = “phpMQTT-subscriber”;

function procmsg($topic, $msg){
echo date(‘Y-m-d H:i:s’) . " - recieved: $msg\n";

// updating gBridge
$server = “mqtt.gbridge.io”; // change if necessary
$port = 1883; // change if necessary
$username = “xxxxxxxxx”; // set your username
$password = “xxxxxxxxx”; // set your password
$client_id2 = “phpMQTT-publisher”; // make sure this is unique for connecting to sever - you could use uniqid()
$mqtt2 = new phpMQTT($server, $port, $client_id2);
if ($mqtt2->connect(true, NULL, $username, $password)) {
$mqtt2->publish(‘gBridge/xxxxxxx/xxxxxx/tempset-setpoint/set’, $msg, 0);
$mqtt2->close();
} else {
echo date(‘Y-m-d H:i:s’) . " - mqtt time out! or something\n";
}
// updating sql
$host = “luna.sabru.lan”;
$user = “xxxxxx”;
$pass = “xxxxxx”;
$database = “smartroom_2b”;
$con=mysqli_connect($host,$user,$pass,$database);
if (mysqli_connect_errno()) echo “Failed to connect to MySQL: " . mysqli_connect_error();
$queryline = “UPDATE rooms SET desiredtemp=” . $msg . " WHERE nr=1”;
mysqli_query($con, $queryline);
$queryline = “INSERT INTO logs VALUES(’” . date(‘Y-m-d H:i:s’) . “’, 0, 3, ‘setting new desired temp in bedroom to " . $msg . "C by google(via gBridge)’)”;
mysqli_query($con, $queryline);
mysqli_close($con);
}

$mqtt = new phpMQTT($url[‘host’], $url[‘port’], $client_id);
if ($mqtt->connect(true, NULL, $url[‘user’], $url[‘pass’])) {
$topics[$topic] = array(
“qos” => 0,
“function” => “procmsg”
);
$mqtt->subscribe($topics,0);
while($mqtt->proc()) {}
$mqtt->close();
} else {
exit(1);
}

?>

I kind of same type of script to control on and off … and problem is when I run those 2 scripts at same time, my requests start going missing. Anybody, any ideas ?

I solved the problem.

the simple answer is that phpMQTT is just bad idea :slight_smile:

I switched to mosquitto php client and everything started working :slight_smile: