Mosquitto bad request format [message #1836636] |
Sun, 10 January 2021 17:40 |
olivier olivier Messages: 2 Registered: January 2021 |
Junior Member |
|
|
Hi
Thanks to help me to resolve my problem
I tried to publish a mqtt message with php
When i send this command under terminal
mosquitto_pub -h localhost -t aps -m "{\"duration\":"10",\"total\":"12.197575"}"
It's ok 1 topic and 2 different payload
But under php... impossible to publish 2 different payload with the right format...i tried without succes this :
<?php
$c = new Mosquitto\Client;
$c->onConnect(function() use ($c) {
$c->publish('aps/test', "{\"duration\":"10",\"total\":"12.197575"}", 0);
$c->disconnect();
});
$c->connect('localhost');
$c->loopForever(10);
echo "Finished\n";
?>
Do you have an idea ? regards
[Updated on: Sun, 10 January 2021 21:36] Report message to a moderator
|
|
|
|
Re: Mosquitto bad request format [message #1836642 is a reply to message #1836641] |
Sun, 10 January 2021 22:36 |
olivier olivier Messages: 2 Registered: January 2021 |
Junior Member |
|
|
I'm losing myself
with this
<?php
$c = new Mosquitto\Client;
$c->onConnect(function() use ($c) {
$c->publish('aps/test', '{\"duration\":"10",\"total\":"12.197575"}',0);
$c->disconnect();
});
$c->connect('localhost');
$c->loopForever(10);
echo "Finished\n";
?>
I publish one topic with the raw value {\"duration\":"10",\"total\":"12.197575"}
than
mosquitto_pub -h localhost -t aps -m "{\"duration\":"10",\"total\":"12.197575"}"
publish one topic with 2 payload duration and total with the value 10 and 12.19... but in json format
and with this
<?php
$response = '{\"duration\":"10",\"total\":"12.197575"}';
$c = new Mosquitto\Client;
$c->onConnect(function() use ($c) {
$c->publish('aps/test', $response,0);
$c->disconnect();
});
$c->connect('localhost');
$c->loopForever(10);
echo "Finished\n";
?>
publish one topic but no value...or payload
[Updated on: Sun, 10 January 2021 22:37] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04007 seconds