CON _clkmode = xtal1 + pll16x ' Crystal and PLL settings. _xinfreq = 5_000_000 ' 5 MHz crystal (5 MHz x 16 = 80 MHz). TAB = $09 CR = $0D SP = $20 LF = $0A QT = $22 COLON = $3B SEMICOLON = $3A EEPROM1 = %1010_000_0 ' address for i2c eeprom EEPROM2 = %1010_001_0 ' address for i2c eeprom CRLF = $0D0A '/// Inputs and Outputs XTENDDO = 0 XTENDDI = 1 WiFlyDO = 2 WiFlyDI = 3 P4 = 4 P5 = 5 P6 = 6 P7 = 7 p8 = 8 'Unused p9 = 9 'Unused p10 = 10 'Unused WiflyPwr = 11 DVPwr = 12 DVRec = 13 p14 = 14 'Unused M1Pwr = 15 M1Batt = 16 Misc12v = 17 Shutdown = 18 'XTEND high to send M2Pwr = 19 M2Batt = 20 NetGear = 21 Misc5v1 = 22 Buzz = 23 C1 = 24 ' contact inputs C2 = 25 C3 = 26 C4 = 27 PropTXPIN = 30 'To GUI PropRXPIN = 31 'From GUI VAR LONG SerialStack[128], TimeString BYTE Response[1024], buffer, chksum, voll, IP[16], clearspace[3], devin, devout, uartin, uartout BYTE IPout, sensorin BYTE IPstring[17], C1S, C2S, C3S, C4S, CM1S, CM2S, CM3S, CM4S, confirmflag, DVS, RECFLAG, concounter BYTE MifiSelect, day, hour, minute, offtimer OBJ ser :"FullDuplexSerial4Port" ''''''timer : "timer2" i2c1 : "CLEAN_minimali2cdriversmall" PUB Start | value, i, counterold INIT repeat PUB Init voll := 11 ' buzzer volume beep(19, 2300, 100) StartSerial '0 = XTEND 1 = GUI 2 = WIFLY 3 = LCD PUB dataforward |d, u ' dev = wifi out p5 (Port,rxpin,txpin) devin := ser.rxtime(1,1) if devin <> $FF ser.tx(2, devin) uartin := ser.rxtime(2,1) if uartin <> $FF ser.tx(1, uartin) PUB TestLANcon | i ser.str(1, string("TESTING LAN CONNECTION")) ser.tx(1, CR) ser.str(2, string("$$$")) Viewreply ser.str(2, string("open 192.168.1.1 80")) 'eyebox1984.com ser.tx(2, CR) Viewreply Viewreply ser.str(2, string("GET / HTTP/1.1")) 'GET / required to see a response ser.tx(2, CR) 'must be CR ser.tx(2, LF) 'must be LF RecWifiData 'repeat 19 'Getreply ser.str(2, string("exit")) ser.tx(2, CR) '''''TEST the response here '''''Parse for some info to determine a successful connection i := 0 repeat 512 ' start checking the string for 'time' reply with the timer value if response[i] == "A" if response[i+1] == "d" if response[i+2] == "m" if response[i+3] == "i" if response[i+4] == "n" w(10_000_000) beep(buzz, 2700, 50) w(6_000_000) beep(buzz, 2600, 50) w(6_000_000) beep(buzz, 2700, 50) w(6_000_000) beep(buzz, 2600, 50) w(6_000_000) beep(buzz, 2700, 50) w(6_000_000) beep(buzz, 2600, 50) ser.str(1, string("**LAN CONNECTION OK**")) ser.tx(1, CR) 'ForceClose Return 1 i++ 'ForceClose PowerONDVR ' if no connection to LAN, turn on DVR PUB TestConnection | i GetReply GetReply GetReply GetReply GetReply GetReply EX Getreply SetIdle5 ser.str(1, string("TESTING INTERNET CONNECTION")) ser.tx(1, CR) Viewreply SetIdle5 ser.str(1, string("**ENTERING COMMAND MODE=**")) ser.tx(1, CR) ser.str(2, string("$$$")) Viewreply ser.str(2, string("open xxxxxxxx.com 80")) ' ser.tx(2, CR) Viewreply 'must wait for connection to open before sending GET Viewreply 'time needed here to get connected, needs OPEN detection Viewreply 'before proceeding or time out, error if no detect ser.str(2, string("GET /connectcheck.php HTTP/1.1")) ser.tx(2, CR) 'must be CR ser.tx(2, LF) 'must be LF ser.str(2, string("Host: xxxxxxxx.com")) ' ser.tx(2, LF) ' two LF required ser.tx(2, LF) ' CR or LF works TESTED 'viewreply 'DEBUG 'viewreply 'DEBUG 'viewreply 'DEBUG 'viewreply 'DEBUG 'viewreply 'DEBUG 'viewreply 'DEBUG 'return 1 'DEBUG RecWifiData i := 0 repeat 1024 if response[i] == "2" if response[i+1] == "0" if response[i+2] == "0" beep(buzz, 2000, 50) w(6_000_000) beep(buzz, 2100, 50) w(6_000_000) beep(buzz, 2200, 50) w(6_000_000) beep(buzz, 2300, 50) w(6_000_000) beep(buzz, 2400, 50) w(6_000_000) beep(buzz, 2500, 50) ser.str(1, string("**CONNECTION OK**")) ser.tx(1, CR) If RECFLAG == 0 PowerOFFDVR 'if connection, turn OFF DVR 'NetGearPowerOff SetIdle2 Return 1 i++ ser.str(1, string("**NO CONNECTION**")) ser.tx(1, CR) offtimer++ beep(buzz, 2000, 50) w(6_000_000) beep(buzz, 1900, 50) w(6_000_000) beep(buzz, 1800, 50) w(6_000_000) beep(buzz, 1700, 50) w(6_000_000) beep(buzz, 1600, 50) w(6_000_000) beep(buzz, 1500, 50) ForceClose '******** ' FOR <<>> MIFI SETUP reboot the MIFI and RETURN SetIdle2 Return -1 PUB ReBootWifly | x X:= 0 StartSerial w(40_000_000) ser.tx(1, CR) WiflyToggle '''' jump straight to recwifi to see what comes in after rebooting wifly Repeat until DetectWiFlyReady == 1 ''' WAIT HERE until wifly is ready WiflyToggle IF X == 2 quit ' go back out to main loop X++ ' use to escape this repeat if no response PUB DetectWiFlyReady | i RecWifiData i := 0 repeat 1024 ' look for Associated! if response[i] == "i" if response[i+1] == "a" if response[i+2] == "t" if response[i+3] == "e" if response[i+4] == "d" w(6_000_000) beep(buzz, 2000, 50) w(6_000_000) beep(buzz, 2000, 50) w(6_000_000) beep(buzz, 2000, 50) ser.str(1, string("**WIFLY READY**")) ser.tx(1, CR) Return 1 i++ ser.str(1, string("**WIFLY NOT READY**")) Return -1 PUB WiflyToggle StartSerial ser.str(1, string("**WIFLY SOFTBOOT**")) ser.tx(1, CR) EX CMD WiflySoftboot PUB WiflyPwrToggle outa[WiflyPwr] := 1 'def=0 Normally closed 0 = power ON w(80_000_000) outa[WiflyPwr] := 0 'def=0 Normally closed 0 = wifly power ON PUB RecWifiData | ii, val, n 'copy content of incoming message to an array ii := 1 response[0] := ser.rxtime(2, 1000) 'waits here for first byte response for 2 seconds Repeat 1023 'look for more, else return Val := ser.rxtime(2, 10) 'read more, wait only 2 ms if no byte found response[ii] := Val ii++ ''''D E B U G O U T P U T''' n := 0 ser.tx(1, CR) repeat 1024 'get the response here from the load command 'if response[n] < $FF ser.tx(1, response[n]) ' N O T E : This extra time seems to help keep GETIP consistent. DO NOT DELETE n++ ''''N O T E : THIS method takes around 10 seconds to complete if no data found. 1 second at top, ''''''''''''''''' then 1000 * 10ms followed by a display of whatever was rec'd PUB ViewReply repeat 512 'get the response here from the load command buffer := ser.rxtime(2,1) if buffer < $FF ser.tx(1, buffer) PUB Pause ser.str(1, string("**PAUSE**")) ser.tx(1, CR) 'must be CR EX SetIdle2 Repeat 15 ' ******* 10 seconds MINIMUM required buffer time********** w(80_000_000) SetIdle5 PUB GetIP SetIdle5 ser.str(1, string("**GETTING IP**")) ser.tx(1, CR) ser.tx(1, CR) Viewreply ser.str(1, string("**ENTERING COMMAND MODE=**")) ser.tx(1, CR) ser.str(2, string("$$$")) Viewreply ser.str(2, string("open getip.dyndns.org 80")) ser.tx(2, CR) Viewreply 'must wait for connection to open before sending GET Viewreply ser.str(2, string("GET /index.php HTTP/1.1")) ser.tx(2, CR) 'must be CR ser.tx(2, LF) 'must be LF ser.str(2, string("Host: getip.dyndns.org")) ser.tx(2, LF) ' two LF required ser.tx(2, LF) ' CR or LF works TESTED RecWifiData ShowWifiResponse ser.str(1, string("**GET IP DONE**")) ser.tx(1, CR) SetIdle2 ''NOTES if it does not open the connection, then the device is stuck in ''CMD mode until either it gets told to exit, or ot connects on a subsquent ''request. PUB SendEmail | i SetIdle5 ReadContacts ReadMem ser.str(1, string("**SENDING EMAIL**")) ser.tx(1, CR) FormatIP ser.str(1, string("**ENTERING COMMAND MODE=**")) ser.str(2, string("$$$")) Viewreply ser.str(2, string("open xxxxxxx.com 80")) ser.tx(2, CR) Viewreply 'must wait for connection to open before sending GET Viewreply ser.str(2, string("GET /emailstatus.php?IP=")) ser.str(2, @ip) ser.str(2, string("&TIMER=")) '' now send the timer ser.str(2, timer.showTimer) ser.str(2, string("&C1=")) '' ser.hex(2, C1S,1) ser.str(2, string("&C2=")) '' ser.hex(2, C2S,1) ser.str(2, string("&C3=")) '' ser.hex(2, C3S,1) ser.str(2, string("&C4=")) '' ser.hex(2, C4S,1) ser.str(2, string("&CM1=")) '' ser.hex(2, CM1S,1) ser.str(2, string("&CM2=")) '' ser.hex(2, CM2S,1) ser.str(2, string("&CM3=")) '' ser.hex(2, CM3S,1) ser.str(2, string("&CM4=")) '' ser.hex(2, CM4S,1) ser.str(2, string("&MIFI=")) '' ser.hex(2, MIFIselect, 1) ser.str(2, string("&DVS=")) '' ser.hex(2, DVS, 1) ser.str(2, string(" HTTP/1.1")) ser.tx(2, CR) 'must be CR ser.tx(2, LF) 'must be LF ser.str(2, string("Host: xxxxxxxx.com")) ser.tx(2, LF) 'two LF required ser.tx(2, LF) 'CR or LF works TESTED Viewreply Viewreply ser.str(1, string("**EMAIL DONE**")) ser.tx(1, CR) 'must be CR SetIdle2 PUB WiflyGetEverything ser.str(2, string("$$$")) ViewReply ser.str(2, string("get everything")) ser.tx(2, CR) ViewReply ViewReply ViewReply PUB ConfigWifly Ex ViewReply Ex ViewReply ser.str(2, string("$$$")) ViewReply ser.str(2, string("set ip address 192.168.1.6")) ser.tx(2, CR) ViewReply ser.str(2, string("set ip localport 80")) ser.tx(2, CR) ViewReply ser.str(2, string("set ip gateway 192.168.1.1")) ser.tx(2, CR) ViewReply ser.str(2, string("set ip netmask 255.255.255.0")) ser.tx(2, CR) ViewReply ser.str(2, string("set wlan ssid M1$Secure")) ser.tx(2, CR) ViewReply ser.str(2, string("set wlan hide 0")) ser.tx(2, CR) ViewReply ser.str(2, string("set wlan phrase 012345678901")) ser.tx(2, CR) ViewReply ser.str(2, string("set uart mode 16")) ser.tx(2, CR) ViewReply ser.str(2, string("set opt format 0")) ser.tx(2, CR) ViewReply ser.str(2, string("set com size 512")) ser.tx(2, CR) ViewReply ser.str(2, string("set com time 10")) ser.tx(2, CR) ViewReply ser.str(2, string("set com match 0")) ser.tx(2, CR) ViewReply ser.str(2, string("set sys autoconn 0")) ser.tx(2, CR) ViewReply ser.str(2, string("set com open ")) ser.tx(2, CR) ViewReply ser.str(2, string("set com close ")) ser.tx(2, CR) ViewReply ser.str(2, string("set com remote 0")) ser.tx(2, CR) ViewReply ser.str(2, string("set broad int 0")) ser.tx(2, CR) ViewReply ser.str(2, string("set ip flags 7")) ser.tx(2, CR) ViewReply ser.str(2, string("set ip remote 80")) ser.tx(2, CR) ViewReply ser.str(2, string("set ip dhcp 0")) ser.tx(2, CR) ViewReply ser.str(2, string("set ip host 0")) ser.tx(2, CR) ViewReply ser.str(2, string("set ip proto 18")) ser.tx(2, CR) ViewReply ser.str(2, string("set dns name 0")) ser.tx(2, CR) ViewReply ser.str(2, string("set dns backup 0")) ser.tx(2, CR) ViewReply ser.str(2, string("set dns address 192.168.1.1")) ser.tx(2, CR) ViewReply ser.str(2, string("set wlan auth 3")) ser.tx(2, CR) ViewReply ser.str(2, string("set wlan channel 0")) ser.tx(2, CR) ViewReply ser.str(2, string("set wlan ext_ant 0")) ser.tx(2, CR) ViewReply ser.str(2, string("set wlan join 1")) ser.tx(2, CR) ViewReply ser.str(2, string("set com idle 4")) ser.tx(2, CR) ViewReply ser.str(2, string("set time enable 0")) ser.tx(2, CR) ViewReply ser.str(2, string("set ftp filename wifly-GSX.img")) ser.tx(2, CR) ViewReply Save ViewReply Ex Repeat ''' stop here PUB UpdateWifly 'update firmware via ftp Ex ViewReply Ex ViewReply ser.str(2, string("$$$")) ViewReply ser.str(2, string("get update")) ser.tx(2, CR) repeat 'lock up here, for programming only, not for running. ViewReply PUB RelayInit 'WiflyPwr = 11 'DVPwr = 12 'DVRec = 13 'M1Pwr = 15 'M1Batt = 16 'Misc12v = 17 'M2Pwr = 19 'M2Batt = 20 'NetGear = 21 'Misc5v1 = 22 dira[WiflyPwr] := 1 '11 dira[NetGear] := 1 '21 dira[DVPwr] := 1 '12 dira[DVRec] := 1 '13 dira[M1Pwr] := 1 '15 dira[M1Batt] := 1 '16 dira[M2Pwr] := 1 '19 dira[M2Batt] := 1 '20 dira[Misc5v1] := 1 '22 dira[Misc12v] := 1 '22 PUB StartSerial 'PUB AddPort(port,rxpin,txpin,ctspin,rtspin,rtsthreshold,mode,baudrate) Ser.stop Ser.init Ser.AddPort(0,0,1,-1,-1,0,0,9600) '// XTENDDO= 0 XTENDDI= 1 Ser.Start w(40_000_000) Ser.stop w(40_000_000) Ser.init Ser.AddPort(0,0,1,-1,-1,0,0,9600) '// XTENDDO= 0 XTENDDI= 1 if ina[31] == 1 Ser.AddPort(1,-1,30,-1,-1,0,0,9600) '// GUI monitor wifly response if ina[31] == 0 Ser.AddPort(1,-1,-1,-1,-1,0,0,9600) '// GUI monitor wifly response ser.addport(2,2,3,-1,-1,0,0,9600) '// WiFlyDO = 2 WiFlyDI = 3 Ser.Start PUB Testrelays 'WiflyPwr = 11 'DVPwr = 12 'DVRec = 13 'M1Pwr = 15 'M1Batt = 16 'Misc12v = 17 'M2Pwr = 19 'M2Batt = 20 'NetGear = 21 'Misc5v1 = 22 dira[WiflyPwr] := 1 '11 dira[NetGear] := 1 '21 dira[DVPwr] := 1 '12 dira[DVRec] := 1 '13 dira[M1Pwr] := 1 '15 dira[M1Batt] := 1 '16 dira[M2Pwr] := 1 '19 dira[M2Batt] := 1 '20 dira[Misc5v1] := 1 '22 dira[Misc12v] := 1 '22 'outa[WiflyPwr] := 1 'def=0 Normally closed 0 = power ON 'w(80000000) 'outa[WiflyPwr] := 0 'def=0 Normally closed 0 = power ON 'w(80000000) 'outa[DVPwr] := 0 'def=0 Normally Open 1 = power on 'w(80000000) 'outa[DVPwr] := 1 'def=0 Normally Open 1 = power on 'w(80000000) 'outa[DVRec] := 0 'def=0 Normally Open 1 = record pulse on 'w(80000000) 'outa[DVRec] := 1 'def=0 Normally Open 1 = record pulse on 'w(80000000) 'outa[M1Pwr] := 0 'def=1 Normally Open 1 =close contact 'w(240_000_000) 'outa[M1Pwr] := 1 'def=1 Normally Open 1 =close contact, wait for USB power to turn on above 'w(160_000_000) 'outa[M2Pwr] := 0 'def=1 Normally Open 1 =close contact 'w(240_000_000) 'outa[M2Pwr] := 1 'def=1 Normally Open 1 =close contact, wait for USB power to turn on above 'w(160_000_000) 'outa[M2Batt] := 0 'def=1 Normally Open 1 =close contact 'w(240_000_000) 'outa[M2Batt] := 1 'def=1 Normally Open 1 =close contact, wait for USB power to turn on above 'w(160_000_000) 'outa[DVRec] := 0 'def=0 Normally Open 1 = power on 'w(80000000) 'outa[DVRec] := 1 'def=0 Normally Open 1 = power on 'w(80000000) 'outa[NetGear] := 0 'def=0 Normally Open 1 = power on 'w(80000000) 'outa[NetGear] := 1 'def=0 Normally Open 1 = power on 'w(80000000) 'outa[Misc5v1] := 0 'def=0 Normally Open 1 = power on 'w(80000000) 'outa[Misc5v1] := 1 'def=0 Normally Open 1 = power on 'w(80000000) 'outa[Misc12v] := 0 'def=0 Normally Open 1 = power on 'w(80000000) 'outa[Misc12v] := 1 'def=0 Normally Open 1 = power on 'w(80000000) PUB ReadContacts '''ser.str(1, string("**READING CONTACTS**")) '''ser.tx(1, CR) if ina[C1] == 0 'if 0, then problem, contact open w(5_000_000) if ina[C1] == 0 'debounce C1S:= 0 WritePage(eeprom2, $7010, @C1S, 1) w(1_000_000) if ina[C2] == 0 w(5_000_000) if ina[C2] == 0 C2S := 0 WritePage(eeprom2, $7020, @C2S, 1) w(1_000_000) if ina[C3] == 0 w(5_000_000) if ina[C3] == 0 C3S := 0 WritePage(eeprom2, $7030, @C3S, 1) w(1_000_000) if ina[C4] == 0 w(5_000_000) if ina[C4] == 0 C4S := 0 WritePage(eeprom2, $7040, @C4S, 1) w(1_000_000) ' The FIRST 3 are grouped for multi break to reset timer. if ina[C1] == 0 AND ina[C2] == 0 AND ina[C3] == 0 ''reset timer if all 3 are open SetTimer(0,0,0,0) timer.run PowerONDVR '-------------------------------- if ina[C1] == 1 w(5_000_000) if ina[C1] == 1 C1S := 1 if ina[C2] == 1 w(5_000_000) if ina[C2] == 1 C2S :=1 if ina[C3] == 1 w(5_000_000) if ina[C3] ==1 C3S:=1 if ina[C4] == 1 w(5_000_000) if ina[C4] ==1 C4S:=1 'ser.str(1, string("**CONTACT STATUS:**")) 'ser.hex(1, C1S,1) 'ser.hex(1, C2S,1) 'ser.hex(1, C3S,1) 'ser.hex(1, C4S,1) 'ser.tx(1, CR) PUB ClearMem ser.str(1, string("**CLEARING CONTACT MEMORY**")) ser.tx(1, CR) CM1S := 1 CM2S := 1 CM3S := 1 CM4S := 1 WritePage(eeprom2, $7010, @CM1S, 1) 'reset to HIGH = 1 to reflect contact default when set(pressed NO) w(1_000_000) WritePage(eeprom2, $7020, @CM2S, 1) w(1_000_000) WritePage(eeprom2, $7030, @CM3S, 1) w(1_000_000) WritePage(eeprom2, $7040, @CM4S, 1) w(1_000_000) PUB ReadMem ReadPage(eeprom2, $7010, @CM1S, 1) ReadPage(eeprom2, $7020, @CM2S, 1) ReadPage(eeprom2, $7030, @CM3S, 1) ReadPage(eeprom2, $7040, @CM4S, 1) 'CM1S := 1 'CM2S := 1 'CM3S := 1 'CM4S := 1 ser.str(1, string("**MEMORY STATUS:**")) ser.hex(1, CM1S,1) ser.hex(1, CM2S,1) ser.hex(1, CM3S,1) ser.hex(1, CM4S,1) ser.tx(1, CR) PUB ShowWifiResponse | i i := 0 ParseIP ParseClose repeat 1024 'reset all values to 0 to avoid false read response[i] := 0 i++ PUB ParseIP | i, val i := 0 repeat 1024 if response[i] == "A" if response[i+1] == "d" if response[i+2] == "d" if response[i+3] == "r" if response[i+4] == "e" if response[i+5] == "s" if response[i+6] == "s" if response[i+7] == ":" IP[0] := response[i+8] IP[1] := response[i+9] IP[2] := response[i+10] IP[3] := response[i+11] IP[4] := response[i+12] IP[5] := response[i+13] IP[6] := response[i+14] IP[7] := response[i+15] IP[8] := response[i+16] IP[9] := response[i+17] IP[10] := response[i+18] IP[11] := response[i+19] IP[12] := response[i+20] IP[13] := response[i+21] IP[14] := response[i+22] IP[15] := response[i+23] SendIPString 'test sending out the complete IP as data quit i++ PUB ParseClose | i, val i := 0 repeat 1024 if response[i] == "C" if response[i+1] == "L" if response[i+2] == "O" if response[i+3] == "S" if response[i+4] == "E" 'if ina[31] == 1 ser.str(1, string("**CONNECTION NOW CLOSED**")) ser.tx(1, CR) quit i++ PUB SendIPString | x x := 0 ser.str(1, string("IP=")) repeat 15 if IP[x] > $2f AND IP[x] < $3a 'test for value between 0-9 dec or hex $30 and $39 ser.tx(1, IP[x]) if IP[x] < $2f AND IP[x] > $3a ser.tx(1, $30) ' place a 0 if no value if IP[x] == $2e ser.tx(1, $2e) ' place a 0 if no value x++ PUB WriteDBall 'write the standard values to the DB SetIdle5 ReadContacts ReadMem ser.str(1, string("**Write DB All**")) ser.tx(1, CR) FormatIP ex ex ser.str(1, string("---")) ser.str(2, string("$$$")) Viewreply ser.str(2, string("open xxxxxx.com 80")) ser.tx(2, CR) Viewreply Viewreply ser.str(2, string("GET /writedball.php?")) ser.str(2, string("TABLE=table1")) 'DB table name ser.str(2, string("&ID=1")) 'system ID ser.str(2, string("&SERVER=xxxxx.db.xxxxxxxx.xxxxxx.com")) '' DB server ser.str(2, string("&DBU=xxxxxx")) ''DB username ser.str(2, string("&DBP=xxxxxx!")) ''DB password ''/// send all status parameters ser.str(2, string("&REMIP=")) '///TEST only >>>192.168.1.13")) ''router IP (dynamic) ser.str(2, @IP) 'send the complete IP in one string from array ser.str(2, string("&TIMER=")) '/// test only>>1005")) ''router IP (dynamic) ser.str(2, timer.showTimer) '' insert the running timer value here ser.str(2, string("&C1=")) ser.hex(2, C1S,1) ser.str(2, string("&C2=")) ser.hex(2, C2S,1) ser.str(2, string("&C3=")) ser.hex(2, C3S,1) ser.str(2, string("&C4=")) ser.hex(2, C4S,1) ser.str(2, string("&CM1=")) ser.hex(2, CM1S,1) ser.str(2, string("&CM2=")) ser.hex(2, CM2S,1) ser.str(2, string("&CM3=")) ser.hex(2, CM3S,1) ser.str(2, string("&CM4=")) ser.hex(2, CM4S,1) ser.str(2, string("&DVS=")) ser.hex(2, DVS,1) ser.str(2, string("&MIFI=")) ser.hex(2, MIFIselect, 1) ser.str(2, string(" HTTP/1.1")) 'http GET terminator ser.tx(2, CR) ser.tx(2, LF) ser.str(2, string("Host: xxxxxxx.com")) ser.tx(2, LF) ' two LF required ser.tx(2, LF) ' CR or LF works TESTED Viewreply Viewreply ser.str(1, string("**Write DB DONE**")) ser.tx(1, CR) SetIdle2 PUB ReadDB SetIdle5 ser.str(1, string("**READING DB**")) ser.tx(1, CR) beep(buzz, 2500, 100) w(20_000_000) beep(buzz, 2500, 100) w(20_000_000) beep(buzz, 2500, 100) ex ex ser.str(1, string("---")) ser.str(2, string("$$$")) Viewreply ser.str(2, string("open xxxxxxxxx.com 80")) ser.tx(2, CR) Viewreply Viewreply Viewreply ser.str(2, string("GET /readdb.php?")) ser.str(2, string("TABLE=table1")) 'DB table name ser.str(2, string("&ID=1")) 'system ID ser.str(2, string("&SERVER=xxx.db.xxxxx.xxxxxx.com")) '' DB server ser.str(2, string("&DBU=xxxxx")) ''DB username ser.str(2, string("&DBP=xxxxxx!")) 'DB password ''ser.str(2, string("&SERVER=localhost")) '' DB server ''ser.str(2, string("&DBU=xxxxxx_user")) ''DB username ''ser.str(2, string("&DBP=xxxxxx!")) 'DB password ''DB name: xxxxxx_db ''Username: xxxxxx_user ''Password: xxxxxxxx ''DB host: localhost ser.str(2, string(" HTTP/1.1")) 'http GET terminator ser.tx(2, CR) ser.tx(2, LF) ser.str(2, string("Host: xxxxxxxx.com")) ''www reqd? ser.tx(2, LF) ' two LF required ser.tx(2, LF) ' CR or LF works TESTED RecWifiData ParseDBReply 'parse and act on commands ser.str(1, string("**READ DB DONE**")) ser.tx(1, CR) SetIdle2 PUB ParseDBreply | ii, val 'copy content of incoming message to an array 'ViewDBResponse 'debug show the reply from DB ser.tx(1, CR) 'must be CR TestRebootDVR TestDVRPower TestClear TestTimer ParseClose PUB ParseWifly |ii, val ii := 1 response[0] := ser.rxtime(2, 2000) 'waits here for first byte response for 2 seconds Repeat 1023 'look for more, else return Val := ser.rxtime(2, 10) 'read more, wait only 2 ms if no byte found response[ii] := Val ii++ PUB WriteConfirm SetIdle5 If confirmFLAG == 1 ser.str(1, string("**WRITE CONFIRM FLAG**")) ser.tx(1, CR) beep(buzz, 2500, 100) w(20_000_000) beep(buzz, 2500, 100) w(20_000_000) beep(buzz, 2500, 100) ex ex ser.str(1, string("---")) ser.str(2, string("$$$")) Viewreply ser.str(2, string("open xxxxxxxx.com 80")) ser.tx(2, CR) Viewreply Viewreply ser.str(2, string("GET /confirm.php?")) ser.str(2, string("TABLE=table1")) 'DB table name ser.str(2, string("&ID=1")) 'system ID ser.str(2, string("&SERVER=xxxx.db.xxxxxx.xxxxxx.com")) '' DB server ser.str(2, string("&DBU=xxxx")) ''DB username ser.str(2, string("&DBP=xxx!")) ''DB password ''/// send all status parameters ser.str(2, string("&TIMER=")) ser.str(2, timer.showTimer) ser.str(2, string("&DVON=0")) 'reset power on to 0 ser.str(2, string("&DVOFF=0")) 'reset power off to 0 ser.str(2, string("&CLEAR=0")) ser.str(2, string("&CONFIRM=7")) ser.str(2, string("&DVS=")) ser.hex(2, DVS, 1) ser.str(2, string("&DVR=0")) ser.str(2, string("&RSTTIMER=0")) ser.str(2, string("&DAY=0")) ser.str(2, string("&HOUR=0")) ser.str(2, string("&MINUTE=0")) ser.str(2, string(" HTTP/1.1")) 'http GET terminator ser.tx(2, CR) ser.tx(2, LF) ser.str(2, string("Host: xxxxxxxxxxxx.com")) ser.tx(2, LF) ' two LF required ser.tx(2, LF) ' CR or LF works TESTED Viewreply Viewreply confirmFLAG := 0 SetIdle2 Return 1 PUB TestClear | i ' webserver request to POWER UP THE DVR ser.str(1, string("**TEST CLEAR MEM FLAG**")) ser.tx(1, CR) i := 0 repeat 1024 ' start checking the string for 'time' reply with the timer value if response[i] == "C" if response[i+1] == "L" if response[i+2] == "E" if response[i+3] == "A" if response[i+4] == "R" if response[i+5] == "=" if response[i+6] == "1" w(10_000_000) beep(buzz, 2500, 50) w(10_000_000) beep(buzz, 2000, 50) ClearMem confirmFLAG := 1 ser.str(1, string("**CLEAM MEM FLAG RECIEVED**")) ser.tx(1,cr) Return i++ PUB FormatIP | i 'for email/DB i := 0 repeat 16 if ip[i] > 57 ' clear any values above "0" ip[i] := 58 ' change to ":" i++ i := 0 repeat 16 if ip[i] == 32 ' change " " to _ due to GET not working with a space included ip[i] := 58 ' "_" i++ i := 0 repeat 16 if ip[i] == 47 ' change "/" to : ip[i] := 58 i++ PUB ViewDBResponse | i i := 0 repeat 1024 'reset all values to 0 to avoid false read ser.str(1, response[i]) i++ PUB EepromWriteTest 'WritePage(eeprom2, $7200, @TS1, 4) 'eeprom is i2c address for the eeprom &7200 is the mem location '@p is the location of the value we are going to write ( ie var long if 4 ), 4 is the number of bytes to write 'WritePage(eeprom2, $7000, @TS1, 4) PUB EepromReadTest | a,b,c,d 'WritePage(eeprom2, $7200, @TS1, 4) 'eeprom is i2c address for the eeprom &7200 is the mem location '@p is the location of the value we are going to write ( ie var long if 4 ), 4 is the number of bytes to write 'ReadPage(eeprom2, $7000, @TS1, 1) PUB WritePage(devid, address, pointer, count) i2c1.i2cWritepage(28, devid, address, pointer, count) waitcnt(clkfreq/200 + cnt) i2c1.i2cstop(28) PUB WiflyServerMode | i 'GET /status ' serber keeps outputting "keep-alive' per second RecWifiData 'ShowData ' debug to terminal 'i := 0 'GetTime 'GetDVRon 'GetDVRoff 'etRebootMifi1 'GetRebootMifi2 PUB ForceClose ser.str(1, string("**FORCING CLOSE**")) ser.tx(1, CR) ser.str(2, string("$$$")) GETreply ser.str(2, string("close")) ser.tx(2, CR) GETreply ser.str(2, string("close")) ser.tx(2, CRLF) ser.tx(2, CRLF) ser.str(2, string(".")) ser.str(2, string("exit")) ser.tx(2, CR) ser.str(2, string("exit")) ser.tx(2, CR) GETreply GETreply GETreply PUB ReadPage(devid, address, pointer, count) 'boot eeprom $A0 i2c1.i2cstart(28) i2c1.i2cReadPage(28, devid, address, pointer, count) '$7000test i2c1.i2cstop(28) return pointer PUB Codeideas 'bytefill(@tmrStr, 0, MAX_STR + 1) byte tmrStr[MAX_STR + 1] 'this sets all the elements to 0, faster than repeat loop 'return @tmrStr return from the method the address of the string 'bytemove(DataAddress,@DateTimeStamp,11) PUB ShowData | i i := 0 repeat 1024 ser.tx(1, response[i]) 'send to GUI i++ PUB Webpage | x, h ' USED as a server response for wifly ' ser.str(2,string("")) ser.tx(2, CRLF) ser.str(2,string("h")) ser.tx(2, CRLF) ser.str(2,string("")) ser.tx(2, CRLF) ser.str(2,string("")) ser.tx(2, CRLF) ser.str(2,string("

