def rebootCounterProcessing(delta): global REBOOT_COUNTER global CALENDAR if((delta < 0) or (delta > 100)): delta = 5 REBOOT_COUNTER = REBOOT_COUNTER + delta SER.send('Current reboot counter: %d\r' % REBOOT_COUNTER) if(REBOOT_COUNTER > int(CFG.get('REBOOTPERIOD'))): SER.send('Terminal reboot.\r') if(int(CFG.get('ALIVESMS')) > 0): CALENDAR = CALENDAR + 1 calendar.writeCalendar(CALENDAR) MOD.sleep(30) gsm.reboot()
result = result + executeCommand(c) sms.sendSms( sms_msg.SmsMessage('0', message.getNumber(), '', result)) if (CFG.get('SMSDELETEALL') == '0'): sms.deleteSms(message.getId()) if (CFG.get('SMSDELETEALL') == '1'): sms.deleteSms(message.getId()) def resetWatchdog(): gsm.sendAT("AT#ENHRST=1,10", "OK", 5) if __name__ == "__main__": try: CFG.read() print('Start GSM init\r') gsm.init() print('Start SMS init\r') sms.init() print('IO init\r') initInputs() print('Start main loop\r') while (1): resetWatchdog() smsProcessing() ioProcessing() except Exception, e: print('Unhandled exception, reboot...\r') gsm.reboot()
global CALENDAR CALENDAR = calendar.readCalendar() SER.send('Wait for network registration\r') gsm.waitRegister() if(int(CFG.get('ALIVESMS')) > 0): SER.send('Calendar processing\r') calendarProcessing() SER.send('Start main loop\r') while(1): start = MOD.secCounter() RX_API.resetWDT() smsProcessing() RX_API.resetWDT() ringProcessing() ioProcessing() RX_API.resetWDT() if(int(CFG.get('REBOOTPERIOD')) > 0): rebootCounterProcessing(MOD.secCounter() - start) except Exception, e: SER.send('Unhandled exception, reboot: %s\r' % e) MOD.sleep(20) gsm.reboot()