Jack

jack

About: Interested in Raspberry Pi, and wireless IoT devices. Just started work on a temperature station which will have remote wireless sensors.

New Conversation

Join the discussion

Log in or create an account, and start talking!

Activity

Jack made a post to Vehicle Tracking Device:

Quick Update to the Auto Referesh the Map Page

This is just a quick update to the Map.php code to allow it to auto refresh as suggested by Georgian Borca.

To achieve this I have basically put the ajax data retrieval function into its own function and put a call to setTimeout() to recursively recall the same function after a specified timeout period, in this case 10000msec (10 seconds).

Here is the updated code (note that the ProcessData() funciton remains unchanged).

    $(document).ready(function() 
	{
		// initialise the map
		map = new google.maps.Map(document.getElementById("map"), 
		{
			center: new google.maps.LatLng(51.5015379, -0.1211846),
			zoom: 13,
			mapTypeId: 'roadmap'
		});
		
		// create a path to show when the car has been
		path = new google.maps.Polyline({
          map: map,
          strokeColor: "#FF3333",
          strokeOpacity: 0.5,
          strokeWeight: 8
        });
		
		refreshMapData();
		
	});
	
	
	function refreshMapData()
	{
		$.ajax(
		{
			type: "GET",
			url: "<?php echo $filename ?>",
			dataType: "text",
			success: function(data) {processData(data);}
		});
		setTimeout(refreshMapData, 5000);
	}

I am not too knowledgeable with javascript, so not sure if this is the best way to do it? Please let me (and Georgian) know if you have a better way! 

Comments

Respond

Join the discussion

Log in or create an account, and start talking!

Great, I'll check it tomorow.
The only problem, for now, is that the internet browser, (mozilla firefox in my case) tends to cache the page. If i delete da file or some lines from it, it still shows the pints on the map. Maybe someone can help solve this problem.
Here i have attached two photos with my very messy prototipe, but it works :)

Respond

Join the discussion

Log in or create an account, and start talking!

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

Jack is now following the project My Workshop

My Workshop

Jack is now following the project CNC machine

CNC machine

Jack made a post to Vehicle Tracking Device:

Burning Down the House (or car in this case...)

Burning Down the House (or car in this case...)

This is just a very quick post to let you know how I am getting on.

Basically not great!  I thought I would give the Li-ion battery a go.  So I attached battery holder to the FONA 808, I attached a FTDI serial adapter to the FONA's RX, TX, Vio, and GND.  Next I added one of the batteries, and powered on the FONA.  Very quickly the magic smoke appeared! the insulator melted off the battery wires and everything got very hot!  Luckily I had some scissors to hand, so quickly just cut all the wires!!!

Not sure what the issue was, there is not a lot to have wired up wrong!?  I also checked there was resistance between the positive and negative battery terminals before adding the battery.

Think I am going to have to rethink the project a bit, I was always a bit cautious about having a lithium battery charging unattended in the car, but this one was not even charging and it would have started a fire!

Any ideas how I can power this thing without the risk of explosions would be great!

Comments

Hi,
Great project. I have designed a power supply for my simCOM GSM module. Let me know if need the schematic or something.
Georgian.
https://oshpark.com/shared_projects/5qelr5jz

Jack replied:

Thanks Georgian. That sounds like it could be useful. I was hoping that by using the liion battery and in built charger, it would mean that when the engine is running the battery would get charged and when the engine was off the GSM module would use the liion battery rather than draining the car battery. But it may be that I can get another battery that I can charge from the car when running, and then put though a power supply like the one you have designed!

Georgian Borca replied:

You shouldn't have any problems using a liion battery. I did use one a lot of times. if it's a 3.7 V Batteray should work just fine. You must have got the polarity wrong or something. One i did have a problem withe that charging IC when chargiung the battery and using it in the same time. the magic smoke came out of the IC but apart from that everything went just fine. Double check the conection again. This power supply dose not charge the battery!

Jack replied:

Yeah, I think I will give the liion battery another go on the weekend. My concern is that I have fried the charger unit on the fona board, so that when I plug a battery in it will just short circuit and melt the wires again. I will check every think with a multimeter before i try it again, but I did do that before plugging it in last time... I will let you know what happens!

