Saturday, April 27, 2013

Hệ thống theo dõi đơn giản mà không có GPS

Here is a simple tracking system which works without a GPS. It gives the tower location to the user. 

To get the tower location check this link. This project is build using the 8051projects board

The user can get the location by sending an sms to the Modem. Just send an sms "location" to the modem and it will send back the tower location back as sms.



 

Xem video bản demo:



Code:


'  Get Location
$regfile = "89S8252.dat"
$large
Config Lcd = 16 * 2
 'define xtal speed
$baud = 9600
$crystal = 11059200


'declare constants
Declare Sub Getline
Declare Sub Send_sms


'LCD connections
Config Lcdpin = Pin , Db4 = P0.2 , Db5 = P0.3 , Db6 = P0.4 , Db7 = P0.5 , E = P0.1 , Rs = P0.0




Dim Temp As Byte
Dim Gps As Byte
Dim Sty As String * 1
Dim Adres As Byte
Dim Value As Byte
Dim Num As String * 10
Dim Disp As String * 16
Dim Inmsg As String * 100


Cursor Off
Cls
Lcd "Initializing"
Lowerline
Lcd "Modem plz wait.."


Wait 10                                                       ' give some time for gsm modem


Print "AT"
Wait 2
Print "ATE0"                                                  'Echo off
Wait 2
Print "AT+CREG?"
Wait 2
Print "AT+CNMI=2,0,2,0,0"                                     'new message indication off
Wait 2
Print "AT+CMGF=1"                                             'change to Text mode
Wait 2
Print "AT+CMGD=1,4"                                           'Delete all sms
Wait 2


Cls
Lcd "Waiting for SMS."




Do
   Print "AT+CMGR=1"                                          'Read for message
   Getline
   If Inmsg <> "OK" Then                                      'got new message
         Num = ","
         Gps = Instr(inmsg , Num)
         Gps = Gps + 5
         Num = Mid(inmsg , Gps , 10)                          'extract the sender number
         Getline                                              'get the message
         Inmsg = Lcase(inmsg)


         Cls
         Lcd "1 Msg Received"
         Lowerline
         Lcd "from:" ; Num
         Wait 1


         If Inmsg = "location" Then
            Print "AT+CSCB=0," ; Chr(34) ; "50" ; Chr(34) ; "," ; Chr(34) ; "0-9" ; Chr(34)       'Read Cell tower location
            Getline
            Getline
            Getline


            Cls
            Lcd "Sending Location"                            'send the location
            Lowerline
            Lcd Inmsg
            Send_sms
         End If


         Wait 1
         Print "AT+CMGD=1,4"                                  'delete all sms
         Wait 1


         Cls
         Lcd "Waiting for SMS."
   End If


   Wait 2


Loop
End
                                                        'continious loop


'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'        SEND SMS
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub Send_sms
    If Num <> "" Then
          Wait 3
          Print "AT+CMGS=" ; Chr(34) ; "+91" ; Num ; Chr(34)       'send sms
          Waitms 200
          Print Inmsg ; Chr(26)
          Wait 5
    End If
End Sub


'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'        Read gsm modem
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub Getline
 Inmsg = ""
 Do
    Gps = Inkey()
    If Gps > 0 Then
       Select Case Gps
        Case 13 : If Inmsg <> "" Then Exit Do                 ' if we have received something
        Case 10 : If Inmsg <> "" Then Exit Do                 ' if we have received something
        Case Else
            Inmsg = Inmsg + Chr(gps)                          ' build string
        End Select
    End If
 Loop


End Sub
'//////////////////////////////////////////////////////////////////////////////


Download code and Hex:Tracking.zip

Nguồn: 8051projects.info



No comments:

Post a Comment