Jack
Published © GPL3+

EM506 GPS Module With PHPoC Blue

This example uses an EM-506 GPS module and Google Map to get and show latitudes and longitudes.

BeginnerShowcase (no instructions)8 hours899
EM506 GPS Module With PHPoC Blue

Things used in this project

Hardware components

PHPoC Blue
PHPoC Blue
×1
EM-506 GPS Module
×1
PHPoC Bread Board
PHPoC Bread Board
×1

Story

Read more

Schematics

EM-506 GPS module with PHPoC Blue

Code

index.php

PHP
It reads GPS data from EM-506 and shows the position on google map.
<?php
include_once "/lib/sd_340.php";

$gps_cmd = _GET("gps");

$latitude = 0.0;
$longitude = 0.0;

if($gps_cmd == "read")
{
	uart_setup(0, 4800);

	$msg = "";
	
	while(1)
	{
		$rbuf = "";
		$read = uart_read(0, $rbuf);
		if($read > 0)
		{
			$msg .= $rbuf;
			if(strpos($msg, "\r\n") !== false)
			{
				$idx = strpos($msg, "\r\n");
				$cmd = substr($msg, 0, $idx);
			
				if(strpos($cmd, "$") !== false)
				{
					$idx = strpos($cmd, "$");
					if(($m_id = substr($cmd, $idx + 1, 5)) !== false)
					{
						if($idx > 0)
						{
							$cmd = substr($cmd, $idx);
						}
						if($m_id == "GPGGA")
						{
							$cmd_crc = str_replace("$", "", $cmd);
							$cmd_crc = str_replace("*", "", $cmd_crc);
						
							$crc = 0;
							$len = strlen($cmd_crc);
							for($i = 0;$i < $len - 2;$i++)
								$crc ^= bin2int($cmd_crc[$i], 0, 1);
								
							$str_crc = substr($cmd_crc, $len - 2);
						
							if(bin2int(hex2bin($str_crc), 0, 1) == $crc)
							{
								$arr = explode(",", $cmd);
							
								$latitude = (int)substr($arr[2], 0, 2) + (float)substr($arr[2], 2, 7) / 60;
								$longitude = (int)substr($arr[4], 0, 3) + (float)substr($arr[4], 3, 7) / 60;
								break;
							}
						}
					}
				}
				$msg = "";
			}
		}
	}
}

?>
<!DOCTYPE html>
<html>
  <head>
    <title>P4S-342</title>
  </head>
  <body align=center>
  	<a href="index.php?gps=read">Read GPS</a><br>
  	<?php
  		if($gps_cmd == "read")
  		{
  			printf("GPS - Latitude: N%.4f, Logitude: E%.4f<br><br>", $latitude, $longitude);
  			printf("<a href=http://maps.google.com/?q=%f,%f&hl=en target=_g_map>View in Google Map</a>", $latitude, $longitude);
		}
  	?>
  </body>
</html>

Credits

Jack

Jack

5 projects • 9 followers

Comments