Geofencing - Node Red, Owntracks

Hey everyone,

Im working on a project for school where I have to track when the user enters or leaves a certain area. Im using OwnTracks to get the coordinates to the broker and the node Geofence to get the valeu for "inarea". I have a function to get the coordinates and then the Geofence node. Then I have a function to count the entrys and leaves in the area but it doesnt work.
image
First function:

msg.payload={
    "lat":msg.payload.lat,
    "lon":msg.payload.lon,
    "name":"a41774"
}
return msg;

Second function:

var entrada = context.get('entrada')||0;
var saida = context.get('saida')||0;

if(location.inarea == "true"){
    entry+= 1;
    context.set('entrada',entrada);
    msg.count = entrada;
}
else if(msg.payload.inarea == "false"){
    saida+= 1;
    context.set('saida',saida);
    msg.count = saida;
}

msg.payload={
    "entrada": entrada,
    "saida": saida
}
return msg;

Here are the outputs.

Output function 1:
image
Output fucntion 2:
image

"true" is a string , that should be true no quotes, or just if(location.inarea)

1 Like

Probably should be:

if ( location.inarea === true ){

Note the 3 = and, as mentioned by others, no quotes.

Then you don't need another else if, only an else.

1 Like

Thank you guys!!

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