Option Explicit Option StringSize 50 '50 chars default Option Base 1 'arrays start with 0 not 1 '======================================================================================== 'Module Title: I_Connector_R2.Bas '======================================================================================== 'Author: ZbasicAndy '======================================================================================== 'Date: 4-4-2006 '======================================================================================== 'Operating System: XP '======================================================================================== 'ZBasic IDE Version: 1.0.4 / ZBasic Compiler version 1-1-18 / ZX-40 Firmware 1.1.6 '======================================================================================== 'Target: ZX-40 '======================================================================================== 'Hardware: "Super Comm Z R1" ([4 software serial & 1 Hardware] RS232 port ZX-40 PCB) 'Main/Support Modules Needed: ComSupport_R4.bas - for basic serial communications subroutines. ' Super_Comm_Z_R1.bas - "sub main" basic module '======================================================================================== 'Comport used: ZX-40 Comport4 9600 @ 8 N 1 -> Keep the parameters the same! 'To change to another port just "replace" Port4 with "Port?" or 3,4,5 or 6. '======================================================================================== 'Bugs fixes and updates: ' ' ' ' ' '======================================================================================== 'Module Description: ' 'The I-Connector can be used for home automation (home security/emergency email/SMS Cell 'Phone notification) or industrial machine to machine automation. ' 'This application is "completely stand-alone" - NO Running PC Is Required but you do 'need a RS232 analog modem with a dial-in ISP. 'An adjustable email "body text" can be changed under program control using the a standard 'global string text variable. ' 'Home security monitoring services cost between $20 - $30 per month! Having "false alarms" 'from a home security system might also cost you in fines or no police coverage. 'Using this ZX-xx / "Super Com Z" Email/SMS Cell Phone Alert System will provide a very low 'cost alternative security or backup system. ' '------------------------------------------------------------------------------------------- ' [What is ConnectOne's I-Connector? (Lite version with special "send only email" firmware)] ' ConnectOne's I-Connector is a small dongle with a 9 pin RS232 male connector for ' modem connection and a 9 pin female for host ZX-xx or "Super Com Z" for ' computer controlled internet PPP connectivity. Inside this dongle there is a iChip which ' takes the burden or critical CPU overhead/timing away the from host - ZX-xx. The dongle has ' a flash (non-volatile) setup pages which uses your ISP setup information to connect to the ' internet. This has to be programmed in the dongle via application iChip config. utility on ' the PC, a serial RS232 PC comport 1 and a cable ' connecting the PC to the device end along with a +5VDC regulated power supply to power ' the I-Connector. Once this information is programmed into this iChip and by using the ' built in dumb terminal program, this dongle can be thoroughly tested/simulated BEFORE ' attaching the I-Connector to the "host" e.g. "Super Com Z". The host just sends a few strings via ' serial RS232 to the dongle to dial, to connect, to send email/SMS text to the recipient ' and then exits and hangs-up. '--------------------------------------------------------------------------------------------- '[Parts Needed for the "Super Com Z" Email/SMS Cell Phone Alert System ] ' ' Qty: Description: ' 1 I-Connector ("Lite version") from ConnectOne.com PN# iC100-FM-I-1 ' (Special order Email "send only" firmware version only!)~ $45.00. + shipping? ' Go to ConnectOne.com for further information. ' Note: The older I-Connector is too expensive for home use. ~ $90-$100. ' 1 Analog modem Hayes AT compatible (try to obtain one with troubleshooting lights ' Pwr,OH,Tx & Rec) - Try eBay ~ $30.00. ' Note: I used a miniature Bluetooth Zoom modem (model #4300) that also has a RS232 ' port on it (switchable). ~ $59.00. ' Note: You can also use this modem to de-code for Caller-ID. ' Note: If you use my modem make sure to flip the selector switch from Bluetooth ' to RS232! ' 1 5 VDC 100 ma. regulated power supply to power the I-Connector on pin 9. ' On the "Super Com Z" I put a +5vdc jumper to pin 9 to power this device. ' 1 ISP (Internet Service Provider) with modem dial-in capability ' (Most do for remote laptop dial-in) Please check. ' 1 Cell Phone with Text Messaging (SMS - Short Message Service) capability. ' T-Mobile has a "pay as you go plan" ' with unlimited (recieve only) text messaging. Please make sure you can email ' a SMS message from your internet email. ' T-Mobile procedure is "email recipient to" = (cell phone number) ' ##########@tmomail.net ' Note: You need an ISP (with dial-in service) to recieve the email alert ' messages but having a Cell Phone with (SMS) is optional. '------------------------------------------------------------------------------------------- ' ' After you read and test your I-Connector dongle with the vendor support software ' then all you have to do is to supply an email text message to the subroutine below ' to transmit the message to the cell phone or email recipient. ' ' ' ' '========================================================================================= ' ' '========================================================================================= 'Program Definitions: '========================================================================================= '========================================================================================= 'Constants '[Public | Private] Const As = (default private) '========================================================================================='----------------------------- ' Port Constants for all ports '----------------------------- ' Do not modify! Private Const Port3 as byte = 3 Private Const Port4 as byte = 4 Private Const Port5 as byte = 5 Private Const Port6 as byte = 6 '----------------------------- '========================================================================================= 'Variables '{Public | Private | Dim} As (default private) '========================================================================================= '========================================================================================= 'Subroutines '========================================================================================= ' Public Sub IC_Send_Email(ByRef Email_Message as string, ByRef Email_Completed as Boolean) Dim Init_IC_OK as Boolean Dim Retry as Byte Dim Email_Sent_OK as BOOLEAN Dim Counter as byte Retry = 3 Counter = 0 Init_IC_OK = False Call Init_IC(Init_IC_OK) if (Init_IC_OK = False) then Debug.Print "IC Init Failure!" Email_Completed = false end if Restart: If Counter >= 3 then Debug.Print "Email Send Failure!" Email_Completed = False Exit sub End if Counter = Counter + 1 ClearInputBuffer(port4) ClearOutputBuffer(port4) Debug.print "Email Message Retry Counter = "; cstr(counter) Email_Sent_OK = False CALL Send_Email(Email_Message,Email_Sent_OK) ' Send email If (Email_Sent_OK) then Email_Completed = True ClearInputBuffer(port4) ClearOutputBuffer(port4) Exit Sub Else Debug.print "Delay Of 30 Seconds Between Retries ..." Call Delay(30.0) 'Wait 30 seconds before retrying GoTo Restart End If End Sub '======================================================================================== Private Sub Init_IC(ByRef Init_IC_OK as BOOLEAN) dim tx as string Dim rx as string Dim success as boolean dim rb as byte Dim rba(7) as byte Dim i as byte Dim counter as byte rx = "" counter = 0 Restart: Counter = counter + 1 If counter >= 3 then Init_IC_OK = false exit sub end if ClearOutputBuffer(port4) ClearInputBuffer(port4) 'Shutdown the @$&% Echo CALL PutByte(Port4,&H41) call delay(0.05) CALL Getbyte(Port4,rb,success) 'Debug.Print chr(rb) CALL PutByte(Port4,&H54) call delay(0.05) CALL Getbyte(Port4,rb,success) 'Debug.Print chr(rb) CALL PutByte(Port4,&H2B) call delay(0.05) CALL Getbyte(Port4,rb,success) 'Debug.Print chr(rb) CALL PutByte(Port4,&H69) call delay(0.05) CALL Getbyte(Port4,rb,success) 'Debug.Print chr(rb) CALL PutByte(Port4,&H45) call delay(0.05) CALL Getbyte(Port4,rb,success) 'Debug.Print chr(rb) CALL PutByte(Port4,&H30) call delay(0.05) CALL Getbyte(Port4,rb,success) 'Debug.Print chr(rb) CALL PutByte(Port4,&H0D) call delay(0.05) CALL Getbyte(Port4,rb,success) 'Debug.Print chr(rb) 'Debug.Print CALL Getbyte(Port4,rb,success) 'lf 'Debug.Print cstrhex(rb) 'Debug.Print For i = 0 to 3 Call Getbyte(Port4,rba(i),success) next Rx = chr(rba(0)) & chr(rba(1)) & chr(rba(2)) & chr(rba(3)) 'Debug.print "rx ="; rx 'should be I/OK If (Rx = "I/OK") then Debug.Print "I-Connector Hardware is OK! " Init_IC_OK = True Else Debug.Print "Init I-Connector Retry Counts = " ; cstr(counter) Goto Restart End If ClearOutputBuffer(port4) ClearInputBuffer(port4) End Sub '-------------------------------------------------------------------------------- Private Sub Send_Email(ByRef Email_Message as string, ByRef Email_Sent_OK as BOOLEAN) dim tx as string dim rx as string Dim rba(8) as byte dim i as byte dim Success as Boolean dim Num_Char as Byte ClearInputBuffer(port4) ClearOutputBuffer(port4) rx = "" tx = "AT+iUP:0" success = false Call PutStr(Port4,Tx) 'Dial ISP CALL PutByte(Port4,13) 'CR call delay(5.0) For i = 0 to 3 Call Getbyte(Port4,rba(i),success) next Rx = chr(rba(0)) & chr(rba(1)) & chr(rba(2)) & chr(rba(3)) debug.print "Dialing Response = " ; rx If Rx = "I/OK" then Debug.Print "Dialing ISP ... " Else Debug.Print "I-Connector Response Failure! " Email_Sent_OK = false Exit sub End If ClearInputBuffer(port4) Call delay(80.0) 'wait 60 seconds - adjustable for ISP For i = 0 to 7 'Get response bytes Call Getbyte(Port4,rba(i),success) next 'Response should be I/ONLINE Rx = chr(rba(0)) & chr(rba(1)) & chr(rba(2)) & chr(rba(3)) & _ chr(rba(4)) & chr(rba(5)) & chr(rba(6)) & chr(rba(7)) debug.print "OnLine Response = " ; Rx If Rx = "I/ONLINE" then Debug.Print "I-Connector OnLine!" Else Debug.Print "I-Connector Not OnLine! " tx = "AT+iDOWN" ' Call PutStr(Port4,Tx) 'Terminate and Hangup CALL PutByte(Port4,13) 'CR CALL delay(10.0) ' wait 1 sec Email_Sent_OK = false Exit sub End If ClearInputBuffer(port4) ClearOutputBuffer(port4) Tx = "AT+iEOA:" Call PutStr(Port4,Tx) 'Send Email Message Body Command Call Delay (0.50) Tx = Email_Message Debug.print "Email Message To Send = "; Tx Call PutStr(Port4,Tx) 'Send Email Message (Global Variable String - max 20 chars) Call Delay (0.50) Call PutByte(Port4,13) 'CR CALL delay(0.05) ' small delay Call PutByte(Port4,46) '. -> The . is needed to terminate the message! Call delay(0.05) Call PutByte(Port4,13) 'CR Call delay(5.0) For i = 0 to 3 Call Getbyte(Port4,rba(i),success) Next Rx = chr(rba(0)) & chr(rba(1)) & chr(rba(2)) & chr(rba(3)) Debug.print "Email Message Completion Response = " ; Rx If Rx = "I/OK" then Debug.Print "Email Sent! ... Hanging Up! ..." Email_Sent_OK = True ClearInputBuffer(port4) ClearOutputBuffer(port4) CALL delay(10.0) ' wait 10 sec Exit Sub Else Debug.Print "Email Was NOT Sent!" Email_Sent_OK = False tx = "AT+iDOWN" ' Call PutStr(Port4,Tx) 'Terminate and Hangup CALL PutByte(Port4,13) 'CR CALL delay(1.0) ' wait 1 sec ClearInputBuffer(port4) ClearOutputBuffer(port4) End If End Sub '=============================================================================================