Georgian Borca replied:

Any chance you post some pictures of it? Using anouther power supply will have the same effect if there is some short on the board.
here is one board that i have previosly designed for the SIM808. It uses the internal charging circuit sa no external is needed (like on the fona).
https://oshpark.com/shared_projects/YvwQATrH

Respond

Join the discussion

Log in or create an account, and start talking!

This post has been deleted.

Respond

Join the discussion

Log in or create an account, and start talking!

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

Jack is now following the project Raspberry Pi News

Raspberry Pi News

Jack made a post to Vehicle Tracking Device:

The Parts

The Parts

Today I finally got all the parts! So before I start playing with them, I thought I would just do a quick post to show them.  This is mainly because I need some advice with the batteries, as I will explain in a bit.

The Enclosure

This is the enclosure that I plan to use.  It is a little bigger than I thought so I am hoping that I am able to hide it in the car some where (that also needs to be dry!).  As I intend for this to double up as a security device It needs to be well hidden and not easily accessible.  So I will need to remove parts of car to fit it.  It will also require power so I will need to find somewhere I can get power too.  I have a few ideas of possible locations, I just hope it fits!!  The box is easily big enough to fit all the components, and in fact could probably be a third of the size, so there is always the option to get a smaller box if I need to.

The Arduino

I have gone for an Arduino Uno, mainly because that is the only type of Arduino I have used before and it worked okay!  I don't need much in the way of IO pins etc for this project so it will do the job.

The FONA 808

This is where it starts getting interesting.  So I have the FONA 808, this is a GSM device that can make phone calls and send SMS messages, as well as do mobile data comms (note: this is only 2G).  An added benefit of the FONA 808 is that it also contains a GPS, so everything I need is in the one package.  You need a micro-controller or processor to use the FONA (hence the Arduino), and you talk to it using AT commands through the serial port (more on this in future posts!).

The funny looking green thing to the right of the FONA 808 is the GSM antenna.  This (and in fact all of the other components) are required separate purchases, so bare this in mind when pricing up your projects or ordering a FONA.

A sim card is also required for the FONA to work, this enable the mobile phone company to charge you for calls/data (and gives your device a phone number etc.).  I have selected the Lebara Pay as you go one, as, after a bit of research this is one I believe still works with 2G.  A lot of other mobile networks (in the UK) are 3G/4G only, so check when you order.  Fortunately they are very cheap, unfortunately you probably have to put £10 on to be able to test it!  I will let you know if this one works! 

GPS Antenna 

This is the GPS antenna.  There are two parts to this (which are purchased separately), the copper cable is used to convert the connector on the FONA 808 to the bigger connector on the GPS antenna.  The GPS antenna has a long cable which may come in useful if there is not a good position for GPS signal local to where I am mounting the enclosure.

The Batteries....

Okay, this is the part that I need help with!

The FONA 808 needs an additional battery.  The device has a USB socket that can be used to power it to some extent, but this is not enough to make calls etc. (which would be a bit limiting!!), so instead it is used to charge a battery.  It has the capability to charge either a LiPo or Li-ion battery.  I have purchased both, but I am not sure which is the best to use.

I first purchased the LiPo battery (silver rectangle thing) as this is the one that most people seem to be using.  However I read a lot of 'horror stories' about LiPo batteries, that make me feel very uneasy about putting on in my car and effectively leaving it charging unattended.  There seems the be issues with charging and if it is not done correctly the battery can 'vent with fire' (search for LiPo fire on youtube to see what I am afraid of!).  In addition to this, you will notice that my batter is bent and dented! which I am also concerned about, as damaged batteries are prone to the explosive failure!  I was also surprised to find that the connector on my LiPo battery is nothing like the socket on the FONA 808!?!  I was expecting a two pin connector, which is what most of the examples on the internet have.

So I next purchased a Li-ion batteries, these are in a 18650 package (purple batteries that look like oversized AAs), These are supposed to be safer (I believe they are chemically similar to LiPo but in a harder package), due to the tougher packaging.

