1
I’m riding my own payload but he’s coming like this:
{
"mode": "sync",
"messageType": "57cd765743f3f9c473d5",
"messages": [{
"Humidity": "99.1",
"Temperature": "99.2",
"Brightness": "99.3",
"Timestamp": "1999999999"
}]
}
When you should go like this:
{
"mode": "sync",
"messageType": "57cd765743f3f9c473d5",
"messages": [{
"Humidity": 25.7,
"Temperature": 21.5,
"Brightness": 13.0,
"timestamp": 1413100000
}]
}
Code:
//Creates a new Messaging.Message Object and sends it to the HiveMQ MQTT Broker
var publish = function(payload, topic, qos) {
mensagem.Humidity = document.getElementById("humidity").value;
mensagem.Temperature = document.getElementById("temperature").value;
mensagem.Brightness = document.getElementById("brightness").value;
mensagem.Timestamp = document.getElementById("timestamp").value;
pl.messages = new Array();
pl.messages[0] = mensagem;
console.log(JSON.stringify(pl));
//Send your message (also possible to serialize it as JSON or protobuf or just use a string, no limitations)
var message = new Messaging.Message(payload);
message.destinationName = topic;
message.qos = 2;
//message.retained = true;
client.send(message);
}
How do I clean up those "" leftover in mine payload?
What do you mean? Do you want to send an invalid JSON? Because the first value is correct, there are no "quotes left". The second is invalid if you want to test: https://jsonlint.com/
– Renan Gomes
I do not understand... because mode" cannot contain the first " to be "mode"?
– NilsonUehara
Nilson, thanks for your return... The problem is a little bigger than this one. I created a very simple app with 4 screen fields and 4 buttons. The general idea is to put the data on the screen, connect me with my MQTT CLOUD, and the mqtt cloud will save the inputted data on the screen to a table in my SAP HANA database... Testing via the web, when I put the payload below, data is recorded correctly in the table of my SAP HANA database: {mode":"Sync","messageType":"57cd765743f3f9c473d5","messages":[{"Humidity":25.7, "Temperature": 21.5, "Brightness": 13.0, "timestamp":1413100000}]}
– cardealt
Nilson, thanks for your return... The problem is a little bigger than this one. I created a very simple app with 4 screen fields and 4 buttons. The general idea is to put the data on the screen, connect me to my MQTT CLOUD, and the mqtt cloud will save the inputted data on the screen to a table in my SAP HANA database... Testing via the web: putting the payload 2 (generated by my app), records the data in my table ...
– cardealt
Maybe because you are sending the numbers as string.
"foo": "32"
and"foo": 32
are different things. I doubt very much that it has to do with quotation marks.– Renan Gomes
Hummm, but how do I change it? Can you tell me?
– cardealt