Unable to remove return carriage from msg

I am receiving a simple msg from a Python code controlling a temperature sensor.
The Python output is stable and doesn't show any carriage return/new line or spaces
I have set a function trying to remove the carriage return but despite many attempts I am failing.
I wonder from where the carriage return is coming, however I would be happy to just remove it.
The function I am using is the following:

var t=msg.payload
t = t.replace(/[\n\r]/g, '')
if(t.length>1)
    return msg
[{"id":"3d0da9a4.5c5796","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"861cf5c7.a8bad8","type":"debug","z":"3d0da9a4.5c5796","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":160,"wires":[]},{"id":"4404f2f3.bf361c","type":"exec","z":"3d0da9a4.5c5796","command":" bash /home/pi/Develop/Temp/Temperature.sh","addpay":"","append":"","useSpawn":"true","timer":"","oldrc":false,"name":"Command Temperature","x":310,"y":200,"wires":[["e8ed8456.02d768"],[],[]]},{"id":"e8ed8456.02d768","type":"function","z":"3d0da9a4.5c5796","name":"","func":"var t=msg.payload\nt = t.replace(/[\\n\\r]/g, '')\nif(t.length>1)\n    return msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":200,"wires":[["6db2d583.4a37fc","861cf5c7.a8bad8"]]},{"id":"6db2d583.4a37fc","type":"influxdb out","z":"3d0da9a4.5c5796","influxdb":"b87cafc6.11924","name":"Digi-Influx","measurement":"temperature","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":720,"y":220,"wires":[]},{"id":"908d862c.149d08","type":"inject","z":"3d0da9a4.5c5796","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":120,"wires":[["4404f2f3.bf361c"]]},{"id":"b87cafc6.11924","type":"influxdb","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"datastorage","name":"","usetls":false,"tls":"","influxdbVersion":"1.x","url":"http://localhost:8086","rejectUnauthorized":true}]

the output I am getting is like this:


Which is causing empty row of data in influx.
Any idea about how to remove the carriage return?

msg.payload=msg.payload.trim()
if(msg.payload)
    return msg

For some reason when I tried that at the beginning, it didn't work.
But now it is working and the issue is solved.
Thanks a million

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