Hi to Everybody,
I'm slowly learning Node-Red and more than I use it more I lve it, but now I found a problem that I'm not able to solve.
I'm trying to convert a Latitude and Longitude from Numeric value to a Degree and decimal value.
It's just some math.
After my function calc the value I would like to publish a new topic on my MQTT server, it works but Node-Red publish my topic + a 'NaN'
But it happened only on my Mosquito local server, if I try to publish on my cloud server (flespi) it works regurarly.
I cannot understand why.
Here my node:
[{"id":"954e36fc.61cc28","type":"debug","z":"2dedba2a.ed27f6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":180,"wires":[]},{"id":"4315bd8f.f3d934","type":"json","z":"2dedba2a.ed27f6","name":"","property":"payload","action":"","pretty":false,"x":450,"y":140,"wires":[["e03e1031.ca58d"]]},{"id":"e03e1031.ca58d","type":"function","z":"2dedba2a.ed27f6","name":"","func":"\n\nlat = msg.payload.latitude;\nvar convertLat = Math.abs(lat);\nvar LatDeg = Math.floor(convertLat);\nvar LatMin = ((convertLat - LatDeg) * 60).toFixed(3);\nvar LatCardinal = ((lat > 0) ? \"N\" : \"S\");\nnewlat = LatCardinal + \" \" + LatDeg + \"°\" + LatMin;\n\nlon = msg.payload.longitude;\nvar convertLon = Math.abs(lon);\nvar LonDeg = Math.floor(convertLon);\nvar LonMin = ((convertLon - LonDeg) * 60).toFixed(3);\nvar LonCardinal = ((lon > 0) ? \"E\" : \"W\");\nnewlon = LonCardinal + \" \" + LonDeg + \"°\" + LonMin;\n\nmsg.payload = { \n \"longitude\" : newlon,\n \"latitude\" : newlat\n}\nmsg.topic = \"vessels/self/navigation/NewPosition\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":640,"y":140,"wires":[["954e36fc.61cc28","c1fc63e4.3e709"]]},{"id":"c1fc63e4.3e709","type":"mqtt out","z":"2dedba2a.ed27f6","name":"NewPosition","topic":"","qos":"0","retain":"false","broker":"a6ffbe0b.cb31d","x":910,"y":120,"wires":[]},{"id":"b41ea6f.b7b2b58","type":"inject","z":"2dedba2a.ed27f6","name":"test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"vessels/self/navigation/position","payload":"{\"longitude\":174.32633333333334,\"latitude\":-35.72366666666667}","payloadType":"str","x":200,"y":140,"wires":[["4315bd8f.f3d934"]]},{"id":"a6ffbe0b.cb31d","type":"mqtt-broker","z":"","name":"Y2K","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
Thanks in advance
Max