'*************Designed By. Engr. Tarique R. Memon '************Realtime GPS Tracking for Car 'Latitude lanog, speed & Battery enabled 'web server iot.electronixforu.com 'Hardware: self made PCB for atmega328p '*************GPRS based Car Security '******GSM Model: Neoway GSM M590 '*******GPS Model: VK16E ublox '*************arduino nano crystal Frequency=16MHz External Low ffh, High DEh '********************chip: atmega328p*************************** '*****portd.6 is connected with RX of GSM, pd6 is tx ,IC PIN 12 '*****portd.5 is connected with TX of GSM, pd5 is rx IC PIN 11 '*****portb.0 is connected with TX of GPS, pb0 is rx IC PIN 14 '***********8BATTERY SENSOR WITH , ADC 5 ' chr(13) is Enter key, chr(10)=Line feed, chr(34)=inverted commas, chr(26)=SUB Cntrol Z ' chr(13) not supported in sms for new line 'Help is available at electronixforu.com/iot.php ' link of this file is electronixforu.com/rtgps.php $regfile = "m328pdef.dat" '$regfile = "m328pdef.dat" $crystal = 16000000 $baud = 9600 Set Portc.2 'SILENCE @INITIAL '***********define variables for GPS****** Dim Xr(15) As String * 10 Dim Yr(14) As String * 10 Dim L As String * 72 Dim M As String * 72 Dim N As String * 72 Dim O As String * 72 Dim P As String * 72 Dim Spd As String * 10 Dim Tim As String * 9 Dim Latt As String * 10 Dim Lon As String * 10 Dim Alt As String * 7 Dim Spd_unit As String * 3 Dim Latt_dir As String * 1 Dim Lon_dir As String * 1 Dim Lat_real As Single 'Dim Alt As String * 6 Dim Alt_unit As String * 2 Dim Spd_v As Single 'SPEED AS NUMERIC VALUE Dim U As Byte Dim W As Byte Dim Length As Byte '*******battery parameters Dim Vol As Word Dim Volt As Single Dim Battery As String * 6 '**********initializing pins Dim Volt_sms_count As Byte Brake Alias Portb.2 : Config Portb.2 = Output Ind Alias Portb.1 : Config Portb.1 = Output Beep Alias Portc.2 : Config Portc.2 = Output Ke Alias Pind.2 : Config Pind.2 = Input 'assign variable Dim Host As String * 24 Dim Get_req As String * 24 Dim Api_key As String * 20 Dim Field1 As String * 8 Dim Field2 As String * 8 Dim Field3 As String * 8 Dim Field4 As String * 8 Dim Http As String * 9 Dim Host1 As String * 8 Dim Connection As String * 30 '****strings Host = "iot.electronixforu.com" Get_req = "GET /post.php?api_key=" Api_key = "5a78c16328e5f" 'test user Field1 = "&field1=" Field2 = "&field2=" Field3 = "&field3=" Field4 = "&field4=" Http = " HTTP/1.1" Host1 = "Host: " Connection = "Connection: close" 'Magnet Alias Pind.7 : Config Pind.7 = Input Print "starting" Print "firmware: realtime_security_car_trm_06022018_atmega328p" Print "Developed for Suzuki Mehran car" Config Adc = Single , Prescaler = Auto , Reference = Avcc Wait 15 Start Adc '*********opening ports software uart for GSM******* Open "comd.6:9600,8,n,1" For Output As #1 Open "comd.5:9600,8,n,1" For Input As #2 '*********opening ports software uart for GPS******* Open "comb.0:9600,8,n,1" For Input As #3 Wait 15 Restart: Print " opened" Gosub Gsm_init '*******MAIN PROGRAM******************************************************* 'Dim Resp As String * 20 'Dim Resp1 As String * 20 'Dim Resp2 As String * 20 Do Print#1 , "AT+TCPSETUP=0,192.169.92.6,80" ; Chr(13) ; Chr(10); Gosub Scan_all Wait 1 Print#1 , "AT+TCPSEND=0," ; Length ; Chr(13) ; Chr(10); Waitms 400 Print#1 , Get_req ; Api_key ; Field1 ; Latt ; Field2 ; Lon ; Field3 ; Spd ; Field4 ; Battery ; Http ; Chr(13) ; Chr(10); Waitms 100 Print#1 , Host1 ; Host ; Chr(13) ; Chr(10); Waitms 100 Print#1 , Connection ; Chr(13) ; Chr(10) ; Chr(13) ; Chr(10); Wait 2 Print#1 , "AT+TCPCLOSE=0" ; Chr(13) ; Chr(10) ; Waitms 100 Print#1 , "AT+TCPCLOSE=0" ; Chr(13) ; Chr(10); Waitms 800 Loop Close#1 Close#2 Close#3 '**********8GSM Initialize*********** Gsm_init: Print#1 , "AT&D2" Wait 1 Print#1 , "AT+XISP=0" Wait 1 Print#1 , "AT+CGDCONT=1," ; Chr(34) ; "IP" ; Chr(34) ; "," ; Chr(34) ; "zonginternet" ; Chr(34) Wait 3 Print#1 , "AT+XIIC=1" Wait 5 Return ' ################scan all parameters**GPS,VOLT, TEMP,KEY,LOCK_status#################### '******************************************************************* Scan_all: Print "Scan All" Gosub Gps_dta Gosub Voltage Gosub Get_length Return '*car voltage check Voltage: Print "Get voltage" Vol = Getadc(5) Volt = Vol / 40.96 Battery = Fusing(volt , "##.#") Return '***car switch check '************GPS data************* Gps_dta: Input#3 , L Input#3 , M Input#3 , N Input#3 , O Input#3 , P Print "GPS Data" '**********l filter*********** If Mid(l , 1 , 6) = "$GPGGA"then U = Split(l , Xr(1) , ",") Elseif Mid(l , 2 , 6) = "$GPVTG"then W = Split(l , Yr(1) , ",") End If '***********M filter*********** If Mid(m , 1 , 6) = "$GPGGA"then U = Split(m , Xr(1) , ",") Elseif Mid(m , 2 , 6) = "$GPVTG"then W = Split(m , Yr(1) , ",") End If '***********N filter*********** If Mid(n , 1 , 6) = "$GPGGA"then U = Split(n , Xr(1) , ",") Elseif Mid(n , 2 , 6) = "$GPVTG"then W = Split(n , Yr(1) , ",") End If '***********O filter*********** If Mid(o , 1 , 6) = "$GPGGA"then U = Split(o , Xr(1) , ",") Elseif Mid(o , 2 , 6) = "$GPVTG"then W = Split(o , Yr(1) , ",") End If '***********P filter*********** If Mid(p , 1 , 6) = "$GPGGA"then U = Split(p , Xr(1) , ",") Elseif Mid(p , 2 , 6) = "$GPVTG"then W = Split(p , Yr(1) , ",") End If Print "time: " ; Xr(2) Print "lat: " ; Xr(3) ; Xr(4) 'position, direction(N/S) Print "lon: " ; Xr(5) ; Xr(6) 'position, direction(N/S) Print "Alt: " ; Xr(10) ; Xr(11) 'speed, unit Print "spd: " ; Yr(8) ; Yr(9) Gosub Lat_convert Gosub Lon_convert 'Tim = Left(xr(2) , 6) Spd = Yr(8) Spd_unit = Yr(9) Alt = Xr(10) Alt_unit = Xr(11) Latt_dir = Xr(4) Lon_dir = Xr(6) Spd_v = Val(spd) If Spd_v <= 00 Then Spd = "0.0" End If Wait 1 Return '**Time conversion in PST and splited in colon: '**latitude conversio Lat_convert: Print "LAT_convert" Dim Lat_deg As String * 10 Dim Lat_min As String * 10 Dim Lat_deg_single As Single Dim Lat_min_single As Single Lat_deg = Mid(xr(3) , 1 , 2) Lat_deg_single = Val(lat_deg) Lat_min = Mid(xr(3) , 3 , 7) Lat_min_single = Val(lat_min) Lat_min_single = Lat_min_single / 60 Lat_real = Lat_deg_single + Lat_min_single Print Lat_deg_single Print Lat_min_single Latt = Fusing(lat_real , "#.####") Print Latt Return '**longitude conversio Lon_convert: Print "LON convert" Dim Lon_deg As String * 10 Dim Lon_min As String * 10 Dim Lon_deg_single As Single Dim Lon_min_single As Single Dim Lon_real As Single Lon_deg = Mid(xr(5) , 1 , 3) Lon_deg_single = Val(lon_deg) Lon_min = Mid(xr(5) , 4 , 7) Lon_min_single = Val(lon_min) Lon_min_single = Lon_min_single / 60 Lon_real = Lon_deg_single + Lon_min_single Print Lon_deg_single Print Lon_min_single Lon = Fusing(lon_real , "#.####") Print Lon Return Get_length: Print "length" Length = 0 Length = Len(latt) + Len(lon) Length = Length + Len(spd) Length = Length + Len(battery) Length = Length + Len(get_req) Length = Length + Len(api_key) Length = Length + Len(field1) Length = Length + Len(field2) Length = Length + Len(field3) Length = Length + Len(field4) Length = Length + Len(http) Length = Length + Len(host1) Length = Length + Len(host) Length = Length + Len(connection) Length = Length + 8 Return