# Global Variables i.e V1 V2 have the same content

**URL:** <https://discourse.nodered.org/t/global-variables-i-e-v1-v2-have-the-same-content/60844>\
**Category:** General\
**Created:** [5 April 2022 18:40 UTC](https://discourse.nodered.org/t/global-variables-i-e-v1-v2-have-the-same-content/60844 "2022-04-05T18:40:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Discourse01](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Discourse01](https://discourse.nodered.org/u/Discourse01)\
**Post date:** [5 April 2022 18:40 UTC](https://discourse.nodered.org/t/global-variables-i-e-v1-v2-have-the-same-content/60844/1 "2022-04-05T18:40:08Z")

</div>

[//msg.payload](https://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;

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 June 2022 18:40 UTC](https://discourse.nodered.org/t/global-variables-i-e-v1-v2-have-the-same-content/60844/2 "2022-06-04T18:40:50Z")

</div>

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