At this point I am not sure which way to go, so any advice would be really useful!

Once I have worked out the battery dilemma, I will next test the FONA 808 and my sim card by connecting it to a serial port on my Laptop and using AT commands to talk to it.  I will do a post of how I get on!

Comments

Jack commented on The Parts:

I have put a question in the Ask section of the site about the batteries: https://incredibits.io/question/lipo-or-li-ion-battery-in-a-car-tracker

Respond

Join the discussion

Log in or create an account, and start talking!

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

Jack made a post to Vehicle Tracking Device:

Car Location Web Site

Car Location Web Site

I am still waiting for the parts to arrive, so I have decided to make a start on a basic viewer for the car location track data.  The plan is that this will be based on google maps, and will show each reported position with a marker icon, which when clicked will show the time the car was there and the cumulative distance traveled that day, at that point.

The page will be a combination of PHP (to get the URL parameters) and javascript (to work with the google maps API and process the data.  The page is loaded with the following HTTP GET request:

http://www.example.org/map.php?date=2016-03-08

which can simply be entered into the browser address bar.  The date is the date to retrieve the data for.  (replace www.example.org with your hosted location).

I will post the complete code at the end of the post, but first I will go through the interesting parts.

<?php
// get the date from the url parameter
$filename = "data/" . $_GET['date'] . ".txt";
?>

The above is the only thing that I am using PHP for in this file.  Basically I create the path to the car location log file by using the date passed in the URL.

Next I initialise the map and load the data on page load:

$(document).ready(function() 
{
	// initialise the map
	map = new google.maps.Map(document.getElementById("map"), 
	{
		center: new google.maps.LatLng(51.5015379, -0.1211846),
		zoom: 13,
		mapTypeId: 'roadmap'
	});
	
	// create a path to show when the car has been
	path = new google.maps.Polyline({
	  map: map,
	  strokeColor: "#3333FF",
	  strokeOpacity: 0.5,
	  strokeWeight: 6
	});
	
	// retrieve the data and set callback function	
	$.ajax(
	{
		type: "GET",
		url: "<?php echo $filename ?>",
		dataType: "text",
		success: function(data) {processData(data);}
	});
});

The first block is initialising the map, and setting it to a sensible zoom level and centred around where I expect my locations to be.  The Next block is creating a ployline object that will be used to join the points up. And the last block is using the PHP $filename variable I set to retrieve the track data file.  The processData() function is set as a callback for when the data has successfully been retrieved.

The ProcessData() function (see the complete code at the bottom of the post), goes through each of the lines in the track data file and adds a marker to the map with the following code:

var point = new google.maps.LatLng(
	parseFloat(data[2]),
	parseFloat(data[1]));
	
coords.push(point);

var distance = google.maps.geometry.spherical.computeLength(coords);

//convert to miles
var miles = Math.round(distance/1609 * 100) / 100;

var html = "Time: " + data[0] + "Distance: " + miles + " miles"; // this is the timestamp
var icon = {};
				
if ( i == ( allTextLines.length - 2 ) )  // this is 2 becuase the last line is empty
{
	// make the last entry a red marker
	icon = customIcons["redPoint"] || {};	
}
else
{
	icon = customIcons["bluePoint"] || {};
}

// create the marker
var marker = new google.maps.Marker(
{
	map: map,
	position: point,
	icon: icon.icon
});

First a latLong point object is created from the latitude and longitude values that are in the track file.  Next the total distance so far is caluculated by adding the distance to all of the points that have been added to the map so far.  This value is converted in to miles and then a HTML string is created that details the timestamp (for the current position) and the distance.  I then assign a marker icon to the track recording, blue for old positions, and red for the last recorded position (that day).

Once I have been through all of the track records in the track data file, I then add of of the points to the path object, so that a line is drawn between them.

And here is how it looks in the browser:

This is a quick and effective way to visualise the data that will be recorded by the tracking device (once I have built it...)

Here is the complete code, Let me know if you have any questions!!

<!DOCTYPE html >
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Car Location Map</title>
    <script src="https://maps.googleapis.com/maps/api/js?key=INSERT-YOUR-GOOGLE-KEY-HERE&libraries=geometry"
            type="text/javascript"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
	
	<style type="text/css">
        html, body, #map_canvas {
            height: 100%;
            width: 100%;
            margin: 0px;
        }

        #map_canvas {
            position: relative;
        }

        .angular-google-map-container {
            position: absolute;
            top: 0;
            bottom: 0;
            right: 0;
            left: 0;
        }
	</style>
	
	<script type="text/javascript">
    //<![CDATA[
	<?php
	// get the date from the url parameter
	$filename = "data/" . $_GET['date'] . ".txt";
	?>
	
	// blue and red marker icons
    var customIcons = {
      bluePoint: {
        icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png'
      },
      redPoint: {
        icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png'
      }
    };

	// global google map object
	var map;
	var path;
	
	$(document).ready(function() 
	{
		// initialise the map
		map = new google.maps.Map(document.getElementById("map"), 
		{
			center: new google.maps.LatLng(51.5015379, -0.1211846),
			zoom: 13,
			mapTypeId: 'roadmap'
		});
		
		// create a path to show when the car has been
		path = new google.maps.Polyline({
          map: map,
          strokeColor: "#3333FF",
          strokeOpacity: 0.5,
          strokeWeight: 6
        });
		
		// retrieve the data and set callback function	
		$.ajax(
		{
			type: "GET",
			url: "<?php echo $filename ?>",
			dataType: "text",
			success: function(data) {processData(data);}
		});
	});

	function processData(allText) 
	{
		// split into the lines of data
		var allTextLines = allText.split(/\r\n|\n/);
		var lines = [];
		var coords = [];

		for (var i=0; i<allTextLines.length; i++) 
		{
			// split the comma seperated values
			var data = allTextLines[i].split(',');
			
			if (data.length >= 3) 
			{
				// create the point object
				var infoWindow = new google.maps.InfoWindow;
 	  
				// set the position from the data
				var point = new google.maps.LatLng(
					parseFloat(data[2]),
					parseFloat(data[1]));
					
				coords.push(point);

				var distance = google.maps.geometry.spherical.computeLength(coords);

				//convert to miles
				var miles = Math.round(distance/1609 * 100) / 100;

				var html = "Time: " + data[0] + "Distance: " + miles + " miles"; // this is the timestamp
				var icon = {};
								
				if ( i == ( allTextLines.length - 2 ) )  // this is 2 because the last line is empty
				{
					// make the last entry a red marker
					icon = customIcons["redPoint"] || {};	
				}
				else
				{
					icon = customIcons["bluePoint"] || {};
				}

				// create the marker
				var marker = new google.maps.Marker(
				{
					map: map,
					position: point,
					icon: icon.icon
				});
				
				// create the info window that displays the timestamp
				bindInfoWindow(marker, map, infoWindow, html);	
			}
		}
		
		// add the coords to the path
		path.setPath(coords);	
	}
		
    function bindInfoWindow(marker, map, infoWindow, html) 
	{
		google.maps.event.addListener(marker, 'click', function() {
			infoWindow.setContent(html);
			infoWindow.open(map, marker);
		});
    }   	
    //]]>
  </script>

  </head>
  <body>
    <div id="map" style="width: 100%; height: 100%"></div>
  </body>

