GPS monitoring of a car or homework for the evening

Hello! One day, thinking about the safety of their car, I rustled a lot of resources with information about car anti-theft systems including GPS. But it was either not what you need or is expensive, and associated services special functions I didn't like, and to admit there is some paranoia in me. In General, the main frightening thing for me was to share information about your location. In the end, was bought by an ordinary alarm with auto start and feedback, but it is a little on the other.

All thoughts of saving information on the situation of the car I have spun in my head, and I just wanted to find an interesting take on leisure. ON these thoughts I decided to buy the so-called personal GPS tracker. Especially to models is not watched, all about the same thing, but very important feature of such as setup on your own server had not many of the enumerated candidates. In the end, my choice fell on the of personal GPS tracker Xexun Chinese companies — Xexun TK102-2. After a few more hours written search as everything is customizable and a bunch of manuals I decided that I need to buy and see what it is. Interesting information about tracker and about writing your own "server" for a tracker, please move.


On the forms of different companies providing services of GPS monitoring, wrote, and warned that walks a bunch of fakes and that it is likely to run into them that supposedly outwardly indistinguishable, etc., if you are not the priority item to them, but I went through a proven and ordered Pribluda on ebay, though had to wait for 4 weeks, anyway — came.

Briefly about the tracker:
Connection standard: GSM 850, GSM 900, GSM 1800, GSM 1900
GPS chipset: SiRF Star III
Satellite navigation system: GPS
Specifications:
Sensitivity tracking: -159 dBm
The "hot start" for 2 seconds
Cold start 35 seconds
5 meter accuracy
Operating temperature -10 to +65° C

Functions
Remote control SMS
The speed control, the start of movement
The signal "battery low"

Dimensions and weight
Length 64 mm
Width 46 mm
Thickness 17 mm
Weight 50 g

Memory
Support for SD memory cards
Data transmission GPRS

Hot keys and display
Panic button: send current coordinates, sending an SOS signal via SMS
Indication: green led

Battery
Battery type Li-ion
Battery capacity 860 mAh
While working in normal mode up to 12 hours
Working time in standby mode up to 80 hours

The device came in a box, which, incidentally, was pretty well done.



The device is made of a nice touch rubberized plastic.



Inside view with an already installed SIM card.


The kit was charging for a replacement battery for the tracker.


It is a pity that nebylo no box to check ON the health tracker, but fortunately there are services which make it relatively easy for simple (sorry for the tautology) of a person to register himself and the device and see how it all works, but it's not for me I wrote about this in the beginning of the topic.

So, it's time to test. Without hesitation, I went to the balcony and launched the tracker, after reading the manual I tried to adjust it, but I was given this variable because the user manual was not written very correctly, many typos, and typos in the commands to send to the tracker, so I got the Russian version and the configuration was fast and without errors.
The first thing I tried to query the tracker by SMS — GPS and instantly checked the maps — well, the next step is to set up on your server, but since I have a server of their, but there is white IP without thinking I wrote a console application in C# and decided to see what comes with the tracker, and the tracker came up the following line:
"130402213013,+79637**3***,GPRMC,173013.000,A,6146.4979,N,03421.2399,E,1.92,21.48 us,020413,,,A*5B,F,, imei:*************,00,-16.4,F:3.73V,0,139,49646,250,99,1478,68A7\n\r"

Asterisks in the fields with a phone number (2) in the imei field I have written specifically.
In fact the description of this line was in the instructions, but not all of it completely, something had to understand example: to find out what GPRMC, but it is also not difficult because the information is complete.

One of the major unclear points for me was the fact that the coordinates come not exactly a few tens of kilometers in the side, although immediately receives an SMS with the normal coordinates. It gives not a little annoyance, because by the time I have written a small program which parses and saves to xml file (more on this later). The decision does not lay on the surface because I just don't understand how to formulate your query in Google to find the information you need in the end a few days in a row I've read various technical specifications about the sea and not only navigation and articles on the work of GPS receivers. Was quite simply the coordinates come in the format of WGS-84 and it was necessary to translate in "normal" i.e. those which are suitable such as Yandex. Maps. Actually with the advent of "WGS-84" circle narrowed, and immediately found the formulas and all the math.

