hi all,
I do have an unexpected result from that code.
var topic = msg.topic;
var deviceName = topic.split("/")[1];
var deviceTopic = topic.split("/")[2];
var deviceList = global.get('mitiiot_devices')||[]; //array
//node.warn(deviceList.length);
if(deviceTopic == "STATE")
{
if(isInArray(deviceList, deviceName))
{
//node.warn(deviceName + " exists already");
}
else
{
//node.warn(deviceName + " not existing");
var ssid = msg.payload.Wifi.SSId;
var bssid = msg.payload.Wifi.BSSId;
tempObj =
{
name: deviceName,
ip:"192.168.188.0",
ssid : ssid,
bssid : bssid
};
deviceList.push(tempObj);
}
}
function isInArray(arr, key)
{
for(var j=0; j<arr.size; j++)
{
tmpObj = arr[j];
if(tmpOj.name == key)
return true;
else
return false;
}
}
result is this
there is a second array wrapping the objects I add. I wanted to push the objects directly to the first array, but it results in array --> array --> object. I cannot see why.
The global array is initialized via config node --> JSON []
mirco