Global Variables i.e V1 V2 have the same content

//msg.payload format = { voltages: , temps: , SOC : , SOH:, STATUS: ,PACK_V : , PACK_I : , BTEMP:} ;
Npacks = global.get("No_of_packs") ;

data = msg.payload ;
flow.set("data2",data);
acsii = 97 ;
var pack = {} ;
bats =
{

    "id": -1,
    "RATEDCAP_AH":-1,
    "Max_V": 0,
    "Max_I": 0,
    "Bat_V": 0,
    "Bat_I": 0,
    "SOC":-1,
    "SOH":-1,
    "Cells_V": [],
    "PCB_TEMP": [],
    "EXT_TEMP": [],
    "Serial_No": "",
    "RUNNING_TIME_MIN" : 0 ,
    "STATUS":"",
    "LAST_DATA":""

};

for (i=0 ; i < Npacks ;i++) {
datav = ;
pack = {} ;

if (global.get("Bat0"+(i+1))==undefined) {
    global.set("Bat0"+(i+1) , bats);  
   }

h = (i+1) ;
h = h.toString() ;
pack = global.get("Bat0"+h ) ;
node.warn(data.voltages[i]) ; // this shows the correct data
node.warn(i);
datav = data.voltages[i] ; // this seems to set the same value in both batteries and not the correct value
pack.Cells_V = datav ;
pack.id= (i+1)*10 ; // id is set to tha same on both packs ????
node.warn(pack) ;

}

return msg;

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.