Events only include server time because not all events are linked to locations.
I have solved this by a small modification to the server code.
Modify Event Model by Altering function Event which contains the variable positionId and add positionDate like below:
public Event(String type, long deviceId, long positionId, Date positionDate) {
this(type, deviceId);
setPositionId(positionId);
//this.serverTime = new Date();
this.serverTime = positionDate;
}
Then, modify all files inside handler => event which contains a call to new Event
function with position.getId()
add extra parameter position.getDeviceTime()
like below:
new Event(Event.TYPE_ALARM, position.getDeviceId(), position.getId(), position.getDeviceTime());
That will solve this issue and I have tested it today morning.
Using this modification above, the events are saved on device time and notifications will be sent with device time too which is much better for user to know the exact event date/time.
I think this changes needs to be considered in your primary code as well @Anton.
Since disconnected devices with data logging capacity will send data to server as and when they connected and the events / notifications create a wrong alert to the user
One update to the Event model, you should update the second function and add this.serverTime = new Date(); to maintain the other events and notifications which do not have a position like deviceOnline and deviceOffline.
The new code to modify on Event model is:
public Event(String type, long deviceId, long positionId, Date positionDate) {
this(type, deviceId);
setPositionId(positionId);
//this.serverTime = new Date();
this.serverTime = positionDate;
}
public Event(String type, long deviceId) {
setType(type);
setDeviceId(deviceId);
this.serverTime = new Date();
}
I have noticed one problem when devices sending old positions.
For some cases, if the server not available for a long time or even for hours, so when the server gets back online the devices start sending positions to the server and some devices save many positions which not sent to the server.
The problem is on the events, the server creates events for old positions on current date/time or server time not based on device time or position time, and also the notifications sent using the current server time which is confusing to receive a notification that device inside a geofence but after checking the route report you will see that it was old position.
I tried to check the code to see if it can be solved but i cannot modify the Event class to get the position date/time maybe because i am new to the traccar code.