</html>

Comments

Will this work for live data e.g is it possible view the progress of a current journey on the map? or would you need refresh the page?

Jack replied:

A live view would be possible using something like AJAX to retrieve the data, however i am only intending to send updates every 20 seconds to keep mobile data charges down.

Mark replied:

Every 20 seconds would probably be enough. Would be great if you can add this feature.

Respond

Join the discussion

Log in or create an account, and start talking!

Also, have you thought about text message alerts when the vehicle is starts moving?

Jack replied:

That is a good idea! And would be straight forward using the fona 808. You could also wire in an accelerometer and send a text when ever the car is moved.

Respond

Join the discussion

Log in or create an account, and start talking!

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

Jack made a post to Vehicle Tracking Device:

Car Position Web Service

Car Position Web Service

Whilst I am waiting for the parts to turn up, I have been getting on with the first part of the project.  This is the Car Position Web Service.  This shall provide a service that the device can report its position to.  The plan is for this interface to be as simple as possible, and use minimum data bandwidth.

I have opted for using PHP, I have no experience of PHP but it is supported out of the box on my webserver, so I don't need to mess around installing any packages or doing any configuring...

The plan is simple, I will make use of URL parameters to send the longitude and latitude from the the device to the web service by doing the following HTTP GET request (this can be tested in a browser by simply entering it as the page address)

