Hi, I'm new to Node-Red, programming and scripting but giving it a go. I'm creating a dashboard using serial data published by an Autonomous Underwater Vehicle operator station. I have all the data coming into Node-Red via MQTT and the dashboard works fine.
I have the position of the AUV plotting on Worldmap, but I would like a button to centre worldmap to the AUV position. I have a button and a function to send the msg.payload.command to worldmap but it recentres every time a position is received from the AUV not just once on the button push.
New to all this so...
[{"id":"7165bf62.19b6b","type":"tab","label":"Skandi Voyager 1","disabled":false,"info":""},{"id":"8a1c8231.17436","type":"mqtt-broker","name":"Mosquitto","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"745e09e9.481608","type":"ui_group","name":"Vehicle Status","tab":"5fea9caf.1021e4","order":1,"disp":true,"width":6,"collapse":false},{"id":"5fea9caf.1021e4","type":"ui_tab","name":"Telemetry","icon":"fa-tachometer","disabled":false,"hidden":false},{"id":"5d3f9b57.bac984","type":"ui_base","theme":{"name":"theme-dark","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#097479","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#4B7930","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"},"themeState":{"base-color":{"default":"#097479","value":"#097479","edited":false},"page-titlebar-backgroundColor":{"value":"#097479","edited":false},"page-backgroundColor":{"value":"#111111","edited":false},"page-sidebar-backgroundColor":{"value":"#333333","edited":false},"group-textColor":{"value":"#0eb8c0","edited":false},"group-borderColor":{"value":"#555555","edited":false},"group-backgroundColor":{"value":"#333333","edited":false},"widget-textColor":{"value":"#eeeeee","edited":false},"widget-backgroundColor":{"value":"#097479","edited":false},"widget-borderColor":{"value":"#333333","edited":false},"base-font":{"value":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"}},"angularTheme":{"primary":"indigo","accents":"blue","warn":"red","background":"grey"}},"site":{"name":"Skandi Voyager 1 Dashboard","hideToolbar":"false","allowSwipe":"false","lockMenu":"true","allowTempTheme":"true","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":48,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}}},{"id":"e358a481.2a6548","type":"ui_group","name":"Vehicle Depth","tab":"5fea9caf.1021e4","order":2,"disp":true,"width":6,"collapse":false},{"id":"edfed5e5.e354d8","type":"ui_group","name":"Vehicle Battery Status","tab":"5fea9caf.1021e4","order":3,"disp":true,"width":6,"collapse":false},{"id":"79041bf8.4ac394","type":"ui_group","name":"Vehicle Speed","tab":"5fea9caf.1021e4","order":4,"disp":true,"width":6,"collapse":false},{"id":"30fafac4.672706","type":"ui_tab","name":"Map","icon":"fa-map","disabled":false,"hidden":false},{"id":"fb6e5f97.c4b4a","type":"ui_group","name":"Map View","tab":"30fafac4.672706","order":1,"disp":false,"width":24,"collapse":false},{"id":"3641848f.051f0c","type":"mqtt in","z":"7165bf62.19b6b","name":"Depth","topic":"depth","qos":"2","datatype":"auto","broker":"8a1c8231.17436","x":130,"y":180,"wires":[["c8f22cfe.2e3a2"]]},{"id":"3373e0a5.c9509","type":"mqtt in","z":"7165bf62.19b6b","name":"Mission State","topic":"mission_state","qos":"2","datatype":"auto","broker":"8a1c8231.17436","x":150,"y":60,"wires":[["e2e564ee.1773e8"]]},{"id":"d03f3519.b65838","type":"mqtt in","z":"7165bf62.19b6b","name":"Altitude","topic":"altitude","qos":"2","datatype":"auto","broker":"8a1c8231.17436","x":130,"y":320,"wires":[["cf009277.c67a6","8ce88019.36a24"]]},{"id":"4e10901.8d39c7","type":"mqtt in","z":"7165bf62.19b6b","name":"Speed","topic":"speed","qos":"2","datatype":"auto","broker":"8a1c8231.17436","x":130,"y":380,"wires":[["19958963.715c37"]]},{"id":"6dcc0e7c.06ecd","type":"mqtt in","z":"7165bf62.19b6b","name":"Battery Voltage","topic":"voltage","qos":"2","datatype":"auto","broker":"8a1c8231.17436","x":160,"y":440,"wires":[["2d6bccdd.2e5844","3d56016d.9c1f4e"]]},{"id":"11927004.75e8","type":"mqtt in","z":"7165bf62.19b6b","name":"Remaining Battery","topic":"batterytime","qos":"2","datatype":"utf8","broker":"8a1c8231.17436","x":170,"y":500,"wires":[["5f63faa2.198d84"]]},{"id":"1246ed37.9a5c23","type":"ui_text","z":"7165bf62.19b6b","group":"745e09e9.481608","order":1,"width":0,"height":0,"name":"Mission State","label":"Mission State:","format":"{{msg.payload}}","layout":"row-left","x":740,"y":60,"wires":[]},{"id":"714f570e.ae4e28","type":"ui_text","z":"7165bf62.19b6b","group":"745e09e9.481608","order":4,"width":0,"height":0,"name":"Depth","label":"Depth:","format":"{{msg.payload}}m","layout":"row-left","x":710,"y":180,"wires":[]},{"id":"cf009277.c67a6","type":"ui_text","z":"7165bf62.19b6b","group":"745e09e9.481608","order":5,"width":0,"height":0,"name":"Altitude","label":"Altitude:","format":"{{msg.payload}}m","layout":"row-left","x":720,"y":320,"wires":[]},{"id":"94294858.8ce7f8","type":"ui_text","z":"7165bf62.19b6b","group":"745e09e9.481608","order":6,"width":0,"height":0,"name":"Speed","label":"Speed:","format":"{{msg.payload}} Knots","layout":"row-left","x":710,"y":380,"wires":[]},{"id":"2d6bccdd.2e5844","type":"ui_text","z":"7165bf62.19b6b","group":"745e09e9.481608","order":7,"width":0,"height":0,"name":"Battery Voltage","label":"Battery Voltage:","format":"{{msg.payload}}V","layout":"row-left","x":740,"y":440,"wires":[]},{"id":"3197281.4c373d8","type":"ui_text","z":"7165bf62.19b6b","group":"745e09e9.481608","order":8,"width":0,"height":0,"name":"Remaining Battery","label":"Remaining Battery:","format":"{{msg.payload}}","layout":"row-left","x":750,"y":500,"wires":[]},{"id":"652c09b5.645008","type":"ui_gauge","z":"7165bf62.19b6b","name":"Depth","group":"e358a481.2a6548","order":1,"width":0,"height":0,"gtype":"gage","title":"Depth","label":" Meters","format":"{{value}}","min":0,"max":"3000","colors":["#ff0000","#00ff11","#ca3838"],"seg1":"100","seg2":"2950","x":910,"y":180,"wires":[]},{"id":"8ce88019.36a24","type":"ui_gauge","z":"7165bf62.19b6b","name":"Altitude","group":"e358a481.2a6548","order":2,"width":0,"height":0,"gtype":"gage","title":"Altitude","label":" Meters","format":"{{value}}","min":"0","max":"60","colors":["#ff0000","#e6e600","#2bff00"],"seg1":"5","seg2":"10","x":920,"y":320,"wires":[]},{"id":"67e1af40.14b08","type":"ui_gauge","z":"7165bf62.19b6b","name":"Speed","group":"79041bf8.4ac394","order":1,"width":0,"height":0,"gtype":"gage","title":"Speed","label":"Knots","format":"{{value}}","min":"0","max":"5","colors":["#ff0000","#04ff00","#f50000"],"seg1":"2","seg2":"4.5","x":910,"y":380,"wires":[]},{"id":"3d56016d.9c1f4e","type":"ui_gauge","z":"7165bf62.19b6b","name":"Battery Voltage","group":"edfed5e5.e354d8","order":1,"width":0,"height":0,"gtype":"gage","title":"Voltage","label":"Volts","format":"{{value}}","min":"35","max":"50","colors":["#ff0000","#e6e600","#1eff00"],"seg1":"30.5","seg2":"41.5","x":940,"y":440,"wires":[]},{"id":"650ad0ec.30259","type":"ui_gauge","z":"7165bf62.19b6b","name":"BatteryTime","group":"edfed5e5.e354d8","order":2,"width":0,"height":0,"gtype":"gage","title":"Remaining Battery Time","label":"hh:mm:ss","format":"{{msg.payload}}","min":"0","max":"30","colors":["#f40101","#e6e600","#3acb3e"],"seg1":"3","seg2":"6","x":930,"y":500,"wires":[]},{"id":"5b092d55.0706b4","type":"ui_worldmap","z":"7165bf62.19b6b","group":"fb6e5f97.c4b4a","order":1,"width":24,"height":11,"name":"","lat":"","lon":"","zoom":"","layer":"OSM","cluster":"","maxage":"","usermenu":"show","layers":"show","panit":"true","panlock":"false","zoomlock":"false","hiderightclick":"true","coords":"none","showgrid":"false","allowFileDrop":"false","path":"/worldmap","x":1860,"y":1740,"wires":[]},{"id":"29d5f1c3.0546fe","type":"mqtt in","z":"7165bf62.19b6b","name":"Lat","topic":"latitude","qos":"2","datatype":"auto","broker":"8a1c8231.17436","x":130,"y":560,"wires":[["3c065b1.b96c3a4"]]},{"id":"9f01fd55.81eb4","type":"mqtt in","z":"7165bf62.19b6b","name":"Long","topic":"longitude","qos":"2","datatype":"auto","broker":"8a1c8231.17436","x":130,"y":620,"wires":[["34a38352.6013ec"]]},{"id":"9c3f3ae3.549d68","type":"ui_text","z":"7165bf62.19b6b","group":"745e09e9.481608","order":9,"width":0,"height":0,"name":"Lat","label":"Latitude:","format":"{{msg.payload.lat}}","layout":"row-left","x":710,"y":560,"wires":[]},{"id":"437be6b8.f02bc8","type":"ui_text","z":"7165bf62.19b6b","group":"745e09e9.481608","order":10,"width":0,"height":0,"name":"Long","label":"Longitude:","format":"{{msg.payload.lon}}","layout":"row-left","x":710,"y":620,"wires":[]},{"id":"5f63faa2.198d84","type":"function","z":"7165bf62.19b6b","name":"HH:MM:SS","func":"// Time HH:MM:SS from number\n\n// Hours\nvar Hours = ((msg.payload)/3600);\nHours = Math.floor(Hours);\n\n// Minutes\nvar Minutes = (msg.payload-(Hours*3600))/60;\nMinutes = Math.floor(Minutes);\n\n// Seconds\nSeconds = (msg.payload-(Hours*3600)-(Minutes*60));\n\n// Concatenate\nvar Time = ('0' +Hours).slice(-2)+':'+('0' +Minutes).slice(-2)+':'+('0' +Seconds).slice(-2);\n\nmsg.payload = Time;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":500,"wires":[["3197281.4c373d8","650ad0ec.30259"]]},{"id":"e2e564ee.1773e8","type":"function","z":"7165bf62.19b6b","name":"State","func":"var payload = msg.payload;\nif (payload == \"M\") {\n msg.payload = \"Mission\";\n} else if (payload == \"C\") {\n msg.payload = \"Configuration\";\n} else if (payload == \"A\") {\n msg.payload = \"Armed\";\n} else if (payload == \"E\") {\n msg.payload = \"Emergency Ascent\";\n} else if (payload == \"S\") {\n msg.payload = \"Ascent\";\n} else if (payload == \"P\") {\n msg.payload = \"Predicted\";\n} else if (payload == \"O\") {\n msg.payload = \"Other\";\n} else {\n msg.payload = char(payload);\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":60,"wires":[["1246ed37.9a5c23"]]},{"id":"c8f22cfe.2e3a2","type":"delay","z":"7165bf62.19b6b","name":"","pauseType":"rate","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":500,"y":180,"wires":[["714f570e.ae4e28","652c09b5.645008"]]},{"id":"19958963.715c37","type":"function","z":"7165bf62.19b6b","name":"Knots","func":"msg.payload = (msg.payload*1.944).toFixed(1);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":380,"wires":[["94294858.8ce7f8","67e1af40.14b08"]]},{"id":"3c065b1.b96c3a4","type":"function","z":"7165bf62.19b6b","name":"S to -","func":"message0 = {};\nmessage1 = {};\n\nvar symblat = \"\";\n\nmsg.string = msg.payload.split(\",\");\n\n//Find if latitude is south and add minus\nif (msg.string[1] == \"S\") {\nsymblat = \"-\";\n} else {\n\n}\n\nmsg.payload = {\nname:\"Lat position\",\nlat: symblat + msg.string[0],\n}\n\nreturn [msg];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":560,"wires":[["9c3f3ae3.549d68"]]},{"id":"34a38352.6013ec","type":"function","z":"7165bf62.19b6b","name":"W to -","func":"message0 = {};\nmessage1 = {};\n\nvar symblon = \"\";\n\nmsg.string = msg.payload.split(\",\");\n\n//Find if longitude is south and add minus\nif (msg.string[1] == \"W\") {\nsymblon = \"-\";\n} else {\n\n}\n\nmsg.payload = {\nname:\"Long position\",\nlon: symblon + msg.string[0],\n}\n\nreturn [msg];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":620,"wires":[["437be6b8.f02bc8"]]},{"id":"1fb15ce7.0cf533","type":"mqtt in","z":"7165bf62.19b6b","name":"Position","topic":"position","qos":"2","datatype":"auto","broker":"8a1c8231.17436","x":130,"y":680,"wires":[["a067a031.98f72"]]},{"id":"1df84317.28f25d","type":"function","z":"7165bf62.19b6b","name":"AUV Position","func":"message0 = {};\nmessage1 = {};\nmessage2 = {};\nmessage3 = {};\nmessage4 = {};\n\nvar symblat = \"\";\nvar symblong = \"\";\n\n\nmsg.string = msg.payload.split(\",\");\n\n//Find if latitude is south and add minus\nif (msg.string[1] == \"S\") {\nsymblat = \"-\";\n} else {\n\n}\n\n//Find if longitude is west and add minus\nif (msg.string[3] == \"W\") {\nsymblong = \"-\";\n} else {\n\n}\n\nmsg.payload = {\nname:\"SV1\",\nlat: symblat + msg.string[0],\nlon: symblong + msg.string[2],\nradius:\"3\",\nlayer: \"AUV\",\nicon: \"fa-ship\"\n\n}\nvar globalposition = {};\nglobalposition.lat = symblat + msg.string[0];\nglobalposition.lon = symblong + msg.string[2];\nglobal.set(\"position\",globalposition);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":489,"y":680,"wires":[["cc86a78.1645758","e08058e7.6e5288"]]},{"id":"cc86a78.1645758","type":"worldmap","z":"7165bf62.19b6b","name":"","lat":"","lon":"","zoom":"","layer":"OSM","cluster":"","maxage":"","usermenu":"show","layers":"show","panit":"true","panlock":"false","zoomlock":"false","hiderightclick":"false","coords":"deg","showgrid":"true","allowFileDrop":"false","path":"/worldmap","x":900,"y":680,"wires":[]},{"id":"e08058e7.6e5288","type":"worldmap-tracks","z":"7165bf62.19b6b","name":"AUV Track","depth":"2000","layer":"combined","x":490,"y":740,"wires":[["cc86a78.1645758"]]},{"id":"a067a031.98f72","type":"delay","z":"7165bf62.19b6b","name":"","pauseType":"rate","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"3","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":280,"y":680,"wires":[["1df84317.28f25d"]]},{"id":"c7b7c863.329348","type":"ui_media","z":"7165bf62.19b6b","group":"79041bf8.4ac394","name":"","width":6,"height":2,"order":2,"category":"Logo","file":"DOF Subsea Logo.JPG","layout":"center","showcontrols":true,"loop":true,"onstart":false,"scope":"local","tooltip":"","x":910,"y":600,"wires":[[]]},{"id":"ba6061a4.6d3e","type":"ui_media","z":"7165bf62.19b6b","group":"79041bf8.4ac394","name":"","width":6,"height":2,"order":3,"category":"AUV","file":"Hugin 1000.png","layout":"adjust","showcontrols":true,"loop":true,"onstart":false,"scope":"local","tooltip":"","x":910,"y":560,"wires":[[]]},{"id":"cc4dbdef.49545","type":"mqtt in","z":"7165bf62.19b6b","name":"Depth Mode","topic":"depth_control","qos":"2","datatype":"auto","broker":"8a1c8231.17436","x":150,"y":120,"wires":[["4e74bc9b.6dabb4"]]},{"id":"58920b77.ee5434","type":"ui_text","z":"7165bf62.19b6b","group":"745e09e9.481608","order":2,"width":0,"height":0,"name":"Depth Mode","label":"Depth Mode:","format":"{{msg.payload}}","layout":"row-left","x":730,"y":120,"wires":[]},{"id":"7c6f27ea.d608c8","type":"mqtt in","z":"7165bf62.19b6b","name":"Guidance Mode","topic":"guidance_control","qos":"2","datatype":"auto","broker":"8a1c8231.17436","x":160,"y":260,"wires":[["1f16408a.3189ef"]]},{"id":"124b0b66.1b5605","type":"ui_text","z":"7165bf62.19b6b","group":"745e09e9.481608","order":3,"width":0,"height":0,"name":"Guidance Mode","label":"Guidance Mode:","format":"{{msg.payload}}","layout":"row-left","x":740,"y":260,"wires":[]},{"id":"71330e96.cde26","type":"delay","z":"7165bf62.19b6b","name":"","pauseType":"rate","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":500,"y":120,"wires":[["58920b77.ee5434"]]},{"id":"4e74bc9b.6dabb4","type":"function","z":"7165bf62.19b6b","name":"D Mode","func":"var payload = msg.payload ;\nif (payload == \"D\") {\n msg.payload = \"Depth\";\n} else if (payload == \"T\") {\n msg.payload = \"Trajectory\";\n} else if (payload == \"H\") {\n msg.payload = \"Altitude\";\n} else if (payload == \"S\") {\n msg.payload = \"Steep Depth\";\n} else if (payload == \"E\") {\n msg.payload = \"External\";\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":302,"y":120,"wires":[["71330e96.cde26"]]},{"id":"1f16408a.3189ef","type":"function","z":"7165bf62.19b6b","name":"G Mode","func":"var payload = msg.payload ;\nif (payload == \"H\") {\n msg.payload = \"Heading\";\n} else if (payload == \"C\") {\n msg.payload = \"Course\";\n} else if (payload == \"W\") {\n msg.payload = \"Waypoint\";\n} else if (payload == \"S\") {\n msg.payload = \"Circle\";\n} else if (payload == \"E\") {\n msg.payload = \"External\";\n} else if (payload == \"P\") {\n msg.payload = \"Pipeline Tracking\";\n} else {\n msg.payload = char(payload);\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":481,"y":260,"wires":[["124b0b66.1b5605"]]},{"id":"9df22c4d.38add","type":"ui_button","z":"7165bf62.19b6b","name":"Center","group":"fb6e5f97.c4b4a","order":2,"width":24,"height":1,"passthru":false,"label":"Center on AUV","tooltip":"","color":"","bgcolor":"","icon":"fa-ship","payload":"{command}","payloadType":"str","topic":"center","topicType":"msg","x":130,"y":800,"wires":[["70863c8e.6a6134"]]},{"id":"70863c8e.6a6134","type":"function","z":"7165bf62.19b6b","name":"Center command","func":"var center_globalposition = global.get(\"position\");\nmsg.payload = { \"command\": {\"lat\": center_globalposition.lat, \"lon\": center_globalposition.lon, \"zoom\": 18}\n\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":510,"y":800,"wires":[["cc86a78.1645758"]]},{"id":"6188c64.8501d38","type":"inject","z":"7165bf62.19b6b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":880,"wires":[["84df9983.574fe8"]]},{"id":"9fc7285e.397b28","type":"debug","z":"7165bf62.19b6b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":880,"wires":[]},{"id":"84df9983.574fe8","type":"moment","z":"7165bf62.19b6b","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/London","adjAmount":0,"adjType":"days","adjDir":"add","format":"\"dddd, MMMM Do YYYY, h:mm:ss a\"","locale":"en-GB","output":"","outputType":"msg","outTz":"Europe/London","x":460,"y":880,"wires":[["9fc7285e.397b28"]]}]