Notification triggered when server receives data from the device. If device buffered old data and sent it later, you will get behaviour like you described.
Thanks Anton. It wasn't buffered old data since I can follow the device in real time and the exit notification wouldn't trigger.
I determined the issue was with the specific geofence i had set up around my house. I had used a polyline instead of a polygon and wasn't familiar with how it determined when a device was inside/outside the geofence. I replaced it with a polgon geofence and the behavior works correctly now.
Thanks again.
Hi,
I have a similar issue regarding geofenceExit.
We have accuracy issue with the devices they are inside the fence but sometime they show it outside which fires a false notification alert mail. To avoid that can we set a tolerance of 100 meter in around the fence before the Mail is fired the it must check if the distance between the geofence boundary and the device is greater then 100 meter. Can you tell is this possible to implement?
You can increase the geofence size. Wouldn't it be the same thing as what you're asking?
Alternatively you can enable filtering to filter out the jumps.
But we need the size of the fence to accurate on the field we are making that geofence because we need the hectare's of the geofence.
How can we enable filtering ? The issue is if a device is moving somewhere near the boundary inside the fence it will constantly show it outside the fence.
Can we implement something like this in traccar ?
private void sendEmail(Device device, Geofence geofence, Position position) throws MessagingException {
// Get the device position
Position devicePosition = Context.getIdentityManager().getLastPosition(device.getId());
if (devicePosition == null) {
return;
}
// Calculate the distance between the device and the geofence boundary
double distance = GeoUtils.distance(
devicePosition.getLatitude(),
devicePosition.getLongitude(),
geofence.getLatitude(),
geofence.getLongitude()
) - geofence.getRadius();
// Check if the device has left the geofence with the tolerance of 100 meters
if (distance > 100) {
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", Config.getSmtpHost());
properties.setProperty("mail.smtp.port", Config.getSmtpPort());
properties.setProperty("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(properties, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(Config.getSmtpUser(), Config.getSmtpPassword());
}
});
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(Config.getSmtpFrom()));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(device.getEmail()));
message.setSubject("Geofence Exited Notification");
String text = String.format("Device %s has exited geofence %s at %s", device.getName(), geofence.getName(), position.getFormattedTime());
message.setText(text);
Transport.send(message);
}
}
Of course you can. The source code is open, so you can implement your own custom logic if you want.
Alright
One last thing if you can tell, In which Java file the code for sending an email to the user if the geofenceExits is implemented? So I can implement my own logic there
All emails are sent using SmtpMailManager
class.
I explored the GeofenceEventHandler.java file but I can not find any class or function that have a mail sending feature is implement.
Alright. I will look through that file Thanks :)
Hi,
I have a strange issue with exit geofence notifications. I have configured both exit and enter notifications for my geofences. When a device is in a geofence and exits it does not trigger the notification initially. It is only when the device reenters the same geofence then I get the delayed exit notification as well as the entry notification at the same time. The timestamp on the exit geofence notification is incorrect as it has the same time as entry notification (which is correct).
So it seems that the enter geofence notification is working correctly but the exit notification is being delayed for some reason. Is there a way I can investigate what is happening using the logs?