Instruction manual

Model DCP-NextG Digital Cell Phone Kit
21
8.1 Example Program
The following program example sends a single SMS, when the temperature of a thermocouple
exceeds 30 degrees celcius.
' This program demonstrates how to use the CR1000 serial instructions to send an SMS
' using a SAM3G+ modem
'
' === WIRING ==========================================================================
'
' ComRS232 Intercel SAM3G+
'
' P1 Switch +, (red wire)
' G Switch -, (black wire)
'
' === DECLARATIONS ====================================================================
' -- Constants ------------------------------------------------------------------------
Const COMPORT = ComME ' Comport Used for Serial I/O
' -- Public Variables -----------------------------------------------------------------
Public Batt_Volt ' Battery supply voltage
Public P_Temp ' The logger's wiring panel temperature
Public AirTemp_TC ' Air temperature as measured by a thermocouple
Units Batt_Volt = "V"
Units P_Temp = "degC"
Units AirTemp_TC = "degC"
' === SUB ROUTINES ====================================================================
Public SMS_PhNo As String ' The cellphone number of the recipient
Public SMS_Msg As String * 160 ' The SMS message to send
Public SMS_Result ' Set to 0 when there has been an error sending an sms
' === DATA TABLES =====================================================================
'Data table to store ten minute temperature data
DataTable (TenMin,1,-1)
DataInterval (0,15,Sec,10)
Minimum (1,Batt_Volt,FP2,0,False)
Sample (1,P_Temp,FP2)
Average (1,AirTemp_TC,FP2,False)
Maximum (1,AirTemp_TC,FP2,False,False)
Minimum (1,AirTemp_TC,FP2,False,False)
EndTable
' Datatable to store the last 100 messages sent by the modem
DataTable (SMSSent,True,100)
Sample (1,SMS_Result,FP2)
Sample (1,SMS_PhNo,String)
Sample (1,SMS_Msg,String)
EndTable
Sub SMSSend
' Open the serial port
SerialOpen (COMPORT,115200,3,0,1000)
' Send the SMS command to the modem (eg. AT+CMGS=0412345678) and wait for ">" to be
' returned
SMS_Result = SerialOut (COMPORT,"AT+CMGS=" + CHR(34) + SMS_PhNo + CHR(34) + CHR(13),">",1,100)