Separating Object/Payload help (Solved) Thank you all

I have a python script running in a shell node. It works great but I can't figure out how to use the data that I'm getting this is the output in debug

RTD ADC Code: 7627
PT100 Resistance: 100.085754 ohms
Straight Line Approx. Temp: -17.656250 degC
Callendar-Van Dusen Temp (degC > 0): 0.219423 degC
high fault threshold: 32767
low fault threshold: 0

I've added the returns, it comes out as a long line with return arrows.
The only number I need is the Callendar-Van Dusen Temp shown above as 0.219423. How do I pull that single value from the long string?

Thank you in advance!

This is a straight paste from the debug window-

RTD ADC Code: 7627PT100 Resistance: 100.085754 ohmsStraight Line Approx. Temp: -17.656250 degCCallendar-Van Dusen Temp (degC > 0): 0.219423 degChigh fault threshold: 32767low fault threshold: 0```

I've tried to use the splitter, it breaks the message into separate strings but the entire output is in quotes so I'm not sure how to manipulate that.
Here is output after using the split node on it

Callendar-Van Dusen Temp (degC > 0): 0.219423 degC

Again all I would like to use in the number in the above string

Please mark your previous topic as solved.

Now you have the data. Would be best if you would change the source code into json and only print what you need. But ok; you can split it again by : then you will get the value (including the text behind it)

Bakman2
Could you please be more specific? Perhaps an example, I'm very sorry but I don't understand how to do what you just described.

Try this flow:

[{"id":"9d9035e6.34b128","type":"inject","z":"811bc2a8.14b62","name":"","topic":"","payload":"{\"payload\":\"RTD ADC Code: 7627\\n PT100 Resistance: 100.085754 ohms\\n Straight Line Approx. Temp: -17.656250 degC\\n Callendar-Van Dusen Temp (degC > 0): 0.219423 degC\\n high fault threshold: 32767\\n low fault threshold: 0\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":700,"wires":[["1203231e.4c0445"]]},{"id":"13240cc4.beedeb","type":"debug","z":"811bc2a8.14b62","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":410,"y":700,"wires":[]},{"id":"1203231e.4c0445","type":"function","z":"811bc2a8.14b62","name":"","func":"\np = msg.payload.payload\nrow = p.split(/\\r?\\n/)\n\noutput = {}\n\nfor(x=0;x<row.length;x++){\n  input = row[x].split(\":\")\n  output[input[0]] = parseFloat(input[1].trim());  \n}\n\nreturn {payload:output};","outputs":1,"noerr":0,"x":250,"y":700,"wires":[["13240cc4.beedeb"]]}]

Note, in the function node it states msg.payload.payload due to the use of the inject node. Change it to msg.payload and connect your python output to it.

I have removed the units and formatted them to floating numbers.

Wow! Thank you very much! I changed to a singe payload and this is the output, I have no idea why this isn't working. That output looks great though. Any suggestions for how to make it look like yours?

[{"id":"729eef08.31b0d8","type":"pythonshell in","z":"1767a230.5f57b6","name":"Temp working rev 1","pyfile":"/home/pi/MAX31865/max31865.py","virtualenv":"","continuous":true,"stdInData":false,"x":250,"y":200,"wires":[["d6433b43.79d188","7eb2656d.f81d0c"]]},{"id":"160bd057.11d498","type":"debug","z":"1767a230.5f57b6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":200,"wires":[]},{"id":"d6433b43.79d188","type":"function","z":"1767a230.5f57b6","name":"bakman2","func":"\np = msg.payload\nrow = p.split(/\\r?\\n/)\n\noutput = {}\n\nfor(x=0;x<row.length;x++){\n  input = row[x].split(\":\")\n  output[input[0]] = parseFloat(input[1].trim());  \n}\n\nreturn {payload:output};","outputs":1,"noerr":0,"x":460,"y":200,"wires":[["160bd057.11d498"]]},{"id":"7eb2656d.f81d0c","type":"debug","z":"1767a230.5f57b6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":460,"y":260,"wires":[]}]

the error says you can't trim "undefined" so whay is what you are tyring to trim undefined? Look at your code and ask yourself why is it undefined.

In cases like this, I add node.warns to show me variables I am using in the debug. Try
node.warn("input="+input);
right after you define it and see want it is.

wait. did you change the function node as I said ?

Yes I did
!

can you post the full output of the 1st debug node ? and change the debug node to 'complete msg object' (not msg.payload)

I'm not sure if this is correct, it looks the same. Is this the setting to change?

Ok if there is no difference that is fine.
Could you post the full output (in text) ?

TypeError: Cannot read property 'trim' of undefined

TypeError: Cannot read property 'trim' of undefined

The one that is attached to the python script

I just noticed sometimes there are two messages

config register byte: 90RTD ADC Code: 8227
PT100 Resistance: 107.959290 ohmsStraight Line Approx. Temp: 1.093750 degCCallendar-Van Dusen Temp (degC > 0): 20.426748 degChigh fault threshold: 32767low fault threshold: 0

OR a single message like the one below

config register byte: 90RTD ADC Code: 8228PT100 Resistance: 107.972412 ohmsStraight Line Approx. Temp: 1.125000 degCCallendar-Van Dusen Temp (degC > 0): 20.460528 degChigh fault threshold: 32767low fault threshold: 0

Your output has an enter after the last item causing the loop to fail.

Change:

for(x=0;x<row.length;x++){
to
for(x=0;x<row.length-1;x++){

One possible hint for the future: Bakman2's example does a perfect job of splitting up the message into an object, but you may want to simplify the keys ... e.g.

This will strip spaces and special characters from the keys:

key = input[0].replace(/[^a-zA-Z0-9 ]/g, '').trim().split(' ').join('_');
output[key] = parseFloat(input[1].trim());  

After that code change the payload in the message looks like:

{
  "RTD_ADC_Code":7627,
  "PT100_Resistance":100.085754,
  "Straight_Line_Approx_Temp":-17.65625,
  "CallendarVan_Dusen_Temp_degC__0":0.219423,
  "high_fault_threshold":32767,
  "low_fault_threshold":0
}

you're right, i've should have fixed that.

Where should I place the code, should I use the above modification and then use your code? I've tried several different ways and it didn't work, and I'm certain its me. I am very new to this. I've attached a screen shot of bakman2's code. Which lines do I replace?

My Pi just crashed so i have to rebuild everything.

Under input = row[... you put:

key = input[0].replace(/[^a-zA-Z0-9 ]/g, '').trim().split(' ').join('_');

and replace:
output[input[0]].... with:
output[key] = parseFloat(input[1].trim());

and change row.length into row.length-1

That worked. Thank you ! but...

I've used this command before in another flow to remove the extra items that I don't need-

msg.payload = msg.humidity 
return msg;

that strips the number from a multi part message.

I think the parts of this message are different than the above example, with the above, number values are in quotes and red text. I tried this with no luck-

msg.payload = msg.CallendarVan_Dusen_Temp_degC__0
return msg;

It doesn't work. I get this-

How can I get this one number as an output?

Also, how do I find out what the different types of information in the debug output are called? IE What does it mean if the text is purple or red or blue. I'm happy to read up on this myself, I'm not sure what to google to find the answer