evens device running and device stop not triped when using a simulator.

Davidescu Ioan7 years ago

Hi there, I am trying to change the color of device SGV icon to red the moment the stopped event get's triped and after that back to green when the device is running again. In the current version of traccar we only have online, offline and unknow statuses. I trying to add one more .. stopped when the device is at 0 speed. I have modified the traccar-web to accept status "stopped" together with online, offline and unknown. I have create a new case Device.STATUS_STOPPED with the eventType = Event.TYPE_DEVICE_STOPPED in the ConnectionManager.java case in traccar source but now i have and issue trying to simulate a stop event.

Fot the simulator I am using a mysql database with some coordinates taken from a gpx file to simulate a track. I am using a python simulator to send data to traccar. All thing are working but some somehow the running and stop events don't get triped when the speed decreses to 0, it hold to 0 for a few updated and after it rises again as the device is moving away, The message send by the simulator is the folowing:

in motion - imei:359710044422195,tracker,171210204032,,F,124029.000,A,4606.01008,N,2516.27356,65,0;
stoped imei:359710044422195,tracker,171210204032,,F,124029.000,A,4606.1038,N,2516.206,0,0;

CREATE TABLE IF NOT EXISTS `track` (
`id` int(11) NOT NULL,
  `lat` varchar(9) NOT NULL,
  `lon` varchar(9) NOT NULL,
  `speed` varchar(3) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=3095 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `track`
--

CREATE TABLE IF NOT EXISTS `track` (
`id` int(11) NOT NULL,
  `lat` varchar(9) NOT NULL,
  `lon` varchar(9) NOT NULL,
  `speed` varchar(3) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=3095 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `track`
--

INSERT INTO `track` (`id`, `lat`, `lon`, `speed`) VALUES
(9, '46.101046', '25.270679', '24'),
(14, '46.101730', '25.270100', '5'),
(17, '46.101730', '25.270100', '0'),
(18, '46.101730', '25.270100', '0'),
(19, '46.101730', '25.270100', '0'),
(20, '46.101730', '25.270100', '0'),
(26, '46.108191', '25.259127', '21'),
(27, '46.108488', '25.257024', '45'),
(28, '46.108845', '25.256029', '95'),
(29, '46.108780', '25.255779', '83');

python simulator:

#!/usr/bin/env python
import sys
import MySQLdb
import socket
from time import sleep
import math
from random import randint


TCP_IP = XXX.XXX.XXX.XXX'
TCP_PORT = 5150
BUFFER_SIZE = 1024
db = MySQLdb.connect(host="localhost",user="xxx",passwd="xxx",db="simulator")
cur = db.cursor()
cur.execute("SELECT * FROM track")

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))

for row in cur.fetchall():
    latitudine = str(row[1][:2])
    longitudine = str(row[2][:2])
    latitudine += "0"
    latitudine += str(float(row[1][2:])*60)
    longitudine += str(float(row[2][2:])*60)
    speed = row[3];
    MESSAGE = "imei:359710044422195,tracker,171210204032,,F,124029.000,A,"
    MESSAGE += latitudine
    MESSAGE += ",N,"
    MESSAGE += longitudine
    MESSAGE += ","
    MESSAGE += speed
    MESSAGE += ",0;"
    s.send(str(MESSAGE))
    print str(MESSAGE)
    print  row[1]
    print row[2]
    sleep(3)
db.close()
s.close()
Anton Tananaev7 years ago

I'm not sure why you provided all that SQL and your script. Do you think the problem is in simulating data? You can easily verify that by looking at Traccar log file.

Davidescu Ioan7 years ago

I provided the sql to show that the simulator is decreasing speed until 0 and rises again, but the stopped and is running events are not triped, even though the notification is configured properly. Using my simulator I can trip the overspeed notification but not the has stopped and is running notification. Looking at this: https://www.traccar.org/forums/topic/how-does-traccar-server-determine-if-a-device-has-stopped/ I saw that Traccar creates deviceStopped event when previous position has speed more than zero and current position has speed about zero. So I did this with my simulator without success. Traccar show the correct speed.. using the device simulator, but the stopped and running events are not trigered.

Anton Tananaev7 years ago

I'm not sure what kind of help you expect. Have you verified that the script works? Are you receiving correct data? If yes, there is no point in showing the script; you can just show the data. If script works, then the problem is with your Java code, which you haven't provided, so there is no way to know what the problem is.

Davidescu Ioan7 years ago

the simulator works. The device is traveling in traccar accordingly to the GPX folowed by the simulator. maybe you can tell me why the device has stopped and device is moving are not triped by the decreasing of speed until 0 and increasing it after a few points. This is why i have showed you the sql.. to see that I am doing this decrease of speed. When using a mobile phone osmand protocol the two events wer are taling about seams to be working. So I guess I am doing something wrong with the simulator data or maybe the procedure of creating deviceStopped is not quite as described in that post.

Anton Tananaev7 years ago

My guess is that the problem is with timestamp that doesn't change.