Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Mosquitto » Mosquitto bad request format
Mosquitto bad request format [message #1836636] Sun, 10 January 2021 17:40 Go to next message
olivier olivier is currently offline olivier olivierFriend
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 #1836641 is a reply to message #1836636] Sun, 10 January 2021 21:22 Go to previous messageGo to next message
Roger Light is currently offline Roger LightFriend
Messages: 90
Registered: September 2013
Member
$c->publish('aps/test', "{\"duration\":"10",\"total\":"12.197575"}", 0);


It looks like you are missing some escaping on the quotes around "12.197575".

Regards,

Roger
Re: Mosquitto bad request format [message #1836642 is a reply to message #1836641] Sun, 10 January 2021 22:36 Go to previous message
olivier olivier is currently offline olivier olivierFriend
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

Previous Topic:Failed to start Mosquitto MQTT
Next Topic:User Authentification (limited IP-Addresses only)
Goto Forum:
  


Current Time: Fri Apr 19 05:13:46 GMT 2024

Powered by FUDForum. Page generated in 0.01966 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top