Hi,
in a previous post I ask how to find all global variable and it's works perfectly. (List of all global)
the JSON i receive is like this :
{
"payload": [
{
"maison/bureau/temperature": "26.30"
},
{
"maison/bureau/humidity": "57.00"
},
{
"maison/bureau/consigne": 16
}
],
"topic": "uibuilder",
"_msgid": "293c262c7209e491",
"count": 3
}
Now, I need to use thoses variables in the uibuilder side.
I make a function like this :
var humidite;
var temperature;
function variables(json) {
for (i=0;i<json.count;i++){
if (typeof json.payload[i]["maison/bureau/temperature"] === 'undefined'){}else{temperature = json.payload[i]["maison/bureau/temperature"]}
if (typeof json.payload[i]["maison/bureau/humidity"] === 'undefined'){}else{humidite = json.payload[i]["maison/bureau/humidity"]}
}
}
window.onload = function() {
// Start up uibuilder - see the docs for the optional parameters
uibuilder.start()
// Listen for incoming messages from Node-RED
uibuilder.onChange('msg', function(msg){
console.info('[indexjs:uibuilder.onChange] msg received from Node-RED server:', msg)
variables(msg)
})
}
but I don't think it's the better way to do that.
Anybody have a better method?
Thanks