Response From Server")) ser.tx(2, CRLF) ser.str(2,string("")) ser.tx(2, CRLF) ForceClose PUB Close ser.str(2, string("$$$")) ser.str(2, string("close")) ser.tx(2, CR) PUB GetReply repeat 1024 'get the response here from the load command buffer := ser.rxtime(2,2) PUB CMD ser.str(2, string("$$$")) Viewreply PUB Ex 'ser.str(2, string("$$$")) ser.str(2, string("exit")) ser.tx(2, CR) ViewReply PUB WiflySoftboot ser.str(2, string("reboot")) ser.tx(2, CR) 'Viewreply PUB beep(pinn, freqq, durr) | period, cycles, frqhi, frqlo, t if ((period := clkfreq / (freqq << 1)) < 4000) return cycles := freqq * durr / 5000 if voll frqhi := $10_0000 << (voll #> 0 <# 11) - 1 else frqhi := 0 frqlo := 0 frqb~ ctrb := %00110 << 26 | pinn t := cnt repeat cycles waitcnt(t += period) frqb := frqhi waitcnt(t += period) frqb := frqlo ctrb~ PUB w(k) waitcnt(k + cnt) PUB go(line,col) | lcdline if line == 0 lcdline := $80 if line == 1 lcdline := $94 ser.putc(3,lcdline + col) PUB Setbuzzvol(freq) 'no counter available in main cog,place buzzer CV in another ctra := %00110 << 26 + Buzz frqa := freq PUB CLS ser.cls(3) PUB ConvertToAscii 'tmrStr[0] := (h / 10) + "0" ' convert 10's digit to ASCII char 'tmrStr[1] := (h // 10) + "0" ' convert 1's digit to ASCII char