http://www.example.org/car.php?lat=51.5015379&long=-0.1211846

 (You need to replace www.exapmle.org/ with the location that you are hosting your php file)

So in the above example the device would be sending a latitude of 51.5015379 and a longitude of -0.1211846.

This is sent to my car.php file:

<html>
<head></head>
<body>
<?php

// debug line
//echo $_GET['long'] . ',' . $_GET['lat'];

$date = date('Y-m-d H:i:s');

// Set the date of the log file to be based on the date
// so a new file is created each day
$filedate = date('Y-m-d');
$file = 'data/' . $filedate . '.txt';

// create the log text to write to the log using the passed
// in londitude and latitude
// written out in csv format
$output = $date . ',' . $_GET['long'] . ',' . $_GET['lat'] . "\r\n";

// Write the log entry to the log file, 
// FILE_APPEND ensures that the new lone is written to the end of the file
// LOCK_EX locks file access so another process can not modify if whilst 
// writing
file_put_contents($file, $output, FILE_APPEND | LOCK_EX);

?>

</body>
</html>

The above code first creates a string representation of the current date time, this is to be written to the log file as a timestamp.

Next it works out the name of the log file that it should write the position message to.  The plan is that a new file is created each day.  To achieve this the file name is based on the current date.

The output line is next created by concatenating the date string, with the longitude and latitude values that are parsed from the URL.

Finally the output line is written to the end of a log file with the date name created above.  If the file does not exist, then a new one is created.

The car.php file is uploaded to the html root folder on the server and a private data folder is created.  To test, all that is needed is to type the address (as shown above) into a web browser.

After a few goes you should get output like the following in the log file

2016-03-07 11:54:48,-0.1211846,51.5015379
2016-03-07 11:55:24,-0.1211846,51.5015379
2016-03-07 11:55:30,-0.1211846,51.5015379

This is a simple csv format that can be loaded into excel etc. for further processing.  Once I have go the device built and uploading to the server, I will look at either putting this into a standard track file format, or creating an application for quick and visual viewing of the data, probably using google maps.

Comments

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

Jack made a post to Vehicle Tracking Device:

The Plan

The Plan

My plan is to create a car tracking device that is able to track movement of my car.  This would be for recording business mileage, but would also be useful as a security device.

I would like it to have the following functionality:

  • Record position of the car every 20(?) seconds.
  • Record position on a remote server
  • Record position if the car is moved when not switched on
  • Only send data if the car has moved (>10m), in order to reduce data usage (and cost).

In order to achieve this I am intending to use a Adafruit FONA 808 (Thanks to griz11 for pointing this device out to me!).  This is a 2G GSM device that allows mobile phone comms to projects, It also has the added benefit that it includes a GPS device!  I am planning on using a Arduino to control the FONA to retrieve the GPS position and then send it using a data connection to a remote HTTP server. 

The device will run off a LiPo battery (the FONA has a built in LiPo charger), which will power the device when the car is switched off, and then be wired in to the car so that it will get charged up every time the car is running.

I have order the first few parts including the FONA and a Sim card, but the first job is to create the basic HTTP web server to accept the position messages.  This shall be the topic of my next post.

Comments

Mark commented on The Plan:

Great Idea!! I might try to add this to my car computer project.

Jack replied:

That would be possible, the fona can be used with a Pi in a very similar way to how i will be using it with an arduino.

Respond

Join the discussion

Log in or create an account, and start talking!

Post a Comment!

Join the discussion

Log in or create an account, and start talking!