I've got a solar inverter that I'd like to log to influxdb / grafana. I found a program on github by an author with a similar model to mine. The comms protocols are the same, as are many of the queried parameters, but mine is a newer model with I think more parameters being returned. The program queries the inverter and dumps the serial buffer to stdout, and I'm successfully pulling the string output into node-red.
My first problem was that an 0x0 was being returned for one of the parameters. I thought I had solved that one with a function I found searching here (see function "Replace 0x0), but now I'm getting an "Unexpected end of JSON input" and my msg,payload stops at the spot where the 0x0 was.
Here's the payload straight out of stdout:
And this is where it stops when functions are applied:
I've also got a lot of extra values being sent by the inverter at the end of the payload. I'm pretty sure these are parameter values that the github author doesn't know about yet. How can I trim the end of the payload string where it's recognizable JSON and I can parse the string and make it suitable for influxdb?
Here's my flow:
flows.json (2.9 KB)
[
{
"id": "2ac97eb7.c68992",
"type": "tab",
"label": "Flow 10",
"disabled": false,
"info": ""
},
{
"id": "6efa58aa.fa188",
"type": "exec",
"z": "2ac97eb7.c68992",
"command": "bash /home/pi/inverter.sh",
"addpay": true,
"append": "-u",
"useSpawn": "false",
"timer": "15",
"oldrc": false,
"name": "",
"x": 230,
"y": 200,
"wires": [
[
"16c80eb2.5bed29",
"7826834a.309314"
],
[],
[]
]
},
{
"id": "1a126ecb.1d5ac9",
"type": "debug",
"z": "2ac97eb7.c68992",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 910,
"y": 240,
"wires": []
},
{
"id": "ba80ce4b.495fe",
"type": "inject",
"z": "2ac97eb7.c68992",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": "0.1",
"x": 120,
"y": 120,
"wires": [
[
"6efa58aa.fa188"
]
]
},
{
"id": "5b024b1a.f178ac",
"type": "json",
"z": "2ac97eb7.c68992",
"name": "",
"property": "payload",
"action": "str",
"pretty": true,
"x": 770,
"y": 240,
"wires": [
[
"1a126ecb.1d5ac9"
]
]
},
{
"id": "b894d2a.bc4833",
"type": "function",
"z": "2ac97eb7.c68992",
"name": "convert",
"func": "msg.payload = msg.payload.toString('utf8');\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 620,
"y": 240,
"wires": [
[
"5b024b1a.f178ac"
]
]
},
{
"id": "16c80eb2.5bed29",
"type": "debug",
"z": "2ac97eb7.c68992",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 910,
"y": 200,
"wires": []
},
{
"id": "7826834a.309314",
"type": "function",
"z": "2ac97eb7.c68992",
"name": "Replace 0x0",
"func": "var zeroIndex = msg.payload.indexOf(0)\nvar newBuffer = Buffer.allocUnsafe(zeroIndex);\nmsg.payload.copy(newBuffer,0,0,zeroIndex)\nmsg.payload = newBuffer.toString();\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 450,
"y": 240,
"wires": [
[
"b894d2a.bc4833"
]
]
}
]