//~~STARTUP // Code to execute when unit starts up timer_interval = 2000 override_gsm = 1 //always on override_low_power = 1 //do not sleep override_gps = 2 IO1=1 // high impedance state IO3=1 // high impedance state sensor1_temp = 0 too_hot=0 first_time=1 timer_count=0; //~~TIMER // Code to execute every TIMER_INTERVAL milliseconds led=1 //green // **************************************** Send web updates ********************************** // do it here, as problems below will jump out of timer loop timer_count = timer_count+timer_interval/1000 // increment every 5 seconds //update website every 5 minutes or if door status changed if (first_time=0) then begin if (timer_count>300) then begin webstr$ = sensor1_temp + "," + 0 + "," + volt_supply + "," + volt_batt; senddata(webstr$) timer_count=0 end end // end not first time // **************************************** sensor 1 ********************************** if (OW_RESET() != 1) then begin debug_str$ = "No reset received"; led=2 //red wait(250) led=0 return end OW_WRITE(0xcc) // Skip ROM command OW_WRITE(0x44) // initiate temperature conversion IO3=2 //strong pullup wait(750); //strong pullup while waiting for conversion IO3=1 //normal pullup if (OW_RESET() != 1) then begin debug_str$ = "No reset received"; led=2 //red wait(250) led=0 return end OW_WRITE(0xcc) // Skip ROM command OW_WRITE(0xbe) // Read scratchpad //read all 9x data bytes temp_LSB = OW_READ() temp_MSB = OW_READ() Th = OW_READ() Tl = OW_READ() configuration = OW_READ() reserve1 = OW_READ() reserve2 = OW_READ() reserve3 = OW_READ() device_crc = OW_READ() //calculate CRC DOW from all received bytes my_crc = 0 my_crc = CRCDOW(my_crc,temp_LSB) my_crc = CRCDOW(my_crc,temp_MSB) my_crc = CRCDOW(my_crc,Th) my_crc = CRCDOW(my_crc,Tl) my_crc = CRCDOW(my_crc,configuration) my_crc = CRCDOW(my_crc,reserve1) my_crc = CRCDOW(my_crc,reserve2) my_crc = CRCDOW(my_crc,reserve3) temp = temp_LSB+temp_MSB*256; if (temp>=0x8000) then temp = -((temp ^ 0xffff) +1) //negative, calculate from 2's complement temp = temp /16 if (my_crc=device_crc AND temp!=0xaa) then begin //0xaa = power on reset value, probably an error... if first_time=1 then sensor1_temp = temp else begin //temp cannot change that fast, probably an error if (temp sensor1_temp-10 ) sensor1_temp = (4*sensor1_temp + temp)/5 else if (temp < sensor1_temp) sensor1_temp--; else sensor1_temp++ end first_time = 0 end led=0 override_led=0 if (sensor1_temp>55) too_hot=too_hot + 1 else too_hot=0 // too hot for 6 successive times (6*5=30 seconds), send SMS if (too_hot=6) then sendSMS("0726194657", "error, fridge too hot!") //send again if still too hot after 10 minutes (120*5 = 10 minutes) if (too_hot=120) then sendSMS("0726194657", "error, fridge too hot!") //~~CALL // Code to execute when receiving an incoming call //~~SMS // Code to execute when receiving an SMS //~~MOVEMENT // Code to execute when detecting movement. // The movement intensity is stored in ACC_DETECT, as well as ACC_X, AXX_Y and AXX_Z //~~USSD // Code to execute when receiving a reply from a USSD string. // Reply is stored in INCOMING_USSD$ string //~~GPRS // Code to execute when receiving GPRS data. // Data is stored in INCOMING_GPRS$ string