hardillb / node-red-node-geofence

Geofence node for Node-RED
Apache License 2.0
29 stars 18 forks source link

add action - send - to output current fence shape to map. #21

Closed dceejay closed 3 years ago

dceejay commented 3 years ago

Hi,

ok - couldn't resist... added action property to allow sending in options to geofence... Initial PR just add msg.payload.action == "send" to send out existing fence shape in a format suitable direct to worldmap. Currently uses node name as the shape name, add to a layer to geofence, and the border colour = red for trigger when inside, green = trigger when outside and yellow for the "both"/inout behaviour.

Example flow below

[{"id":"75d51935.033378","type":"worldmap","z":"78444ab3.45a654","name":"","lat":"","lon":"","zoom":"6","layer":"","cluster":"","maxage":"","usermenu":"show","layers":"show","panit":"false","panlock":"false","zoomlock":"false","hiderightclick":"false","coords":"none","showgrid":"false","allowFileDrop":"false","path":"/worldmap","x":620,"y":260,"wires":[]},{"id":"84bf68e3.fc6728","type":"geofence","z":"78444ab3.45a654","name":"rectFence","mode":"polyline","inside":"true","rad":0,"points":[{"latitude":50.388164497948594,"longitude":-3.6021423339843746},{"latitude":51.22817289705297,"longitude":-3.6021423339843746},{"latitude":51.22817289705297,"longitude":1.616363525390625},{"latitude":50.388164497948594,"longitude":1.616363525390625}],"centre":{},"floor":"","ceiling":"","x":360,"y":140,"wires":[["c5daff7d.3ba97","75d51935.033378"]]},{"id":"3b04ec9c.1f86c4","type":"inject","z":"78444ab3.45a654","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"action\":\"send\"}","payloadType":"json","x":140,"y":140,"wires":[["84bf68e3.fc6728"]]},{"id":"c5daff7d.3ba97","type":"debug","z":"78444ab3.45a654","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":140,"wires":[]},{"id":"a0095875.4e1878","type":"geofence","z":"78444ab3.45a654","name":"circleFence","mode":"circle","inside":"false","rad":68909.67107280553,"points":[],"centre":{"latitude":52.47608904123904,"longitude":0.94482421875},"floor":"","ceiling":"","x":370,"y":200,"wires":[["c5daff7d.3ba97","75d51935.033378"]]},{"id":"c550248c.9974f8","type":"inject","z":"78444ab3.45a654","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"action\":\"send\"}","payloadType":"json","x":140,"y":200,"wires":[["a0095875.4e1878"]]},{"id":"898921da.17565","type":"geofence","z":"78444ab3.45a654","name":"polyFence","mode":"polyline","inside":"both","rad":0,"points":[{"latitude":53.60676632634897,"longitude":-2.63397216796875},{"latitude":53.61980121473449,"longitude":0.61798095703125},{"latitude":52.81728815003413,"longitude":-0.7223510742187499},{"latitude":52.134752461085824,"longitude":-3.35906982421875},{"latitude":53.22700162666451,"longitude":-3.86444091796875}],"centre":{},"floor":"","ceiling":"","x":370,"y":260,"wires":[["c5daff7d.3ba97","75d51935.033378"]]},{"id":"297f8ccc.23e014","type":"inject","z":"78444ab3.45a654","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"action\":\"send\"}","payloadType":"json","x":140,"y":260,"wires":[["898921da.17565"]]}]
hardillb commented 3 years ago

I'm not seeing anything on the map when I click the inject buttons in the example flow.

Do I need to enable a layer on the left hand side?

dceejay commented 3 years ago

Odd - latest worldmap ? and it has connected ? should just get image

hardillb commented 3 years ago

Worldmap v2.8.1

How would I know it's connected?

hardillb commented 3 years ago

Hmm, looks to work on Chrome but not firefox

dceejay commented 3 years ago

bottom left image green = connected :-) - or indeed image

hardillb commented 3 years ago

Ignore me, firefox autocomplete URL had stuck me on the wrong instance. Looks good

dceejay commented 3 years ago

so yes - still to debate... I went with action - send... as the worldmap actually send out all it's feedback with an action property so we could (at some point) feed them straight in to update a fence... but... the worldmap itself (for most things) takes a "command" property - and reality is may not want all actions going into fence as a) not necessary and b) it can only handle one shape at a time (currently) so needs to be some logic in front to only allow a certain (matching name?) updates in.. maybe... dunno... and 2) I used send because err. - is show better ? or even showFence ? or...

hardillb commented 3 years ago

I still think it should output the input to the worldmap on an optional second output so users don't need to filter the output before putting it through any other down stream nodes.

dceejay commented 3 years ago

why ? it would only be sent if they ask so won't affect existing (as they won't know to ask). What sort of nodes would care ?

hardillb commented 3 years ago

I'm assuming that the output of the geofence node is not just connected to the worldmap node and is being used to trigger events based on the in/out status of the messages

dceejay commented 3 years ago

true - but in that case (not going to worldmap) why would you ask it to send the fence out ?

(at end of the day I don't mind a second output - just seems like extra ui/config/things to think about/hassle)

hardillb commented 3 years ago

I'm saying the output goes to both the worldmap and something else, or through other things before going to the worldmap