NodeRed live location

It looks like you are using node-red worldmap - by @dceejay ??

If so the help is pretty explicit about what to do

Usage

Plots "things" on a map. By default the map will be served from {httpRoot}/worldmap , but this can be configured in the configuration panel.

Use keyboard shortcut ⌘⇧m , ctrl-shift-m to jump to the map.

The minimum msg.payload must contain name , lat and lon properties, for example

msg.payload = { "name":"Jason", "lat":51.05, "lon":-1.35 }

Is this the correct node ?

In your debug you do not appear to have a name ? and appear to have added a date field

Craig

what about now assigning the value to lat , lon but its field I think is because the data type is string right? if yes how can I convert it ?

In there you have not got the lat and long - they are showing as undefined ? - although you do have a name

So can you confirm which worldmap you are using ?

have you read the help about the options - other than what i posted ?

Craig

i'm using worldmap , and the data is showing as string

Whatever change you made to the processing of lat and long since 04:24 has broken it because they now show as undefined.

you can see here it shows the data from the upper debug, but when it crosses the function looks undefined from lower debug


Yes in your function node you are trying to access the lat and lon as if the information is held in a Javascript object - it isnt - it is a string

  1. Put a name on your debug objects so we know what we are looking at
  2. enable the debug from the serial port and show me what it is showing you

Craig

you will need to split this stuff out to make it accessible. It appears to be some combination of formats so may take a while to get right

I would suggest you try with a JSON node first and tell it to turn it into an object and show us the debug of the complete msg (remember to name the debug node)

You can also try the split node and see if that gives better results

Craig

Just woken up here in the UK.

I agree with @craigcurtin - you need to split out the string to get the 'lat' and 'lon' values.

I've very quickly modified my Wildfires flow and turned it into a very simple position indicator for the ISS.

Once you have split out your values you could probably make use of the last two nodes in this flow.

[{"id":"605c9ce313e4a5a7","type":"ui_worldmap","z":"a9b12d67e974b017","group":"d4d2c5a78449ad8a","order":1,"width":18,"height":14,"name":"fires","lat":"51","lon":"0","zoom":"4","layer":"EsriS","cluster":"","maxage":"","usermenu":"show","layers":"show","panit":"true","panlock":"false","zoomlock":"false","hiderightclick":"true","coords":"none","showgrid":"false","allowFileDrop":"false","path":"/worldmap","overlist":"CO,RA,DN","maplist":"EsriS,EsriT,NatGeo","mapname":"","mapurl":"","mapopt":"","mapwms":false,"x":830,"y":440,"wires":[]},{"id":"060a72676e03f9d3","type":"inject","z":"a9b12d67e974b017","name":"Trigger every 5-secs","props":[{"p":"headers","v":"{\"Accept\":\"text/json\"}","vt":"json"},{"p":"url","v":"http://api.open-notify.org/iss-now.json","vt":"str"}],"repeat":"5","crontab":"","once":true,"onceDelay":0.1,"topic":"","x":200,"y":440,"wires":[["3b88474842c4750d"]]},{"id":"3b88474842c4750d","type":"http request","z":"a9b12d67e974b017","name":"Get ISS coordinates","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":440,"y":440,"wires":[["6b32ca2b8bafb6cf"]]},{"id":"6b32ca2b8bafb6cf","type":"function","z":"a9b12d67e974b017","name":"Extract lat, lon","func":"let out = [];  // Declare an array\n\nlet id  = \"ISS\";\nlet lat = \"\";\nlet lon = \"\";\n\nlon = msg.payload.iss_position.longitude;\nlat = msg.payload.iss_position.latitude;\n\nout.push({\"name\": id, \"lat\": lat, \"lon\": lon, \"layer\": \"ISS track\", \"icon\": \"fa-space-shuttle\"});\n\nmsg.payload = out;\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":440,"wires":[["605c9ce313e4a5a7"]]},{"id":"d4d2c5a78449ad8a","type":"ui_group","name":"World_map","tab":"47ec854f298fe1a9","order":1,"disp":true,"width":"18","collapse":false,"className":""},{"id":"47ec854f298fe1a9","type":"ui_tab","name":"Wild_fires","icon":"dashboard","order":40,"disabled":false,"hidden":false}]

And here is a bit of JSONATA ugliness that could do it for you also (don't blame me i am just learning JSONATA) !!

[{"id":"a5ce70a5.b7ab8","type":"change","z":"c78e3c9a.7b1ca","name":"","rules":[{"t":"set","p":"Lon","pt":"msg","to":"$number($substringAfter($$.payload, \", Lon: \"))","tot":"jsonata"},{"t":"set","p":"Lat","pt":"msg","to":"$number($substringAfter($substringBefore($$.payload, \",\"),\"Lat: \"))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":420,"wires":[["29f139ab.a1e136"]]},{"id":"95b52563.300cf8","type":"inject","z":"c78e3c9a.7b1ca","name":"Test inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Lat: 25, Lon: 29","payloadType":"str","x":230,"y":420,"wires":[["a5ce70a5.b7ab8","d593e94d.836878"]]},{"id":"d593e94d.836878","type":"debug","z":"c78e3c9a.7b1ca","name":"before change","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":360,"wires":[]},{"id":"29f139ab.a1e136","type":"debug","z":"c78e3c9a.7b1ca","name":"after change","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":790,"y":420,"wires":[]}]

Craig

1 Like

Looks like you could be very near to having a solution with @craigcurtin JSONata in the 'change' node.

You just need to move things around so the 'lat' and 'lon' are in the correct places for the Worldmap node.

Thanks so much, but I'm confused now about how I can sort the flow to make it correct cuz I try to replace COM5 with Test inject and still not working


YOu have changed something - before you had more data incoming on the COm Port - for instance the date was in there ?

Show us the output from my test flow that i sent you firstly

And then show us the complete message object from the COM port again

What i showed you was an example with test data - to show you how it could be done

Craig

Craig

Here's a test flow with test-data from your screen-shot above.
ma-car

[{"id":"b6b1c6060c03f0a1","type":"inject","z":"e6f7c855bf7f6cc9","name":"Test inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Lat: 25.67 Lon: 29.78","payloadType":"str","x":240,"y":420,"wires":[["41692b35459812ed"]]},{"id":"41692b35459812ed","type":"function","z":"e6f7c855bf7f6cc9","name":"","func":"let parts = msg.payload.split(\" \");\nlet lat = parts[1];\nlet lon = parts[3];\n\nlet out = [];  // Declare an array\n\nlet id  = \"NEO-6m\";\n\nout.push({\"name\": id, \"lat\": lat, \"lon\": lon, \"layer\": \"NEO-6m\", \"icon\": \"ma-car\"});\n\nmsg.payload = out;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":420,"wires":[["620696059e87bec2"]]},{"id":"620696059e87bec2","type":"debug","z":"e6f7c855bf7f6cc9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":590,"y":420,"wires":[]}]

I'm still learning JSONata, so I've used a simple 'split' on a space character in the function node.

EDIT
As @jbudd said below, you don't need to convert the lat/lon values, worldmap will accept text.

Let me know if it works for you?

Yes, I removed the date from my code. this shows the output from your test


and this original output

I don't want to confuse things even further, but you don't actually have to convert the lat and long values to numbers, the worldmap seems to accept these values as strings.

Edit - @dynamicdave already confirmed this.

it's working successfully


Thank you so much Mr. @dynamicdave

Yipppppeeee - success at last.
You can have some fun now.

1 Like

I've published a version of the question asked by @lord on Share Your Projects.

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