Separately want to write about the program I was working in the evenings, in order to receive data from the tracker. I chose c# as the most convenient, in the University labs prefer to do it because of its apparent simplicity, however. However, everything taught in school and what I taught myself — not useful in this project. For example about multithreading, I had never heard know about C#. Yes Yes. Network was not the same. In General had to understand and read everything yourself.

All in good time.
To start ServerStart will start the method that makes you listen whodie of coedine, one runs the method that spawns a new thread which waits for "clients". When a client is generated by another thread that receives data from the tracker. Everything is quite simple.
the
 public void ServerStart()
{
isServerRunning = true;
listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// Define endpoint IPAddress.Any means that our server will  accept  incoming connections from any address
Point = new IPEndPoint(IPAddress.Any, port);
// Associate the socket with the endpoint
listener.Bind(Point);
// Start to listen incoming connections
listener.Listen(10);

socketAccepter();
}

public void socketAccepter()
{
// Run the loop in a separate thread so the app hasn't crashed
Thread th = new Thread(delegate()
{
while (isServerRunning)
{
// Create a new socket on which we will be able to handle customer
// This loop will stop until some client tries to join the server
Socket client = listener.Accept();

//client.ReceiveTimeout = 20000;
// Now, referring to the client object, we will be able to send and receive packets from the last logged-in user.
// Add the connected client to the list of all customers for future mass mailing of packages
clients.Add(client);

// Begin to accept incoming packets
Thread thh = new Thread(delegate()
{
messageReciever(client);
});

thh.Name = "Recieving end" + DateTime.Now.ToString();
thh.Start();
threads.Add(thh);
}
});
th.Name = "Accepting Connecton" + threads.Count;
th.Start();
threads.Add(th);
}


A method which accepts the message. Many times I heard "For infinite loops, you need to burn at the stake", referring to his experience or should I say not literacy in this issue, have decided that the use of so, then after reading relevant literature I try to write as it would be correct. Although actually I noticed that I began devouring CPU, there were moments when one core is fully loaded due to the process of this cycle, but after I adjusted and began to use the Recieve method which stops the execution flow until you will not receive a message from the tracker, in General, used the same logic as with the listener.Accept().
the
 public void messageReciever(Socket client)
{
int i = 0, av = 0;
double t = 0;
string[] data;
string[] messages;
char[] spliter = { '\n', '\r' };
string message = "";

while (isServerRunning && client.Connected == true)
{
try
{
// Here we write the received bytes
byte[] bytes = new byte[2048];
// Taken
av = client.Receive(bytes);
if (av != 0)
{

message = Encoding.UTF8.GetString(bytes).Remove(av);
messages = message.Split(spliter, System.StringSplitOptions.RemoveEmptyEntries);
for (i = 0; i < messages.Length; i++)
{
data = messages[i].Split(',');
if (double.TryParse(data[0], out t))
saver.parseData(data);
//else
//MessageBox.Show(messages[i].ToString());

}
}
else
{
continue;
}

}
catch //(Exception e)
{
//MessageBox.Show(e.Message + "" + e.StackTrace, Method "Message Reciever");
}
}
threads.Remove(Thread.CurrentThread);
Thread.CurrentThread.Abort();
}


For that I want to finish, the only thing that I would like to add is that the save data to xml file, I decided to give up, because not really figured out how to synchronize threads between them and often it turns out that the file was opened by one thread, and it is trying to reach out already in another thread. The problem of lock put on a DBMS MySQL. Ah Yes, the parsing of the data separated by comma I think also do not need special representation, and connect C# to MySQL simply and friendly happens, the more that MySQL provides all the headers.

At the moment, I plan to expand the functionality of this app and distribute a web muzzle to start to visualize the displacement. With the web face, too, there are certain difficulties, namely: to determine which cards to use, well, actually studying the maps API. Experience with API any maps there, but I think in a leisurely manner as in the evenings and all will be studied.

Thank you to those who read, and special thanks to UFO.

Application
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Integration of PostgreSQL with MS SQL Server for those who want faster and deeper

Parse URL in Zend Framework 2

Custom database queries in MODx Revolution