With an array of ASCII values I Node-RED/JS, I need to convert everything into one long string. To handle a varying number of values in the array, I found String.fromCharCode.apply(null, msg.payload); to be great, and my payload is converted as expected - or at least in part.
The payload consists of a number of bools and ints, and a string in the end. The string it output just fine, but the ints and bools (3s and 0s for the time being) are not converted. The array contains 121 ASCII values, but the string output is only ~77 characters long. In other words,
[0,45,83,51,0,0,0,0,1,0,0,0,14,0,202,0,19,162,0,0,0,0,0,0,3,0,3,0,3,0,3,0,3,0,3,0,3,0,3,0,49,53,55,52,48,55,57,54,57,50,56,48,54,48,48,48,48,48,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,80,70,86,32,1,0,0,99,103,114,111,117,112,47,99,32,0,0,0,0,0,0,0,0,0,0,0,0,71,80,82,77,67,44,49,50,50,49,51,50,46,48,48,44,65,44,52,52,52,52,46,50,48,56,48,53,44,78,44,48,48,52,52,52,46,50,55,51,50,51,44,69,44,48,46,48,49,51,44,44,49,56,49,49,49,57,44,44,44,68,42,55,55,13,0,13,0,48,48,48,42,54,68,13,0,50,44,0,0]
is converted into something like
-S3yÆ1574241874748,092421.00,A,1324.56789,N,12345.56789,E,0.024,,201119,,,D*73
while it would expect it to be something like
0,0,0,0,3,3,3,3,3,3,3,3,1574241874748,092421.00,A,1324.56789,N,12345.56789,E,0.024,,201119,,,D*73
Note: -S3yÆ
isn't exactly the output at the beginning, because there is some special character in there (displayed as Æ
, but I don't think it really is, and it also varies and can't be handled by the clipboard). I suspect this is the culprit which needs to be taken care of. There are a lot of null values in the input, and I suspect these are causing fromCharCode
problems.