How to convert array byte to ASCII

Hi Colin,

I did a test... comparing the output received via Node-Red and directly from the inverter monitoring app. Here's what I found...

Just focusing on KDY which is Energy today [Wh]. The inverter monitoring application showed...


Then I ran the Node-Red data retrieve function and got the following from the inverter...


EDIT: I also noticed a correlation between PAC=800 and the inverter monitoring app, so the numbers seem to line up, just I think the hexadecimal may be getting in the way.

Focusing on just KDY, if I look at the KDY=5 then it appears to correlate with the inverter monitoring app, although the formatting isn't the same i.e. 5 versus 0.5.

In your opinion, would it be better to try and convert the KDY=?? and KT0=?? to pure decimal, so I am not getting caught by hexadecimal oddities? After that, I can then focus on comparing the numbers between the Node-Red data retrieval and the inverter monitoring app.

Thanks again, Mark

OK, it seems you just have to convert the hex to decimal and divide by 10. The first thing then is to extract the values from the string. Looks like the easiest thing is first to splt on the | characters, select the second part, and then split on the :, again take the second part then split on the ; to get the three parts KDY=5, KT0=5317 and PAC=800. Then each of those can be split on the = to get the individual values. Those can then be converted to decimal numbers and divided by ten. This is not the simplest bit of code so I have done it for you, but please do make sure you understand it and ask about bits you don't.

[{"id":"50c685f.3fe2f7c","type":"inject","z":"bdd7be38.d3b55","name":"test string","topic":"","payload":"{01;FB;29|64:KDY=5;KT0=5317;PAC=800|08BB}","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":244,"y":69,"wires":[["758bea22.9f3d8c"]]},{"id":"758bea22.9f3d8c","type":"function","z":"bdd7be38.d3b55","name":"split","func":"let firstSplit = msg.payload.split(\"|\")\nlet centreSection = firstSplit[1]\nlet valueString = centreSection.split(\":\")[1]\nlet valuesArray = valueString.split(\";\")\nmsg.payload = {}\nfor (let i=0; i<valuesArray.length; i++) {\n    let splitValue = valuesArray[i].split(\"=\")\n    let key = splitValue[0]     // this is \"KDY\" etc\n    let hexValue = splitValue[1]  // this is the hex string for the key\n    let value = parseInt(hexValue,16) / 10  // convert to decimal and divide by 10\n    // now add it to the payload\n    msg.payload[key] = value\n}\nreturn msg;","outputs":1,"noerr":0,"x":383,"y":68,"wires":[["c888f4c0.f0fa98"]]},{"id":"c888f4c0.f0fa98","type":"debug","z":"bdd7be38.d3b55","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":537,"y":68,"wires":[]}]

@gregoinc did that work for you?

Hi Colin,

Apology for not replying. Unfortunately the pandemic has derailed my investigations, having to focus more time on my paying work than fun work :grinning: due to my employer supporting various functions in Australia.

I intend to take a look this weekend time permitting. Hope you and your family are well and keeping ahead of things.

Regards, Mark

Hi All!

Greetings - hope you are well. I came across this topic whilst trying to capture two MQTT messages and output them through UDP message. The JSON looks like this;


If I convert to ASCII, the data looks like:
7B 0D 0A 22 69 64 22 3A 22 7A 74 61 74 7A 5F 64 74 22 2C 0D 0A 22 76 65 72 73 69 6F 6E 22 3A 31 2E 30 2C 0D 0A 22 74 5F 75 6E 69 74 22 3A 22 43 22 2C 0D 0A 22 74 5F 69 6E 5F 61 76 67 22 3A 32 34 2E 31 2C 0D 0A 22 74 5F 6F 75 74 5F 61 76 67 22 3A 32 32 2E 30 2C 0D 0A 22 74 5F 69 6E 22 3A 32 34 2E 32 39 38 2C 0D 0A 22 74 5F 6F 75 74 22 3A 32 32 2E 31 35 30 2C 0D 0A 22 73 65 71 22 3A 32 34 34 36 34 0D 0A 7D

So I receive t_in and t_out though MQTT on topics t_in and t_out. How can I convert the MQTT to ASCII (same as above) and +1 the seq number (till 32768, and the start over - begin with 1).

Hope someone can help - I've spent 10+ hours and it is driving me crazy....


Hi Colin,

Finally managed to find some time over Easter in daylight when the solar inverter was running. First question, how should the code be formatted, it appears to be just one lone line/string of characters, so I am wondering for me to understand what is happening would it be easier to break it down into chunks/sections? Or am I looking at it from the wrong angle?

Also, when I run the code you gave me I get the following output....



But I have no idea what the numbers mean?

Thanks, Mark

I don't understand why you are getting that output, when I click the inject node in my test flow I get this

Do you get something different when you click the inject node?

There is absolutely no way the function node I posted could return the array you have shown. That debug node output is not coming from my function. Use separate debug nodes at each point in the flow and give the debug nodes names so you can see what output is coming from which node.

Hi Colin,

Most likely my lack of knowledge is causing the issues. I will attempt to pictorially show the setup below.

The function with your code is identified below as "Test Code" function...

Inside the function injecting the query to the inverter...

Hope this helps. Let me know if you need more info.

Thanks, Mark

And... Inside the function containing your code...

You appear to have pasted my whole flow into your function node. Instead you need to import it into node red. Mark and Copy it from my post then in Node red from the hamburger menu select import and paste from clipboard (I forget the exact phrase). Then it will appear in your flow. You can test the function using the inject node and then use the function in your flow.

Hi Colin,

Ok, I am a bit embarrassed... but I did say it would be me that would be causing the issues. I have imported the code successfully, tested the 'test string' which gave the correct output to debug. I have joined it to my input from the inverter, so when I have some sunshine tomorrow I will do a test input from the inverter. You have the patience of a saint.

Thanks, Mark

1 Like

Hi Colin,

Did a test this morning... remotely from work. And when I click on 'inject' I get an error, but when I click on test string it works?

Not sure why there's an error, and I am unable to understand why Node-Red is stating msg.payload.split is not a function?

Thanks, Mark

Probably because msg.payload is not a string (probably null or undefined or perhaps something else like an object)

Put a debug node before where that error occurs - inspect the contents.

This is what is coming out of the SolarMax_Connect connection...


After I run it through my convert to ASCII I get this...


Here's the screen capture...

I changed the config, basically placing split after Convert to ASCII and bingo it appears to work.

No Errors... and the numbers look pretty good.


1 Like

Yes, if you want a function to work then you have to give it the data that it is designed to expect.

Point taken, unfortunately my lack of experience with Node-Red is an obvious one :grinning:

Thanks again Colin, your advice and patience is very much appreciated.

Hi gregoinc
could you post the flow for reading the Solarmax data and converting the ASCII code here? Would be a big help for me