Hello, I would like to change the name, for example gps001, so that I can immediately recognize the vehicle's identification in the debug and on the map. What would be the configuration then? Thanks
What would you like to change it to? Is there a fixed relationship between the name and gps number?
You could create a cross reference table in a context variable eg flow.gps
{
"gps001": "Shandong",
"gps002": "Fujian"
}
And a change node
Yes... the trackers are permanently assigned.
gps001 = NOR X1
gps002 = PUA X2
And NOR and PUA should be displayed on the map not gps001 gps002 and so on
How to create a cross reference table in a context variable eg flow.gps?
[{"id":"f0253ad934fa6c83","type":"group","z":"c1759c372b184d6a","name":"Populate flow.gps","style":{"label":true},"nodes":["36c8f2e88a35e273","81d2c5110ad10bcc"],"x":94,"y":79,"w":352,"h":82},{"id":"36c8f2e88a35e273","type":"inject","z":"c1759c372b184d6a","g":"f0253ad934fa6c83","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"go","payloadType":"str","x":190,"y":120,"wires":[["81d2c5110ad10bcc"]]},{"id":"81d2c5110ad10bcc","type":"change","z":"c1759c372b184d6a","g":"f0253ad934fa6c83","name":"","rules":[{"t":"set","p":"gps","pt":"flow","to":"{\"gps001\":\"Fujian\",\"gps002\":\"Shandong\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":120,"wires":[[]]}]
I don't know anything about the map you are using but it must be getting "gps001" from somewhere, perhaps from msg.name.
If you change msg.name as I showed above, won't that change be shown on the map?
If it's node-red-contrib-web-worldmap then it needs to set msg.payload.name
Thanks deejay. Yes... simply put, the flow works with 3 nodes and 1 tracker display (MQTT-IN, a function node and node -red-contrib-web-wordmap. Since wordmap requires at least name, lat and log, I have the function node configured as shown in the picture.
So yes - use a lookup like @jbudd suggests (Or hardcode it in the function if it is not really going to change or get too big) - but in the change node use Set : msg.payload.name to the value flow.gps[msg.payload.name]
I now have the solution... very simple. I simply installed a change node between MQTT-IN and FUNCTION (see screenshot)
On line #6 you have wiped out the incoming msg
object, with any other properties that may have been set upstream -- generally, that is considered bad form. Instead you can delete that line, and just set your payload to the new object containing the lat, long, name properties.
Not that is matters now, since that last solution uses a change
node that preserves the other fields... but just in case someone later tries that same code... fwiw.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.