# Kostal Plenticore MODBUS LE Code to start charge from grid code

**URL:** <https://discourse.nodered.org/t/kostal-plenticore-modbus-le-code-to-start-charge-from-grid-code/72601>\
**Category:** General\
**Tags:** modbus, function-node\
**Created:** [22 December 2022 19:25 UTC](https://discourse.nodered.org/t/kostal-plenticore-modbus-le-code-to-start-charge-from-grid-code/72601 "2022-12-22T19:25:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gutein](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gutein/32/73019_2.png) [@Gutein](https://discourse.nodered.org/u/Gutein)\
**Post date:** [22 December 2022 19:25 UTC](https://discourse.nodered.org/t/kostal-plenticore-modbus-le-code-to-start-charge-from-grid-code/72601/1 "2022-12-22T19:25:38Z")

</div>

Hi there. Im trying to figure out how I can start and stop charg 5000w from grid to send a Little-endian in json and run it in Nod-Red to my BYD battery. Any suggestions?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/96ca665cc496c4445398491a59c1433e81bde2a7.jpeg)

Here is a jason code that works in BE but not in LE please help!

[  
{  
"id": "e6ebc9556a4f754e",  
"type": "function",  
"z": "2aa9d19d.92731e",  
"name": "Lad Kostan 5kw",  
"func": "var fc = 16;\nvar sa = 1034;\nvar addresses = 2;\nvar value = -5000;\nbuf = Buffer.alloc(4);\nbuf.writeFloatBE(value);\n//buf.writeFloatBE(-5000);\nvar values = [(buf[0] \* 256 + buf[1]), (buf[2] \* 256) + buf[3]]\nmsg.slave\_ip = "192.168.0.117";\nmsg.payload = { "value": values, 'fc': fc, 'unitid': 71, 'address': sa, 'quantity': addresses };\nreturn msg;",  
"outputs": 1,  
"noerr": 6,  
"initialize": "",  
"finalize": "",  
"libs": ,  
"x": 840,  
"y": 1780,  
"wires": [  
[  
"44d268e917f21846"  
]  
]  
},  
{  
"id": "44d268e917f21846",  
"type": "modbus-flex-write",  
"z": "2aa9d19d.92731e",  
"name": "Write It",  
"showStatusActivities": false,  
"showErrors": false,  
"server": "3da3c5245580e30a",  
"emptyMsgOnFail": false,  
"keepMsgProperties": false,  
"x": 1020,  
"y": 1780,  
"wires": [  
,  
  
]  
},  
{  
"id": "add8a27e9551ee3e",  
"type": "function",  
"z": "2aa9d19d.92731e",  
"name": "Stop batteri",  
"func": "var fc = 16;\nvar sa = 1034;\nvar addresses = 2;\nvar value = 0;\nbuf = Buffer.alloc(4);\nbuf.writeFloatBE(value);\n//buf.writeFloatBE(0);\nvar values = [(buf[0] \* 256 + buf[1]), (buf[2] \* 256) + buf[3]]\nmsg.slave\_ip = "192.168.0.117";\nmsg.payload = { "value": values, 'fc': fc, 'unitid': 71, 'address': sa, 'quantity': addresses };\nreturn msg;",  
"outputs": 1,  
"noerr": 6,  
"initialize": "",  
"finalize": "",  
"libs": ,  
"x": 870,  
"y": 1700,  
"wires": [  
[  
"44d268e917f21846"  
]  
]  
},  
{  
"id": "3da3c5245580e30a",  
"type": "modbus-client",  
"name": "Kostal",  
"clienttype": "tcp",  
"bufferCommands": true,  
"stateLogEnabled": true,  
"queueLogEnabled": false,  
"failureLogEnabled": true,  
"tcpHost": "192.168.0.117",  
"tcpPort": "1502",  
"tcpType": "DEFAULT",  
"serialPort": "/dev/ttyUSB",  
"serialType": "RTU-BUFFERD",  
"serialBaudrate": "9600",  
"serialDatabits": "8",  
"serialStopbits": "1",  
"serialParity": "none",  
"serialConnectionDelay": "100",  
"serialAsciiResponseStartDelimiter": "0x3A",  
"unit\_id": 71,  
"commandDelay": 1,  
"clientTimeout": 1000,  
"reconnectOnTimeout": true,  
"reconnectTimeout": 2000,  
"parallelUnitIdsAllowed": true  
}  
]

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [22 December 2022 20:39 UTC](https://discourse.nodered.org/t/kostal-plenticore-modbus-le-code-to-start-charge-from-grid-code/72601/2 "2022-12-22T20:39:02Z")

</div>

first use Ctrl+E for Code.  
second use correct code, not squares symbols !

what do you want with 1076+1078 ?  
you can't do anything with it.

you´ll need 1024 to set power manually.

> 1024 Battery charge power (AC) setpoint Note1,6  
> Negative values will charge the battery, positive values will discharge the battery.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 December 2022 13:07 UTC](https://discourse.nodered.org/t/kostal-plenticore-modbus-le-code-to-start-charge-from-grid-code/72601/4 "2022-12-23T13:07:23Z")

</div>

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![Gutein](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gutein/32/73019_2.png) [@Gutein](https://discourse.nodered.org/u/Gutein)\
**Post date:** [27 December 2022 08:50 UTC](https://discourse.nodered.org/t/kostal-plenticore-modbus-le-code-to-start-charge-from-grid-code/72601/5 "2022-12-27T08:50:59Z")

</div>

```auto
var fc = 16;
var sa = 1034;
var addresses = 2;
var value = 0;
buf = Buffer.alloc(4);
buf.writeFloatBE(value);
//buf.writeFloatBE(0);
var values = [(buf[0] * 256 + buf[1]), (buf[2] * 256) + buf[3]]
msg.slave_ip = "192.168.10.12";
msg.payload = { "value": values, 'fc': fc, 'unitid': 71, 'address': sa, 'quantity': addresses };
return msg;

var fc = 16;
var sa = 1034;
var addresses = 2;
var value = -5000;
buf = Buffer.alloc(4);
buf.writeFloatBE(value);
//buf.writeFloatBE(-5000);
var values = [(buf[0] * 256 + buf[1]), (buf[2] * 256) + buf[3]]
msg.slave_ip = "192.168.10.12";
msg.payload = { "value": values, 'fc': fc, 'unitid': 71, 'address': sa, 'quantity': addresses };
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:** [16 January 2023 09:38 UTC](https://discourse.nodered.org/t/kostal-plenticore-modbus-le-code-to-start-charge-from-grid-code/72601/6 "2023-01-16T09:38:42Z")

</div>

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