'GSM Alarm 'ap0cn3t@gmail.com 'http://alumni.ipt.pt/~pmad/index.php Option Explicit Private Const INPUT_PIN As Byte = 6 Private Const OUTPUT_PIN As Byte = 10 Private Const COM_BAUD As Long = 19200 Private Const INPUT_BUFFER_SIZE As Integer = 60 Private Const OUTPUT_BUFFER_SIZE As Integer = 45 Private InputBuffer(1 To INPUT_BUFFER_SIZE) As Byte Private OutputBuffer(1 To OUTPUT_BUFFER_SIZE) As Byte Sub Main() Dim Hours as Integer Dim Data(1 to 100) As Byte Dim Counter As Integer Const InputPin As Byte = 8 Call PutPin(InputPin, bxInputPullup) Call InitializeCOM(3) Debug.Print "Initializing..." delay(40.0) Debug.Print "Initialized" Do Hours = GetHour() Debug.Print "Hour: " & CStr(Hours) If ((Hours > 0) And (Hours < 7)) Or (Hours = 23) Then Debug.Print "Motion Sensor ON" Call PutPin(11, 0) Dim N as Integer For N = 1 To 25000 If GetPin(InputPin) = 1 Then Debug.Print "Alarm Triggered" Call CloseCom(3, InputBuffer, OutputBuffer) delay(1.0) Call InitializeCOM(3) delay(1.0) Call PutQueueStr(OutputBuffer, "at+cmss=1,123456789" & Chr(13)) '123456789=cellphone number Call PutPin(11, bxInputPullup) Counter = 0 Do while Counter < 10 Call PutQueueStr(OutputBuffer, "ata" & Chr(13)) delay(5.0) Counter = Counter +1 Loop delay(40.0) Debug.Print "Motion Sensor ON" Call PutPin(11, 0) End If Next Debug.Print "Motion Sensor OFF" Else Debug.Print "Sleeping..." Delay(1800.0) End If Loop Call CloseCom(3, InputBuffer, OutputBuffer) End Sub '------------------------------------------------------------------------------- Public Function GetHour() As Integer Call CloseCom(3, InputBuffer, OutputBuffer) Call InitializeCOM(3) delay(0.5) Dim Data(1 to 60) As Byte Call PutQueueStr(OutputBuffer, "at+cclk?" & Chr(13)) delay(1.0) Dim BufferSize As Integer BufferSize = GetQueueCount(InputBuffer) Call GetQueue(InputBuffer, Data, BufferSize) Dim Hour as Integer Dim N as Integer For N = 1 To BufferSize If Data(N) = 44 then Hour = Cint(Data(N+1)-48) Hour = Hour*10 Hour = Hour + Cint(Data(N+2)-48) Exit For End If Next GetHour=Hour End Function '------------------------------------------------------------------------------- Public Sub InitializeCOM(ByVal COM_PORT As Byte) Call OpenQueue(InputBuffer, INPUT_BUFFER_SIZE) Call OpenQueue(OutputBuffer, OUTPUT_BUFFER_SIZE) Call DefineCom3(INPUT_PIN, OUTPUT_PIN, bx0000_1000) Call OpenCom(COM_PORT, COM_BAUD, InputBuffer, OutputBuffer) End Sub '-------------------------------------------------------------------------------